B1. Basic implementation and usage

Code below shows a cut-down version of original PHP_CodeSniffer/tests/AllTests.php (1.2.0RC2)

PHP code
  1. class PHP_CodeSniffer_AllTests
  2. {
  3.     public static function main()
  4.     {
  5.         PHPUnit_TextUI_TestRunner::run(self::suite());
  6.     }
  7.  
  8.     public static function suite()
  9.     {
  10.         $suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer');
  11.         $suite->addTest(PHP_CodeSniffer_Core_AllTests::suite());
  12.         $suite->addTest(PHP_CodeSniffer_Standards_AllSniffs::suite());
  13.         spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
  14.         return $suite;
  15.     }
  16. }
generated by Generic Syntax Highlighter - GeSHi

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

PHP code
  1. class PHP_CodeSniffer_AllTests
  2. {
  3.     public static function main()
  4.     {
  5.         include_once('PEAR/TestRunner.php');
  6.         PEAR_TestRunner::run(self::suite());
  7.     }
  8.  
  9.     public static function suite()
  10.     {
  11.         $suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer');
  12.         $suite->addTest(PHP_CodeSniffer_Core_AllTests::suite());
  13.         $suite->addTest(PHP_CodeSniffer_Standards_AllSniffs::suite());
  14.         spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
  15.         return $suite;
  16.     }
  17. }
generated by Generic Syntax Highlighter - GeSHi

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

php path/to/PHP_CodeSniffer/AllTests.php

PHPUnit 3.3.16 by Sebastian Bergmann.

............................................................  60 / 169
...................................................SS....... 120 / 169
..............................................S..

Time: 0 seconds

OK, but incomplete or skipped tests!
Tests: 169, Assertions: 33, Skipped: 3.

You will find text file in /pear/test_dir/PEAR_TestRunner_20090602.log, with a following cut-down version.

[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'PHP CodeSniffer' started.
[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'PHP CodeSniffer Core' started.
[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'Core_IsCamelCapsTest' started.
[2009-06-02 22:46:01] PEAR_TestRunner: Test 'testValidNotClassFormatPublic' started.
... more ...
[2009-06-02 22:46:01] PEAR_TestRunner: Test 'testInvalidClassFormatPrivate' ended.
[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'Core_IsCamelCapsTest' ended.
[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'PHP CodeSniffer Core' ended.
[2009-06-02 22:46:01] PEAR_TestRunner: TestSuite 'PHP CodeSniffer Standards' started.
[2009-06-02 22:46:01] PEAR_TestRunner: Test 'DuplicateClassName' started.
... more ...
[2009-06-02 22:46:02] PEAR_TestRunner: Test 'ValidVariableName' ended.
[2009-06-02 22:46:02] PEAR_TestRunner: TestSuite 'PHP CodeSniffer Standards' ended.
[2009-06-02 22:46:02] PEAR_TestRunner: TestSuite 'PHP CodeSniffer' ended.
[2009-06-02 22:46:02] PEAR_TestRunner: TestSuite was successful. Tests: 169, Assertions: 33, Skipped: 3.