Commit: 3fde97a0ea76fa12f6534a7e207e32ebd5332bbd
Author: zoe slattery <z...@php.net> Fri, 12 Oct 2012 14:28:29 +0100
Parents: b668d1f0fec05a87f29f2aa9601203228b123916
Branches: master
Link:
http://git.php.net/?p=phpruntests.git;a=commitdiff;h=3fde97a0ea76fa12f6534a7e207e32ebd5332bbd
Log:
Refactor - add Group results class
Changed paths:
M src/rtClassMap.php
M src/taskScheduler/rtTaskScheduler.php
M src/taskScheduler/rtTaskSchedulerFile.php
M src/taskScheduler/rtTaskTestGroup.php
M src/testcase/rtTestOutputWriter.php
A src/testgroup/rtGroupResults.php
M src/testgroup/rtPhpTestGroup.php
M src/testrun/rtPhpTestRun.php
A tests/rtGroupResultsTest.php
M tests/rtPhpTestGroupTest.php
M tests/rtTaskSchedulerTest.php
diff --git a/src/rtClassMap.php b/src/rtClassMap.php
index ad56c93..b9f0327 100644
--- a/src/rtClassMap.php
+++ b/src/rtClassMap.php
@@ -100,6 +100,7 @@ $rtClassMap = array(
'rtOutputSection' =>
'testcase/sections/rtOutputSection.php',
'rtSection' =>
'testcase/sections/rtSection.php',
'rtGroupConfiguration' =>
'testgroup/rtGroupConfiguration.php',
+ 'rtGroupResults' =>
'testgroup/rtGroupResults.php',
'rtPhpTestGroup' =>
'testgroup/rtPhpTestGroup.php',
'rtPhpTestRun' => 'testrun/rtPhpTestRun.php',
);
diff --git a/src/taskScheduler/rtTaskScheduler.php
b/src/taskScheduler/rtTaskScheduler.php
index 3a6377c..cf1b9f1 100644
--- a/src/taskScheduler/rtTaskScheduler.php
+++ b/src/taskScheduler/rtTaskScheduler.php
@@ -19,7 +19,7 @@ class rtTaskScheduler
protected $resultList = array(); // list of results
protected $processCount = 0; // the number of processes
protected $reportStatus = 0; // the level of repoerting as tests
atr run (0, 1, 2)
- protected $redirectedTestCases = array();
+
/**
diff --git a/src/taskScheduler/rtTaskSchedulerFile.php
b/src/taskScheduler/rtTaskSchedulerFile.php
index 326c615..1831eba 100644
--- a/src/taskScheduler/rtTaskSchedulerFile.php
+++ b/src/taskScheduler/rtTaskSchedulerFile.php
@@ -178,16 +178,16 @@ class rtTaskSchedulerFile extends rtTaskScheduler
$response = explode("[END]", $response);
array_pop($response);
- foreach ($response as $testGroupResults) {
+ foreach ($response as $testGroupResult) {
- $testGroupResults =
unserialize($testGroupResults);
+ $testGroupResult =
unserialize($testGroupResult);
- if ($testGroupResults === false) {
+ if ($testGroupResult === false) {
print "ERROR unserialize - receiver
$cid\n";
continue;
}
- $this->resultList[] = $testGroupResults;
+ $this->resultList[] = $testGroupResult;
}
unlink(self::TMP_FILE.$cid);
@@ -225,16 +225,17 @@ class rtTaskSchedulerFile extends rtTaskScheduler
$task->run();
$e = microtime(true);
+
- $results = $task->getResult();
+ $statusList = $task->getResult()->getTestStatusList();
- if (isset($results[0]) && is_object($results[0])) {
- $results[0]->setTime($e-$s);
+ if (isset($statusList[0]) && is_object($statusList[0]))
{
+ $statusList[0]->setTime($e-$s);
}
- rtTestOutputWriter::flushResult($results,
$this->reportStatus, $cid);
+ rtTestOutputWriter::flushResult($statusList,
$this->reportStatus, $cid);
- $response = serialize($results)."[END]";
+ $response = serialize($task->getResult())."[END]";
file_put_contents(self::TMP_FILE.$cid, $response,
FILE_APPEND);
}
diff --git a/src/taskScheduler/rtTaskTestGroup.php
b/src/taskScheduler/rtTaskTestGroup.php
index d0a2910..c8a3d6b 100644
--- a/src/taskScheduler/rtTaskTestGroup.php
+++ b/src/taskScheduler/rtTaskTestGroup.php
@@ -15,7 +15,6 @@ class rtTaskTestGroup extends rtTask implements
rtTaskInterface
{
protected $runConfiguration;
protected $subDirectory;
- protected $redirectedTestCases = array();
protected $groupConfig;
@@ -35,13 +34,14 @@ class rtTaskTestGroup extends rtTask implements
rtTaskInterface
{
$testGroup = new rtPhpTestGroup($this->runConfiguration,
$this->subDirectory, $this->groupConfig);
$testGroup->run();
- $this->result = $testGroup->getResults();
-
+ $this->result = $testGroup->getGroupResults();
+
$testGroup->__destruct();
unset($testGroup);
return true;
}
+
}
diff --git a/src/testcase/rtTestOutputWriter.php
b/src/testcase/rtTestOutputWriter.php
index 99e1ac7..b20638a 100644
--- a/src/testcase/rtTestOutputWriter.php
+++ b/src/testcase/rtTestOutputWriter.php
@@ -106,12 +106,12 @@ abstract class rtTestOutputWriter
}
/*
- * Most of the code uses processCount = 0 to indicate serial runs.
Clearly there must always be one process,
- * so it is set to 1 here to make the output make sense.
+ * Add one to the process count (it should represesnt the number or
processes, not the nubmer of
+ * proccess in addition to the one that you have to have anyway!
*/
- if($processCount == 0) {
- $processCount ++;
- }
+
+ $processCount ++;
+
// collect data
$state = array();
diff --git a/src/testgroup/rtGroupResults.php b/src/testgroup/rtGroupResults.php
new file mode 100644
index 0000000..fdbf5aa
--- /dev/null
+++ b/src/testgroup/rtGroupResults.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * rtPhpGroupResults
+ *
+ * Stores the results of a 'group of tests'. A 'group' is all or the tests in
a single directory.
+ *
+ * @category Testing
+ * @package RUNTESTS
+ * @author Zoe Slattery <z...@php.net>
+ * @author Stefan Priebsch <sprieb...@php.net>
+ * @copyright 2009 The PHP Group
+ * @license http://www.php.net/license/3_01.txt PHP License 3.01
+ *
+ */
+class rtGroupResults
+{
+
+ protected $testStatusList = array();
+ protected $redirectedTestCases = array();
+ protected $groupName;
+
+ public function __construct($gn) {
+ $this->groupName = $gn;
+ }
+
+ public function __destruct() {
+ unset ($this->testStatusList);
+ unset ($this->redirectedTestCases);
+
+ }
+
+ public function setTestStatus($name, $status) {
+ $this->testStatusList[$name] = $status;
+ }
+
+ public function setRedirectedTestCase (rtPhpTest $testCase) {
+ $this->redirectedTestCases[] = $testCase;
+ }
+
+ public function getGroupName() {
+ return $this->groupName;
+ }
+
+ public function getTestStatusList() {
+ return $this->testStatusList;
+ }
+
+ public function getRedirectedTestCases() {
+ return $this->redirectedTestCases;
+ }
+
+}
\ No newline at end of file
diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php
index f6e8ff5..e4724db 100644
--- a/src/testgroup/rtPhpTestGroup.php
+++ b/src/testgroup/rtPhpTestGroup.php
@@ -16,21 +16,22 @@ class rtPhpTestGroup extends rtTask implements
rtTaskInterface
{
protected $testDirectory;
protected $testCases;
- protected $result = array();
protected $runConfiguration;
protected $groupConfiguration;
- protected $redirectedTestCases = array();
-
+ protected $groupResults;
+
public function __construct(rtRuntestsConfiguration $runConfiguration,
$directory, $groupConfiguration)
{
$this->runConfiguration = $runConfiguration;
$this->testDirectory = $directory;
- $this->groupConfiguration = $groupConfiguration;
+ $this->groupConfiguration = $groupConfiguration;
+ $this->groupResults = new rtGroupResults($directory);
$this->init();
}
public function __destruct() {
unset ($this->testCases);
+ unset ($this->groupResults);
}
@@ -79,12 +80,12 @@ class rtPhpTestGroup extends rtTask implements
rtTaskInterface
if($redirectedTest->getStatus()->getValue('skip')) {
$testStatus->setTrue('skip');
$testStatus->setMessage('skip',
$testFile->getExitMessage(). ' and the skip condition has failed');
- $this->result[$testFile->getTestName()] =
$testStatus;
+
$this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
} else {
$testStatus->setTrue('redirected');
$testStatus->setMessage('redirected',
$testFile->getExitMessage());
- $this->result[$testFile->getTestName()] =
$testStatus;
- $this->redirectedTestCases[] = $redirectedTest;
+
$this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
+
$this->groupResults->setRedirectedTestCase($redirectedTest);
}
}
@@ -92,7 +93,8 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface
}else {
$testStatus->setTrue('bork');
$testStatus->setMessage('bork', $testFile->getExitMessage());
- $this->result[$testFile->getTestName()] = $testStatus;
+ $this->groupResults->setTestStatus($testFile->getTestName(),
$testStatus);
+
}
//echo "\n" .memory_get_usage() . ", setup complete".
$testFileName . "\n";
}
@@ -117,7 +119,8 @@ class rtPhpTestGroup extends rtTask implements
rtTaskInterface
$testResult = new rtTestResults($testCase);
$testResult->processResults($testCase, $this->runConfiguration);
- $this->result[$testCase->getName()] = $testResult->getStatus();
+ $this->groupResults->setTestStatus($testCase->getName(),
$testResult->getStatus());
+
//unset($testResult); Makes no diffetence
//echo "\n" .memory_get_usage() . ", run end";
}
@@ -129,7 +132,7 @@ class rtPhpTestGroup extends rtTask implements
rtTaskInterface
public function writeGroup($outType, $cid=null)
{
- $testOutputWriter = rtTestOutputWriter::getInstance($this->result,
$outType);
+ $testOutputWriter =
rtTestOutputWriter::getInstance($this->groupResults->getTestStatusList(),
$outType);
$testOutputWriter->write($this->testDirectory, $cid);
}
@@ -137,13 +140,13 @@ class rtPhpTestGroup extends rtTask implements
rtTaskInterface
public function getTestCases() {
return $this->testCases;
}
-
- public function getResults() {
- return $this->result;
+
+ public function getGroupName() {
+ return $this->testDirectory;
}
- public function getRedirectedTestCases() {
- return $this->redirectedTestCases;
+ public function getGroupResults() {
+ return $this->groupResults;
}
}
diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php
index f2cc34e..5cd8593 100644
--- a/src/testrun/rtPhpTestRun.php
+++ b/src/testrun/rtPhpTestRun.php
@@ -171,14 +171,24 @@ class rtPhpTestRun
$scheduler->run();
foreach($scheduler->getResultList() as $groupResult) {
- $this->resultList[] = $groupResult;
- }
+
+ $this->resultList[] = $groupResult->getTestStatusList();
+
+ $redirects = $groupResult->getRedirectedTestCases();
+ foreach($redirects as $testCase) {
+ $this->redirectedTestCases[] = $testCase;
+ }
+ }
+
+
+
}
public function run_serial_groups($testDirectories,
$groupConfigurations) {
$count = 0;
+ //xdebug_start_trace('/tmp/memorycheck');
foreach($testDirectories as $subDirectory) {
@@ -194,13 +204,13 @@ class rtPhpTestRun
//$midm = memory_get_usage();
-
rtTestOutputWriter::flushResult($testGroup->getResults(), $this->reportStatus);
- $this->resultList[] = $testGroup->getResults();
+
rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(),
$this->reportStatus);
+ $this->resultList[] =
$testGroup->getGroupResults()->getTestStatusList();
// Memory usage debugging
//$midm2 = memory_get_usage();
- $redirects = $testGroup->getRedirectedTestCases();
+ $redirects =
$testGroup->getGroupResults()->getRedirectedTestCases();
foreach($redirects as $testCase) {
$this->redirectedTestCases[] = $testCase;
}
@@ -213,8 +223,9 @@ class rtPhpTestRun
// Memory usage debugging
//echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", "
.$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n";
-
- }
+
+ }
+ //xdebug_stop_trace();
}
public function run_tests($testNames) {
diff --git a/tests/rtGroupResultsTest.php b/tests/rtGroupResultsTest.php
new file mode 100644
index 0000000..6a234cc
--- /dev/null
+++ b/tests/rtGroupResultsTest.php
@@ -0,0 +1,61 @@
+<?php
+require_once dirname(__FILE__) . '/../src/rtAutoload.php';
+require_once dirname(__FILE__) . '/rtTestBootstrap.php';
+
+class rtGroupResultsTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ $this->testCase = array (
+ '--TEST--',
+ 'This is a test',
+ '--FILE--',
+ '<?php',
+ ' echo "hello world"; ',
+ '?>',
+ '===Done===',
+ 'blah blah blah',
+ '--EXPECTF--',
+ 'hello world',
+ '===Done===',
+ 'gah',
+ );
+ }
+ public function testCreateInstance()
+ {
+
+ $results = new rtGroupResults("some_directory");
+ $this->assertEquals($results->getGroupName(), "some_directory");
+ }
+
+ public function testTestResult()
+ {
+
+ $results = new rtGroupResults("some_directory");
+ $results->setTestStatus('test_name', 'test_status');
+
+ $resultsArray = $results->getTestStatusList();
+
+ $this->assertEquals($resultsArray['test_name'], "test_status");
+ }
+
+ public function testRedirect()
+ {
+ $config = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', RT_PHP_PATH, 'test.phpt'));
+ $config->configure();
+
+ $status = new rtTestStatus('nameOfTest');
+ $testcase = new rtPhpTest($this->testCase, 'nameOfTest', array('TEST',
'FILE', 'EXPECTF'), $config, $status);
+
+
+ $results = new rtGroupResults("some_directory");
+ $results->setRedirectedTestCase($testcase);
+
+ $redirectsArray = $results->getRedirectedTestCases();
+
+ $this->assertEquals($redirectsArray[0], $testcase);
+ }
+
+
+}
\ No newline at end of file
diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php
index 51e2527..6fd8a6f 100644
--- a/tests/rtPhpTestGroupTest.php
+++ b/tests/rtPhpTestGroupTest.php
@@ -22,12 +22,12 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase
$validTestCaseCount = count($phpTestGroup->getTestCases());
$phptFileCount = count(glob($directory . "/*.phpt"));
- $inValidTestCaseCount = count($phpTestGroup->getResult());
+ $inValidTestCaseCount =
count($phpTestGroup->getGroupResults()->getTestStatusList());
//PhpTestGroup should divide the test cases into valid tests
(TestCases),
//or invalid ones. An invalid test is either one which 'borks' (that
is, the
//phpt fails to parse), or a redirected test case. Invalid test cases
are not run
- //but a TestResults object is created during initialisation of the
TestGroup.
+ //but a TestStatus object is created and added to the group results.
$this->assertEquals($phptFileCount, $validTestCaseCount +
$inValidTestCaseCount);
@@ -46,7 +46,7 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase
- $redirects = $phpTestGroup->getRedirectedTestCases();
+ $redirects = $phpTestGroup->getGroupResults()->getRedirectedTestCases();
foreach($redirects as $testCase) {
$this->assertTrue($testCase->hasSection('REDIRECTTEST'));
diff --git a/tests/rtTaskSchedulerTest.php b/tests/rtTaskSchedulerTest.php
index 9265fbe..e1a0a6e 100644
--- a/tests/rtTaskSchedulerTest.php
+++ b/tests/rtTaskSchedulerTest.php
@@ -6,6 +6,7 @@ class rtTaskSchedulerTest extends PHPUnit_Framework_TestCase
{
public function testResult()
{
+ /* Need to rewrite this to test the PHP group runner
$taskList = array();
$expected = array();
$results = array();
@@ -24,8 +25,10 @@ class rtTaskSchedulerTest extends PHPUnit_Framework_TestCase
$scheduler->setProcessCount(3);
$scheduler->setReportStatus(-1);
$scheduler->run();
+
+ var_dump($scheduler->getResultList());
- // $this->assertEquals($expected, $scheduler->getResultList());
+ $this->assertEquals($expected, $scheduler->getResultList());*/
}
}
--
PHP Quality Assurance Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php