Chapter 5. The Command-Line Test Runner

The PHPUnit command-line test runner is invoked through the phpunit command. The following code shows how to run tests with the PHPUnit command-line test runner:

phpunit ArrayTest
PHPUnit 2.3.0 by Sebastian Bergmann.

..

Time: 0.067288

OK (2 tests)

For each test run, the PHPUnit command-line tool prints one character to indicate progress:

. Printed when the test succeeds.
F Printed when an assertion fails while running the test method.
E Printed when an error occurs while running the test method.
I Printed when the test is marked as being incomplete or not yet implemented (see "Incomplete Tests," later in this book).

PHPUnit distinguishes between failures and errors. A failure is a violated PHPUnit assertion. An error is an unexpected exception or a PHP error. Sometimes this distinction proves useful because errors tend to be easier to fix than failures. If you have a big list of problems, it's best to tackle the errors first and see if you have any failures left when the errors are all fixed.

Let's take a look at the command-line test runner's switches in the following code:

phpunit --help PHPUnit 2.3.0 by Sebastian Bergmann. Usage: phpunit [switches] UnitTest [UnitTest.php] --coverage-data <file> Write code-coverage data in raw format to file. --coverage-html <file> Write code-coverage data in HTML format to file. --coverage-text <file> Write code-coverage data in text format to file. --testdox-html <file> Write agile documentation in HTML format ...

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.