0
我正在爲phpunit進行自定義測試偵聽器,並且在完成後我無法獲得測試的狀態。在測試結束後,當我在測試中調用getStatus()時,我得到的是null而不是狀態。我已經在一些測試中嘗試了這一點,其中一個不完整,一個失敗,但getStatus()對所有測試都返回null。phpunit的自定義偵聽器的測試狀態爲空
我使用PHPUnit的版本3.7.10
這裏是我的測試監聽器代碼:
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\n";
}
}
}
任何人有什麼我做錯了任何想法?