Ok I realise I missed a part of the documentation - I needed to implement a TestListener...
Code: Select all
<?
class SimpleTestListener implements PHPUnit_Framework_TestListener {
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time){
printf( "Error while running test '%s'.<br>", $test->getName());
}
public function addFailure(
PHPUnit_Framework_Test $test,
PHPUnit_Framework_AssertionFailedError $e,
$time){
}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time){
printf("Test '%s' is incomplete.<br>", $test->getName());
}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time){
printf("Test '%s' has been skipped.<br>", $test->getName());
}
public function startTest(PHPUnit_Framework_Test $test){
printf("%s()... ", $test->getName());
}
public function endTest(PHPUnit_Framework_Test $test, $time){
if ($test->getStatus()){
echo "FAILED... " . $test->getStatusMessage() . " ";
} else {
echo "OK. ";
}
echo "(". $test->getNumAssertions() ." assertions run) <br>";
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite){
printf("<h2>TestSuite '%s' started</h2>", $suite->getName());
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite){
}
}
?>
Then use it like this:
Code: Select all
class TestTest extends PHPUnit_Framework_TestCase {
public function testTest() {
}
}
$suite = new PHPUnit_Framework_TestSuite('TestTest');
$result = new PHPUnit_Framework_TestResult;
$result->addListener(new SimpleTestListener());
$suite->run($result);
But my next questions are:
1) Which class/method I need to extend to output the assertion message in the format I want. For example, when this assertion fails:
$this->assertTrue(false, "My assertion X failed");
it would currently output:
My assertion X failed Failed asserting that is true.
2) How to make the listener respond to successful assertions
Thanks