The PHPUnit command Line test tool is invoked by the PHPUnit command. The following code shows how to run a test through the PHPUnit command-line test tool.
phpunit ArrayTest
PHPUnit 2.3.0 by Sebastian Bergmann.
Time: 0.067288
OK (2 tests)
For each test, the PHPUnit command line test tool prints a character representing the process:
• Test successfully print "."
• Run test method is an assertion failed to print "F".
• Run test method is an error printing "E".
• The test did not complete or the test did not implement print "I" (see the "Unfinished Test" chapter after this book).
PHPUnit can distinguish between failures and errors. One failure is phpunit assertion violation, error is an unexpected exception or a PHP error. Sometimes this difference is useful because errors are easier to fix than failures. If you have a list of questions, it's best to fix all the errors and see if there are any failures left.
Let's look at some of the following options for the Code Command-Line test tool:
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 to file.
--testdox-text <file> Write agile documentation in Text format to file.
--log-xml <file> Log test progress in XML format to file.
--loader <loader> TestSuiteLoader implementation to use.
--skeleton Generate skeleton UnitTest class for Unit in Unit.php.
--wait Waits for a keystroke after each test.
--help Prints this usage information.
--version Prints the version and exits.
PHPUnit UnitTest
Run the test provided by the class UnitTest, which should be defined in the source file unittest.php.
Class UnitTest must inherit the Phpunit2_framework_testcase class, or provide a public static method suite, and return a class of Phpunit2_ Framework_test objects (for example, class phpunit2_ An instance of Framework_testsuite)
PHPUnit UnitTest unittest.php
Run the test provided by the class UnitTest, which is defined in the source file (unittest.php) specified by the command.
--coverage-data,--coverage-html, and--coverage-text
Controls the analysis and collection of code coverage information for running tests (see section on Code Coverage analysis after this book)
--testdox-html and--testdox-text
Generate an agile document that runs tests in HTML or plain text format (see the "Other uses for tests" chapter later in this book)
--log-xml
Generates an XML-formatted log file that runs tests.