B4. Basic usage with a XML configuration file

Code below shows a cut-down version of original XML_Util/tests/AllTests.php (1.2.1)

PHP code
  1. <?php
  2. class XML_Util_AllTests
  3. {
  4.     public static function main()
  5.     {
  6.         PHPUnit_TextUI_TestRunner::run(self::suite());
  7.     }
  8.  
  9.     public static function suite()
  10.     {
  11.         $suite = new PHPUnit_Framework_TestSuite(
  12.             'XML_Util Full Suite of Unit Tests');
  13.  
  14.         $phpt = new PHPUnit_Extensions_PhptTestSuite(XML_UTIL_DIR_PHPT);
  15.         $suite->addTestSuite($phpt);
  16.  
  17.         return $suite;
  18.     }
  19. }
  20. ?>
generated by Generic Syntax Highlighter - GeSHi

We will replace the highlihted yellow line as follow (lines 6-7) :

PHP code
  1. <?php
  2. class XML_Util_AllTests
  3. {
  4.     public static function main()
  5.     {
  6.         include_once 'PEAR/TestRunner.php';
  7.         PEAR_TestRunner::run(self::suite());
  8.     }
  9.  
  10.     public static function suite()
  11.     {
  12.         $suite = new PHPUnit_Framework_TestSuite(
  13.             'XML_Util Full Suite of Unit Tests');
  14.  
  15.         $phpt = new PHPUnit_Extensions_PhptTestSuite(XML_UTIL_DIR_PHPT);
  16.         $suite->addTestSuite($phpt);
  17.  
  18.         return $suite;
  19.     }
  20. }
  21. ?>
generated by Generic Syntax Highlighter - GeSHi

XML code: phpunit.xml
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <phpunit>
  3.     <loggers>
  4.         <file ident="XML_Util_AllTests" name="C:\wamp\bin\php\php5.2.9-2\tmp\xml_util_alltests.log" />
  5.         <composite>
  6.             <file ident="XML_Util_AllTests" />
  7.         </composite>
  8.     </loggers>
  9. </phpunit>
generated by Generic Syntax Highlighter - GeSHi

To run all the tests that are declared in XML_Util_AllTests::suite() we can use the following command:

php path/to/XML_Util/AllTests.php  --configuration /path/to/phpunit.xml

PHPUnit 3.3.16 by Sebastian Bergmann.

..................

Time: 6 seconds

OK (18 tests, 0 assertions)

You will find text file as defined in phpunit.xml (line 4), with a following cut-down version.

Jun 05 19:43:05 XML_Util_AllTests [info] TestSuite 'XML_Util Full Suite of Unit Tests' started.
Jun 05 19:43:05 XML_Util_AllTests [info] TestSuite 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests' started.
Jun 05 19:43:05 XML_Util_AllTests [info] Test 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests\testBasic_apiVersion.phpt' started.
Jun 05 19:43:05 XML_Util_AllTests [info] Test 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests\testBasic_apiVersion.phpt' ended.
... more ...
Jun 05 19:43:11 XML_Util_AllTests [info] Test 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests\testBug_5392.phpt' started.
Jun 05 19:43:11 XML_Util_AllTests [info] Test 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests\testBug_5392.phpt' ended.
Jun 05 19:43:11 XML_Util_AllTests [info] TestSuite 'C:\wamp\bin\php\php5.2.9-2\tests\XML_Util\tests' ended.
Jun 05 19:43:11 XML_Util_AllTests [info] TestSuite 'XML_Util Full Suite of Unit Tests' ended.
Jun 05 19:43:11 XML_Util_AllTests [notice] TestSuite was successful. Tests: 18.