phpunit
Run PHP unit tests
TLDR
Run tests in the current directory. Note: Expects you to have a 'phpunit.xml'
Run tests in a specific file
Run tests annotated with the given group
Run tests and generate a coverage report in HTML
SYNOPSIS
phpunit [options] [testfile|testdirectory]
PARAMETERS
--configuration
Read configuration from XML file.
--coverage-clover
Generate Clover XML coverage report.
--coverage-crap4j
Generate Crap4J XML coverage report.
--coverage-html
Generate HTML coverage report.
--coverage-php
Export PHP code coverage data to file.
--coverage-text
Generate text coverage report. Default: Standard output.
--coverage-xml
Generate XML coverage report.
--debug
More verbose output.
--filter
Filter which tests to run.
--group
Only runs tests from the specified group(s).
--help
Prints this usage information.
--list-groups
List available test groups.
--list-suites
List available test suites.
--list-tests
List available tests.
--log-junit
Log test execution in JUnit XML format to file.
--no-configuration
Ignore phpunit.xml configuration file.
--no-coverage
Ignore code coverage configuration.
--process-isolation
Run each test in a separate PHP process.
--repeat
Runs the test(s) repeatedly.
--testsuite
Only runs tests from the specified test suite.
--verbose
Output more verbose information, including test names.
--version
Prints the version and exits.
DESCRIPTION
The `phpunit` command is a powerful command-line tool for executing PHP unit tests. It's part of the PHPUnit testing framework, which allows developers to write and run repeatable tests to ensure the quality and correctness of their code. PHPUnit supports features like test doubles, data providers, code coverage analysis, and various assertion methods. The `phpunit` command automatically discovers and runs tests in your project, providing detailed reports on test results. It's an essential tool for practicing Test-Driven Development (TDD) and ensuring robust PHP applications. Configuration is handled via a `phpunit.xml` file, allowing for extensive customization of the test execution environment. It supports generating reports in various formats, including HTML, XML, and plain text.
CAVEATS
Requires PHP and the PHPUnit library to be installed. Configuration files (phpunit.xml) are crucial for defining test suites and other options. Paths specified as arguments are relative to the current working directory.
CONFIGURATION FILE
The phpunit.xml file configures PHPUnit. It specifies test suites, code coverage options, and other settings. Example: <phpunit>
<testsuites>
<testsuite name="My Project Tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
RETURN CODES
PHPUnit returns different exit codes to indicate test success or failure. An exit code of 0 typically indicates that all tests passed, while non-zero exit codes indicate failures, errors, or other issues.
HISTORY
PHPUnit was originally created by Sebastian Bergmann. It was inspired by JUnit for Java. It has evolved from simple unit testing to a full suite of tools supporting various testing methodologies in PHP. The `phpunit` command is the primary executable to run tests.