com phpruntests: assemble redirected tests, ready to add code to run: phpt-tests/sample_redirect.phpt src/taskScheduler/rtTaskT estGroup.php
src/testcase/rtTestResults.php src/testgro up/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php test s/rtPhpTestGroupTest.php
tests/testcase/sections/configurat ionsections/rtRedirectSectionTest.php

From: Date: Sun, 05 Aug 2012 19:46:41 +0000
Subject: com phpruntests: assemble redirected tests, ready to add code to run: phpt-tests/sample_redirect.phpt src/taskScheduler/rtTaskT estGroup.php
src/testcase/rtTestResults.php src/testgro up/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php test s/rtPhpTestGroupTest.php
tests/testcase/sections/configurat ionsections/rtRedirectSectionTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66741@lists.php.net to get a copy of this message
Commit: c899eb4017fab1c4cb3cc0490ea8f49221b83280 Author: zoe slattery <zoe@php.net> Sun, 5 Aug 2012 20:46:41 +0100 Parents: f596cdb981324e41f6242f09a3db772502348855 Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=c899eb4017fab1c4cb3cc0490ea8f49221b83280 Log: assemble redirected tests, ready to add code to run Changed paths: A phpt-tests/sample_redirect.phpt M src/taskScheduler/rtTaskTestGroup.php M src/testcase/rtTestResults.php M src/testgroup/rtPhpTestGroup.php M src/testrun/rtPhpTestRun.php A tests/rtPhpTestGroupTest.php A tests/testcase/sections/configurationsections/rtRedirectSectionTest.php

