Permalink
Browse files

Refactor - add Group results class

  • Loading branch information...
zoe slattery
zoe slattery committed Oct 12, 2012
1 parent b668d1f commit 3fde97a0ea76fa12f6534a7e207e32ebd5332bbd
View
@@ -100,6 +100,7 @@
'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',
);
@@ -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();
+
/**
@@ -178,16 +178,16 @@ protected function receiver()
$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 @@ protected function child($cid)
$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);
}
@@ -15,7 +15,6 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface
{
protected $runConfiguration;
protected $subDirectory;
- protected $redirectedTestCases = array();
protected $groupConfig;
@@ -35,13 +34,14 @@ public function run()
{
$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;
}
+
}
@@ -106,12 +106,12 @@ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount
}
/*
- * 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();
@@ -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 <zoe@php.net>
+ * @author Stefan Priebsch <spriebsch@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;
+ }
+
+}
@@ -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,20 +80,21 @@ public function init()
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);
}
}
}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 @@ public function run()
$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,21 +132,21 @@ public function run()
public function writeGroup($outType, $cid=null)
{
- $testOutputWriter = rtTestOutputWriter::getInstance($this->result, $outType);
+ $testOutputWriter = rtTestOutputWriter::getInstance($this->groupResults->getTestStatusList(), $outType);
$testOutputWriter->write($this->testDirectory, $cid);
}
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;
}
}
@@ -171,14 +171,24 @@ public function run_parallel_groups($testDirectories, $groupConfigurations, $pro
$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 @@ public function run_serial_groups($testDirectories, $groupConfigurations) {
//$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 @@ public function run_serial_groups($testDirectories, $groupConfigurations) {
// Memory usage debugging
//echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n";
-
- }
+
+ }
+ //xdebug_stop_trace();
}
public function run_tests($testNames) {
@@ -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);
+ }
+
+
+}
@@ -22,12 +22,12 @@ public function testCreateInstance()
$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 @@ public function testFindRedirect()
- $redirects = $phpTestGroup->getRedirectedTestCases();
+ $redirects = $phpTestGroup->getGroupResults()->getRedirectedTestCases();
foreach($redirects as $testCase) {
$this->assertTrue($testCase->hasSection('REDIRECTTEST'));
Oops, something went wrong.

0 comments on commit 3fde97a

Please sign in to comment.