As default PEAR_TestListener SplObserver Interface only listen one event "endTestSuite", we need to define our own version to have ability to listen other events.
In this example we suppose that our class PHP_Reflector have no SplSubject interface defined. So we will use the Event_Dispatcher package to notify additionnal (debug) events : 'startTest', 'endTest' We will see implementation later.
NOTE: In case our class PHP_Reflector got one day a real SplSubject Interface, we have nothing to change here, because we used the subject adapter feature (lines 16-22).
IMPORTANT: Do not forget line 11, otherwise this update method implementation (lines 14-39) won't be called.
In this test suite launcher, important lines are :
We used also two handlers (file, mail) with custom values.
For more fine-grained control of which tests to run we can use the --group
switch
php path/to/PHP_Reflector/AllTests.php --group parser PHPUnit 3.3.16 by Sebastian Bergmann. .............I Time: 0 seconds OK, but incomplete or skipped tests! Tests: 14, Assertions: 27, Incomplete: 1.
Valuable with alternative solution: see code above
php path/to/PHP_Reflector/AllTests.php --configuration path/to/config/file/phpunit.xml --group parser PHPUnit 3.3.16 by Sebastian Bergmann. .............I Time: 0 seconds OK, but incomplete or skipped tests! Tests: 14, Assertions: 27, Incomplete: 1.
You will find text file in /where/ever/you/want/PHP_Reflector_TestSuite_Parser_20090603.log
,
with content as follow.
[2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: TestSuite 'PHP_Reflector_TestSuite_Parser' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringSimpleClass' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringSimpleClass' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringAbstractClass' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringAbstractClass' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringInterface' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringInterface' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringClassWithMethod' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringClassWithMethod' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringClassWithConstant' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringClassWithConstant' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringAccessingProperties' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringAccessingProperties' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testFilteringClass' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testFilteringClass' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testFilteringInterface' started. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testFilteringInterface' ended. [2009-06-03 21:48:54] PHP_Reflector_TestSuite_Parser: Test 'testFilteringProperty' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testFilteringProperty' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testFilteringMethod' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testFilteringMethod' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testMethodChaining' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testMethodChaining' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testMethodChainingInClass' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testMethodChainingInClass' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testProceduralCode' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testProceduralCode' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringFunction' started. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringFunction' is incomplete. This test has not been implemented yet. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringFunction' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: TestSuite 'PHP_Reflector_TestSuite_Parser' ended. [2009-06-03 21:48:55] PHP_Reflector_TestSuite_Parser: TestSuite was successful. Tests: 14, Assertions: 27, Incomplete: 1.
And you will get an email named PHP_Reflector_TestSuite_Parser results with this body
Jun 03 21:48:55 - Test 'testDeclaringFunction' is incomplete. This test has not been implemented yet. Jun 03 21:48:55 - TestSuite was successful. Tests: 14, Assertions: 27, Incomplete: 1.
FAQ:
Even if our custom TestListener class is ready (PHP_Reflector_TestListener), we have now to implement some notification send at right places.
Have a look inside one test case: for example 'testDeclaringSimpleClass' and especially lines 8,10.
To have a chance to see these new informations on text file, don't forget to change LOG level (see above PHP_Reflector_TestSuite_Parser line 15) accordingly to the one used into PHP_Reflector_TestListener into update method at line 28 and 33. ==> PEAR_LOG_DEBUG
And if you run command below ...
php path/to/PHP_Reflector/AllTests.php --filter testDeclaringSimpleClass PHPUnit 3.3.16 by Sebastian Bergmann. . Time: 0 seconds OK (1 test, 1 assertion)
... you can see the new text file result as follow
[2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: TestSuite 'PHP_Reflector_TestSuite_Parser' started. [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringSimpleClass' started. [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: Parsing files 'array ( 0 => \'C:\\\\wamp\\\\bin\\\\php\\\\php5.2.9-2\\\\includes\\\\PHP\\\\tests\\\\parseFile\\\\parser_simpleclass.php\', )' [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: Parsing results array ( 'C:\\wamp\\bin\\php\\php5.2.9-2\\includes\\PHP\\tests\\parseFile\\parser_simpleclass.php' => array ( 'extensions' => array ( ), 'classes' => array ( 'myClass' => array ( 'attribs' => array ( 'class' => array ( 0 => 'user', ), 'file' => 'C:\\wamp\\bin\\php\\php5.2.9-2\\includes\\PHP\\tests\\parseFile\\parser_simpleclass.php', 'start' => 2, 'end' => 3, 'docblock' => '', ), 'constants' => array ( ), 'static_properties' => array ( ), 'static_methods' => array ( ), 'properties' => array ( ), 'methods' => array ( ), ), ), 'functions' => array ( ), 'constants' => array ( ), 'includes' => array ( ), ), ) [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: Test 'testDeclaringSimpleClass' ended. [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: TestSuite 'PHP_Reflector_TestSuite_Parser' ended. [2009-06-03 22:17:44] PHP_Reflector_TestSuite_Parser: TestSuite was successful. Test: 1, Assertion: 1.