diff --git a/Unit_testing/SimpleTestListener.php b/Unit_testing/SimpleTestListener.php index 3d48555..07b0472 100644 --- a/Unit_testing/SimpleTestListener.php +++ b/Unit_testing/SimpleTestListener.php @@ -2,7 +2,7 @@ class SimpleTestListener implements PHPUnit_Framework_TestListener { /** - * When you're running test suites, the various count methods in TestResult return only the total number of tests, fails, etc., for the entire Test, even if you filter the tests to be run within a given suite. We therefore need to keep track of these within the test listener for each suite. The results are indexed by suite name, which will be something like "BDL_Test_Staff_structure::testFoo". + * When you're running test suites, the various count methods in TestResult return only the total number of tests, fails, etc., for the entire Test, even if you filter the tests to be run within a given suite. We therefore need to keep track of these within the test listener for each suite and test. The results are indexed by suite/test name, which will be something like "BDL_Test_Staff_structure::testFoo"/"testFoo". */ private $passes = array(); private $fails = array(); @@ -14,98 +14,110 @@ /** * These keep track of the counts within a given suite execution, and are reset at the start of every new suite. I'm not sure whether nested suites are stored as actual TestSuite objects. If not, this could mean that the counts for the enclosing suites may be wrong? */ - private $passCount = 0; - private $failCount = 0; - private $errorCount = 0; + private $suitePassCount = 0; + private $suiteFailCount = 0; + private $suiteErrorCount = 0; private $incompleteCount = 0; - private $skipCount = 0; - private $testCount = 0; + private $suiteSkipCount = 0; + private $suiteTestCount = 0; - public function countPasses( $suiteName ) + public function countPasses( $name ) { - return $this->passes[ $suiteName ]; + return $this->passes[ $name ]; } - public function countFails( $suiteName ) + public function countFails( $name ) { - return $this->fails[ $suiteName ]; + return $this->fails[ $name ]; } - public function countErrors( $suiteName ) + public function countErrors( $name ) { - return $this->errors[ $suiteName ]; + return $this->errors[ $name ]; } - public function countIncompletes( $suiteName ) + public function countIncompletes( $name ) { - return $this->incompletes[ $suiteName ]; + return $this->incompletes[ $name ]; } - public function countSkips( $suiteName ) + public function countSkips( $name ) { - return $this->skips[ $suiteName ]; + return $this->skips[ $name ]; } - public function countTests( $suiteName ) + public function countTests( $name ) { - return $this->tests[ $suiteName ]; + return $this->tests[ $name ]; + } + + public function wasSuccessful( $name ) + { + return ( $this->countPasses( $name ) === $this->countTests( $name ) ); } public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { echo "ERROR! " . $e->getMessage() . "\n"; - $this->errorCount++; + $this->suiteErrorCount++; + $this->errors[ $test->getName() ] = 1; } public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { echo "FAILED! " . $e->getMessage() . "\n"; - $this->failCount++; + $this->suiteFailCount++; + $this->fails[ $test->getName() ] = 1; } public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { echo "INCOMPLETE: " . $e->getMessage() . "\n"; $this->incompleteCount++; + $this->incompletes[ $test->getName() ] = 1; } public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { echo "SKIPPED: " . $e->getMessage() . "\n"; - $this->skipCount++; + $this->suiteSkipCount++; + $this->skips[ $test->getName() ] = 1; } public function startTest(PHPUnit_Framework_Test $test) { -// printf("Test '%s' started.\n", $test->getName()); - $this->testCount++; +// printf("@@@ Test '%s' started.\n", $test->getName()); + $this->suiteTestCount++; + $this->tests[ $test->getName() ] = 1; } public function endTest(PHPUnit_Framework_Test $test, $time) { -// printf("Test '%s' ended.\n", $test->getName()); +// printf("@@@ Test '%s' ended.\n", $test->getName()); if ( $test->getStatus() === PHPUnit_Runner_BaseTestRunner::STATUS_PASSED ) { echo "OK\n"; - $this->passCount++; + $this->suitePassCount++; + $this->passes[ $test->getName() ] = 1; } } public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { -// printf("TestSuite '%s' started.\n", $suite->getName()); - $this->passCount = $this->failCount = $this->errorCount = $this->incompleteCount = $this->skipCount = $this->testCount = 0; +// printf("@@@ TestSuite '%s' started.\n", $suite->getName()); + $this->suitePassCount = $this->suiteFailCount = $this->suiteErrorCount = + $this->incompleteCount = $this->suiteSkipCount = $this->suiteTestCount = 0; } public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { -// printf("TestSuite '%s' ended.\n", $suite->getName()); - $this->passes[ $suite->getName() ] = $this->passCount; - $this->fails[ $suite->getName() ] = $this->failCount; - $this->errors[ $suite->getName() ] = $this->errorCount; +// printf("@@@ TestSuite '%s' ended.\n", $suite->getName()); + $this->passes[ $suite->getName() ] = $this->suitePassCount; + $this->fails[ $suite->getName() ] = $this->suiteFailCount; + $this->errors[ $suite->getName() ] = $this->suiteErrorCount; $this->incompletes[ $suite->getName() ] = $this->incompleteCount; - $this->skips[ $suite->getName() ] = $this->skipCount; - $this->tests[ $suite->getName() ] = $this->testCount; + $this->skips[ $suite->getName() ] = $this->suiteSkipCount; + $this->tests[ $suite->getName() ] = $this->suiteTestCount; } } ?>