diff --git a/phpt-tests/sample_redirect.phpt b/phpt-tests/sample_redirect.phpt new file mode 100644 index 0000000..778d42b --- /dev/null +++ b/phpt-tests/sample_redirect.phpt @@ -0,0 +1,13 @@ +--TEST-- +SQLite +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded('pdo_sqlite')) print 'skip'; ?> +--REDIRECTTEST-- +return array( + 'ENV' => array( + 'PDOTEST_DSN' => 'sqlite::memory:' + ), + 'TESTS' => 'ext/pdo/tests' + ); + diff --git a/src/taskScheduler/rtTaskTestGroup.php b/src/taskScheduler/rtTaskTestGroup.php index 5c89b65..6f9c665 100644 --- a/src/taskScheduler/rtTaskTestGroup.php +++ b/src/taskScheduler/rtTaskTestGroup.php @@ -34,13 +34,8 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory); $testGroup->runGroup($this->runConfiguration); $this->result = $testGroup->getResults(); - $this->redirectedTestCases = $testGroup->getRedirectedTestCases(); return true; } - - public function getRedirectedTestCases() { - return $this->redirectedTestCases; - } } diff --git a/src/testcase/rtTestResults.php b/src/testcase/rtTestResults.php index 0aa8597..93da986 100644 --- a/src/testcase/rtTestResults.php +++ b/src/testcase/rtTestResults.php @@ -24,6 +24,7 @@ class rtTestResults protected $savedFileNames = array(); protected $title = ''; protected $time = 0; + protected $redirectedTest; public function __construct(rtPhpTest $testCase = null, rtTestStatus $testStatus = null) { @@ -36,6 +37,9 @@ class rtTestResults $this->title = implode('',$testCase->getSection('TEST')->getContents()); $this->testStatus = $testCase->getStatus(); $this->testName = $testCase->getName(); + if($testStatus == 'redirected') { + $this->redirectedTest = $testCase; + } } else { $this->testStatus = $testStatus; $this->testName = $testStatus->getTestName(); @@ -205,5 +209,8 @@ class rtTestResults { $this->time = $time; } + public function getRedirectedTestCase() { + return $this->redirectedTest; + } } ?> diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index b995119..1bcd7f7 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -17,7 +17,6 @@ class rtPhpTestGroup protected $testDirectory; protected $testCases; protected $results; - protected $redirectedTestCases = array(); public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) { @@ -51,10 +50,10 @@ class rtPhpTestGroup $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ //Redirect handler, save the test case for processing after the main groups have finished. - $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); + $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); $testStatus->setTrue('redirected'); $testStatus->setMessage('redirected', $testFile->getExitMessage()); - $this->results[] = new rtTestResults(null, $testStatus); + $this->results[] = new rtTestResults($redirectedTest, $testStatus); }else { $testStatus->setTrue('bork'); $testStatus->setMessage('bork', $testFile->getExitMessage()); @@ -90,8 +89,8 @@ class rtPhpTestGroup return $this->results; } - public function getRedirectedTestCases() { - return $this->redirectedTestCases; + public function getTestCases() { + return $this->testCases; } } diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index 2e86e19..b3ed91f 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -17,7 +17,7 @@ class rtPhpTestRun { protected $commandLineArguments; protected $runConfiguration; - protected $redirectedTestCases; + protected $redirectedTestCases = array(); public function __construct($argv) { @@ -71,7 +71,10 @@ class rtPhpTestRun } } - if($this->redirectedTestCases != null) { + if(count($this->redirectedTestCases) > 0) { + foreach($this->redirectedTestCases as $testCase){ + echo $testCase->getName() . "\n"; + } //For each test case - construct a new group //Call run_group() again with an array of groups // @@ -132,10 +135,17 @@ class rtPhpTestRun $scheduler->run(); $resultList = $scheduler->getResultList(); - - //Check to see if there are any redirected tests. - - $this->redirectedTestCases = $scheduler->getRedirectedTestCases(); + + //locate any redirected tests in teh group results files. + foreach ($resultList as $testGroupResults) { + + foreach ($testGroupResults as $testResult) { + + if($testResult->getStatus() == 'redirected') { + $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); + } + } + } // create output $type = null; diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php new file mode 100644 index 0000000..1a3ff74 --- /dev/null +++ b/tests/rtPhpTestGroupTest.php @@ -0,0 +1,59 @@ +<?php +require_once dirname(__FILE__) . '/../src/rtAutoload.php'; +require_once dirname(__FILE__) . '/rtTestBootstrap.php'; + +class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase +{ + + public function setUp() { + } + + public function testCreateInstance() + { + $directory = realpath(dirname(__FILE__) . '/../phpt-tests'); + $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, $directory)); + + $config->configure(); + + $phpTestGroup = new rtPhpTestGroup($config, $directory); + + + $validTestCaseCount = count($phpTestGroup->getTestCases()); + $phptFileCount = count(glob($directory . "/*.phpt")); + $inValidTestCaseCount = count($phpTestGroup->getResults()); + + //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. + + $this->assertEquals($phptFileCount, $validTestCaseCount + $inValidTestCaseCount); + + } + + public function testFindRedirect() + { + $directory = realpath(dirname(__FILE__) . '/../phpt-tests'); + $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, $directory)); + + $config->configure(); + + $phpTestGroup = new rtPhpTestGroup($config, $directory); + + + + $inValidTests = $phpTestGroup->getResults(); + + foreach($inValidTests as $testResult) { + if($testResult->getStatus() == 'redirected') { + //If the status has been set to redirected it should have a valid REDIRECTTEST section + $testCase = $testResult->getRedirectedTestCase(); + $this->assertTrue($testCase->hasSection('REDIRECTTEST')); + } + } + } + + + +} +?> diff --git a/tests/testcase/sections/configurationsections/rtRedirectSectionTest.php b/tests/testcase/sections/configurationsections/rtRedirectSectionTest.php new file mode 100644 index 0000000..1475234 --- /dev/null +++ b/tests/testcase/sections/configurationsections/rtRedirectSectionTest.php @@ -0,0 +1,13 @@ +<?php +require_once dirname(__FILE__) . '../../../../../src/rtAutoload.php'; + +class rtRedirectSectionTest extends PHPUnit_Framework_TestCase +{ + public function testCreateInstance() + { + $redirectSection = rtRedirectSection::getInstance('REDIRECTTEST', 'contents', 'testname'); + + $this->assertEquals('contents', $redirectSection->getContents()); + } +} +?>
« previous php.qa (#66741) next »