I am working on a custom test listener for phpunit and I am unable to get the status of a test after it finishes. When I call getStatus() on the test after it is finished I am getting null instead of the status. I have tried this out on some tests where one passes, one is incomplete and one fails, but getStatus() returns null for all of them.
I am using PHPUnit version 3.7.10
Here is my test listener code:
class MyTestListener implements PHPUnit_Framework_TestListener
{
protected $tests = array();
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function startTest(PHPUnit_Framework_Test $test) {}
public function endTest(PHPUnit_Framework_Test $test, $time) {
$this->tests[] = array('test'=>$test, 'time'=>$time);
$status = $test->getStatus();
//NOTE: $status is null
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {}
public function __destruct() {
foreach($this->tests as $d) {
$test = $d['test'];
$time = $d['time'];
$testClass = get_class($test);
$status = $test->getStatus();
//NOTE: $status is null here
if($status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
$status = "fail - ";
} else if($status == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) {
$status = "skip - ";
} else if($status == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
$status = "inc - ";
} else if($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) {
$status = "err - ";
} else {
$status = $status."ok - ";
}
print $status.$testClass."::".$test->getName()." ".round($time,1)." seconds
";
}
}
}
Anyone have any ideas of what I am doing wrong?