Implement PHPUnit2_Framework_TestListener
You do not necessarily need to write a whole subclass of
PHPUnit2_Framework_TestResult
to customize it. Most of the time, it will suffice to implement a new PHPUnit2_Framework_ TestListener
(see Table 15) and attach it to the PHPUnit2_ Framework_TestResult
object, before running the tests.
Example 26 shows a simple implementation of the PHPUnit2_ Framework_TestListener
interface.
Example 26. A simple test listener
<?php require_once 'PHPUnit2/Framework/TestListener.php'; class SimpleTestListener implements PHPUnit2_Framework_TestListener { public function addError(PHPUnit2_Framework_Test $test, Exception $e) { printf( "Error while running test '%s'.\n", $test->getName( ) ); } public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { printf( "Test '%s' failed.\n", $test->getName( ) ); } public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { printf( "Test '%s' is incomplete.\n", $test->getName( ) ); } public function startTest(PHPUnit2_Framework_Test $test) { printf( "Test '%s' started.\n", $test->getName( ) ); } public function endTest(PHPUnit2_Framework_Test $test) { printf( "Test '%s' ended.\n", $test->getName( ) ); } public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { printf( "TestSuite '%s' started.\n", $suite->getName( ) ); } public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { printf( "TestSuite '%s' ended.\n", $suite->getName( ) ...
Get PHPUnit Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.