For each test run, the PHPUnit command-line tool prints one character to indicate progress:
phpunit UnitTest
-
Runs the tests that are provided by the class UnitTest. This class is expected to be declared in the UnitTest.php source file.
UnitTest must be either a class that inherits from PHPUnit2_Framework_TestCase or a class that provides a public static suite( ) method that returns a PHPUnit2_ Framework_Test object (for example, an instance of the PHPUnit2_Framework_TestSuite class).
phpunit UnitTest UnitTest.php
-
Runs the tests that are provided by the class UnitTest. This class is expected to be declared in the specified source file.
--coverage-data, --coverage-html, and --coverage-text
-
Controls the collection and analysis of code-coverage information for the tests that are run. (See the section "Code-Coverage Analysis," later in this book.)
--testdox-html and --testdox-text
-
Generates agile documentation in HTML or plain text format for the tests that are run. (See "Other Uses for Tests," later in this book.)
--log-xml
-
Generates a logfile in XML format for the tests run.
The following example shows the XML logfile generated for the tests in ArrayTest:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="ArrayTest" tests="2" failures="0"
errors="0" time="0.020026">
<testcase name="testNewArrayIsEmpty"
class="ArrayTest" time="0.014449"/>
<testcase name="testArrayContainsAnElement"
class="ArrayTest" time="0.005577"/>
</testsuite>
</testsuites>
The following XML logfile was generated for two tests, testFailure and testError, of a test-case class named FailureErrorTest. It shows how failures and errors are denoted.
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="FailureErrorTest" tests="2"
failures="1" errors="1" time="0.013603">
<testcase name="testFailure"
class="FailureErrorTest" time="0.011872">
<failure message=""
type="PHPUnit2_Framework_AssertionFailedError">
</failure>
</testcase>
<testcase name="testError"
class="FailureErrorTest" time="0.001731">
<error message="" type="Exception"></error>
</testcase>
</testsuite>
</testsuites>
--loader
-
Specifies the PHPUnit2_Runner_TestSuiteLoader implementation to use.
The standard test-suite loader will look for the source file in the current working directory and in each directory that is specified in PHP's include_path configuration directive. Following the PEAR Naming Conventions, a class name such as Project_Package_Class is mapped to the source file name Project/Package/Class.php.
--skeleton
-
Generates a skeleton test-case class UnitTest (in UnitTest. php) for a class Unit (inUnit.php). For each method in the original class, there will be an incomplete test case (see "Incomplete Tests,"later in this book) in the generated test-case class.
The following example shows how to generate a skeleton test class for a class named Sample:
phpunit --skeleton Sample
PHPUnit 2.3.0 by Sebastian Bergmann.
Wrote test class skeleton for Sample to
SampleTest.php.
phpunit SampleTest
PHPUnit 2.3.0 by Sebastian Bergmann.
I
Time: 0.007268
There was 1 incomplete test case:
1) testSampleMethod(SampleTest)
OK, but incomplete test cases!!!
Tests run: 1, incomplete test cases: 1.
When you are writing tests for existing code, you have to write the same code fragments over and over again, as in the following example:
public function testSampleMethod( ) {
}
PHPUnit can help you by analyzing the existing code and generating a skeleton test-case class for it.
--wait
-
Waits for a keystroke after each test. This is useful if you are running the tests in a window that stays open only as long as the test runner is active.