4. CLI Options
This appendix provides a reference overview of all command-line options supported by PHPUnit’s test runner.
Configuration
--bootstrap <file>Specifies a PHP script that is included before any tests are executed. This is typically used to set up autoloading or initialize the environment required by the test suite.
-c,--configuration <file>Reads configuration from the specified XML file instead of the default
phpunit.xml. This allows you to maintain multiple configuration files for different testing scenarios.--no-configurationIgnores the default
phpunit.xmlconfiguration file. Useful when you want to run tests without any XML-based configuration being applied.--extension <class>Registers a test runner extension by specifying its bootstrap class. The extension will be loaded and activated for the current test run.
--no-extensionsPrevents any test runner extensions from being registered. This disables all extensions, including those configured in the XML configuration file.
--include-path <path(s)>Prepends PHP’s
include_pathwith the given path or paths. Multiple paths can be specified, separated by the platform’s path separator.-d <key[=value]>Sets a
php.iniconfiguration value for the duration of the test run. For boolean settings, the value can be omitted to set it to1.--cache-directory <dir>Specifies the directory where PHPUnit stores data between test suite runs. The following data is stored in this directory:
test-run-history: Status and duration of each test from the previous test suite run (used for reordering tests based on previous defects or duration with the--order-byoption, for instance)code-coverage: Results of static analysis of tested code and test code (only written when code coverage reporting is requested; significantly improves performance of code coverage analysis on subsequent runs)
--generate-configurationGenerates a
phpunit.xmlconfiguration file with suggested settings through an interactive wizard. This is a convenient way to bootstrap a new PHPUnit configuration.--migrate-configurationMigrates an existing XML configuration file to the current format. This is useful after upgrading PHPUnit to a new major version that introduces configuration changes.
--validate-configurationValidates the XML configuration file against the XML schema definition for the current PHPUnit version and then exits. Validation errors are reported with the line numbers on which they occur.
--generate-baseline <file>Generates a baseline file that records currently existing issues such as deprecations and warnings. This baseline can later be used to suppress known issues so that only new issues are reported.
--use-baseline <file>Uses a previously generated baseline file to suppress known issues during the test run. Issues recorded in the baseline will not be reported.
--ignore-baselineIgnores any configured baseline file, causing all issues to be reported regardless of whether they appear in the baseline.
Selection
--allIgnores test selection configured in the XML configuration file and runs all discovered tests. This overrides any
<testsuites>filtering from the configuration.--list-suitesLists all available test suites defined in the XML configuration file and then exits. No tests are executed.
--testsuite <name>Restricts test execution to the specified test suite or suites. Multiple suite names can be separated by commas.
--exclude-testsuite <name>Excludes the specified test suite or suites from the test run. Multiple suite names can be separated by commas.
--list-groupsLists all available test groups and then exits. No tests are executed.
--group <name>Only runs tests belonging to the specified group. This option can be used multiple times to select tests from more than one group. Names separated with
+select the tests that are in all of the named groups:--group database+slowonly runs the tests that are in the groupdatabaseand in the groupslow. See Filtering by group.--exclude-group <name>Excludes tests belonging to the specified group from the test run. This option can be used multiple times to exclude tests from more than one group. Names separated with
+exclude the tests that are in all of the named groups. See Filtering by group.--covers <name>Only runs tests that declare they intend to cover the specified class or function. This filters based on
#[Covers*]attributes. This option can be used multiple times.--uses <name>Only runs tests that declare they intend to use the specified class or function. This filters based on
#[Uses*]attributes. This option can be used multiple times.--requires-php-extension <name>Only runs tests that declare a requirement for the specified PHP extension. Tests without this requirement are skipped.
--list-test-filesLists all test files that would be executed and then exits. No tests are actually run.
--list-test-idsLists all tests that would be executed as test IDs and then exits. A test ID is the fully qualified test name, for example
PHPUnit\TestFixture\ExampleTest::testOne. For tests with data sets, a#suffix is appended with the data set index or name, for examplePHPUnit\TestFixture\ExampleTest::testOne#0orPHPUnit\TestFixture\ExampleTest::testOne#named data set.--list-testsLists all tests that would be executed and then exits. Each test is shown with its fully qualified name.
--list-tests-xml <file>Lists all tests that would be executed in XML format and writes the output to the specified file. No tests are actually run.
--filter <pattern>Selects tests whose name matches
<pattern>. In addition to full PCRE regular expressions, a shortcut syntax is accepted for selecting individual data sets (testFoo#3,testFoo#1-3,testFoo@named set,testFoo#named set). See Filtering by test name for the full syntax.--exclude-filter <pattern>The inverse of
--filter; accepts the same pattern syntax and removes matching tests from the run.--test-suffix <suffix>Restricts test file discovery to files with the specified suffix. The defaults are
Test.phpand.phpt. This option can be used multiple times.--test-files-file <file>Only runs tests from the test files listed in the specified file, with one file path per line. This provides an explicit list of test files to execute.
--run-test-id <test-id>Only runs the single test identified by
<test-id>. Matching is strict and exact. A test ID is the fully qualified test name, for examplePHPUnit\TestFixture\ExampleTest::testOne. For tests with data sets, a#suffix is appended with the data set index or name, for examplePHPUnit\TestFixture\ExampleTest::testOne#0orPHPUnit\TestFixture\ExampleTest::testOne#named data set.--test-id-filter-file <file>Only runs the tests listed by test ID in the specified file, with one test ID per line. A test ID is the fully qualified test name, for example
PHPUnit\TestFixture\ExampleTest::testOne.
Execution
--process-isolationRuns each test in a separate PHP process. This ensures complete isolation between tests but significantly increases execution time.
--globals-backupBacks up and restores the
$GLOBALSsuperglobal before and after each test. This prevents tests from inadvertently affecting each other through global state.--static-backupBacks up and restores static properties of all classes before and after each test. This prevents tests from affecting each other through shared static state.
--strict-coverageEnforces strict mode for code coverage metadata. Tests that execute code not declared in their
#[Covers*]or#[Uses*]metadata will be marked as risky.--require-coverage-contributionMarks tests as risky when they have code coverage targets but do not execute any line of the targeted code.
--strict-global-stateEnforces strict checking of global state changes. Tests that modify global state (such as global variables, super-globals, or static properties) will be marked as risky.
--disallow-test-outputMarks tests that produce output (via
echo,print, etc.) as risky. This helps ensure tests only communicate results through assertions.--enforce-time-limitEnforces time limits on test execution based on test size. Small tests get 1 second, medium tests get 10 seconds, and large tests get 60 seconds by default.
--default-time-limit <sec>Sets the timeout in seconds for tests that have no declared size. This is used in conjunction with
--enforce-time-limit.--timeout <sec>Stops the test run after the specified number of seconds of wall-clock time for the entire run, including bootstrapping and loading the test suite. When the limit is exceeded, no further tests are started, the logs are written, the result is printed, and PHPUnit exits with exit code
124. When thepcntlextension is available, the test that is running when the limit is exceeded is aborted and reported as an error. See Limiting the duration of the test run.--do-not-report-useless-testsSuppresses reporting of useless tests. A test is considered useless if it does not perform any assertions.
--stop-on-defect[=<n>]Stops test execution after the first (or n-th) error, failure, warning, or risky test. This is a shorthand for enabling all specific stop-on options. When used without a value, execution stops after the first defect. When a threshold
nis specified, execution stops afterndefects have been encountered.--stop-on-error[=<n>]Stops test execution after the first (or n-th) test that results in an error.
--stop-on-failure[=<n>]Stops test execution after the first (or n-th) test that results in a failure.
--stop-on-warning[=<n>]Stops test execution after the first (or n-th) test that triggers a warning.
--stop-on-risky[=<n>]Stops test execution after the first (or n-th) test that is considered risky.
--stop-on-deprecation[=<n>]Stops test execution after the first (or n-th) test that triggers a deprecation.
--stop-on-notice[=<n>]Stops test execution after the first (or n-th) test that triggers a notice.
--stop-on-skipped[=<n>]Stops test execution after the first (or n-th) skipped test.
--stop-on-incomplete[=<n>]Stops test execution after the first (or n-th) incomplete test.
--fail-on-empty-test-suiteCauses PHPUnit to return a failure exit code when no tests were executed. This is useful in CI pipelines to detect misconfigured test suites.
--fail-on-warningCauses PHPUnit to return a failure exit code when any test triggers a warning.
--fail-on-riskyCauses PHPUnit to return a failure exit code when any test is considered risky.
--fail-on-deprecationCauses PHPUnit to return a failure exit code when any test triggers a deprecation.
--fail-on-self-deprecationCauses PHPUnit to return a failure exit code when any test triggers a deprecation in first-party code. This option only takes effect when PHPUnit can identify how a deprecation was triggered. See Failing on deprecations based on how they are triggered.
--fail-on-direct-deprecationCauses PHPUnit to return a failure exit code when any test triggers a deprecation in third-party code that is called from first-party code. This option only takes effect when PHPUnit can identify how a deprecation was triggered. See Failing on deprecations based on how they are triggered.
--fail-on-indirect-deprecationCauses PHPUnit to return a failure exit code when any test triggers a deprecation in third-party code that is called from third-party code. This option only takes effect when PHPUnit can identify how a deprecation was triggered. See Failing on deprecations based on how they are triggered.
--fail-on-phpunit-deprecationCauses PHPUnit to return a failure exit code when a PHPUnit deprecation is triggered. PHPUnit deprecations relate to deprecated usage of PHPUnit’s own API.
--fail-on-phpunit-noticeCauses PHPUnit to return a failure exit code when a PHPUnit notice is triggered. PHPUnit notices are informational messages about PHPUnit-specific issues.
--fail-on-phpunit-warningCauses PHPUnit to return a failure exit code when a PHPUnit warning is triggered.
--fail-on-noticeCauses PHPUnit to return a failure exit code when any test triggers a notice.
--fail-on-skippedCauses PHPUnit to return a failure exit code when any test is skipped.
--fail-on-incompleteCauses PHPUnit to return a failure exit code when any test is marked incomplete.
--fail-on-all-issuesCauses PHPUnit to return a failure exit code when any issue is triggered. This is a shorthand that enables all
--fail-on-*options at once. It takes precedence over the fine-grainedfailOn*attributes of the XML configuration file; only the--do-not-fail-on-*options can disable failing on a specific issue type when it is used.--do-not-fail-on-empty-test-suiteDisables the signaling of failure when no tests were run. This overrides the corresponding XML configuration setting.
--do-not-fail-on-warningDisables the signaling of failure when a warning is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-riskyDisables the signaling of failure when a test is considered risky. This overrides the corresponding XML configuration setting.
--do-not-fail-on-deprecationDisables the signaling of failure when a deprecation is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-self-deprecationDisables the signaling of failure when a deprecation is triggered in first-party code, even when
--fail-on-deprecationis used. This overrides the corresponding XML configuration setting. See Failing on deprecations based on how they are triggered.--do-not-fail-on-direct-deprecationDisables the signaling of failure when a deprecation is triggered in third-party code that is called from first-party code, even when
--fail-on-deprecationis used. This overrides the corresponding XML configuration setting. See Failing on deprecations based on how they are triggered.--do-not-fail-on-indirect-deprecationDisables the signaling of failure when a deprecation is triggered in third-party code that is called from third-party code, even when
--fail-on-deprecationis used. This overrides the corresponding XML configuration setting. See Failing on deprecations based on how they are triggered.--do-not-fail-on-phpunit-deprecationDisables the signaling of failure when a PHPUnit deprecation is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-phpunit-noticeDisables the signaling of failure when a PHPUnit notice is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-phpunit-warningDisables the signaling of failure when a PHPUnit warning is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-noticeDisables the signaling of failure when a notice is triggered. This overrides the corresponding XML configuration setting.
--do-not-fail-on-skippedDisables the signaling of failure when a test is skipped. This overrides the corresponding XML configuration setting.
--do-not-fail-on-incompleteDisables the signaling of failure when a test is marked incomplete. This overrides the corresponding XML configuration setting.
--record-test-run-historyEnables the recording of the status and duration of each test in the
test-run-historyfile. The test run history is used by the--order-by defects,--order-by duration-ascending, and--order-by duration-descendingoptions to reorder tests based on previous test suite runs.--do-not-record-test-run-historyDisables the recording of the status and duration of each test in the
test-run-historyfile. This overrides the corresponding XML configuration setting. PHPUnit emits a test runner warning when this is combined with--order-by defectsor--order-by duration-*, as those cannot work without the test run history.--warn-when-php-is-not-configured-for-developmentEnables the triggering of a test runner warning when PHP is not configured for development (see Configuring PHP for Development). A warning is triggered for each PHP configuration setting that is not configured as recommended. This overrides the corresponding XML configuration setting.
--do-not-warn-when-php-is-not-configured-for-developmentDisables the triggering of a test runner warning when PHP is not configured for development. This overrides the corresponding XML configuration setting.
--order-by <order>Controls the order in which tests are executed. Accepted orders are
default,duration-ascending,duration-descending,modified-ascending,modified-descending,random,reverse,size-ascending, andsize-descending. Exactly one order can be configured. The order may be followed by,defectsto move the tests that errored or failed during the previous test run to the front, for instance--order-by duration-ascending,defects.--order-by defectscan also be used without configuring an order. See Test execution order.The values
dependsandno-dependsare deprecated, use--resolve-dependenciesand--ignore-dependenciesinstead. Writingdefectsbefore the order, and configuring more than one order, are deprecated as well. The valuesdurationandsizeare still accepted as shortcuts forduration-ascendingandsize-ascendingrespectively, but are deprecated and will be removed in PHPUnit 14.--resolve-dependenciesReorders tests so that as many dependencies between them, expressed using the
Depends*attributes, as possible are resolved. This is the default. This overrides the corresponding XML configuration setting.--ignore-dependenciesDoes not reorder tests to resolve dependencies between them. This overrides the corresponding XML configuration setting.
--random-orderAlias for
--order-by random.--random-order-seed <N>Sets the seed for the random number generator when using
--order-by random. Using the same seed produces the same test order, which is useful for reproducing failures.--repeat <N>Runs each eligible test
Ntimes, stopping at the first failure. This helps find flaky tests and stress-test stateful code. PHPT tests are repeated as well. See Repeating Tests. Mutually exclusive with--retry.--retry <N>Attempts each eligible test up to
Ntimes, stopping at the first success. This helps tolerate flaky tests that cannot be eliminated, while keeping them visible. PHPT tests are retried as well. See Retrying Tests. Mutually exclusive with--repeat.--reverse-orderAlias for
--order-by reverse.
Reporting
--colors=<flag>Controls the use of colors in terminal output. Accepted values are
never,auto(uses colors when the terminal supports it), andalways.--columns <n>Sets the number of columns to use for progress output. This controls the width of the progress bar displayed during test execution.
--columns maxUses the maximum number of columns available in the terminal for progress output.
--diff-context <n>Sets the number of context lines shown around changes in diffs (default:
3). When a test fails and PHPUnit displays the difference between the expected and actual values, this option controls how many unchanged lines are displayed before and after each change to provide context.--stderrWrites output to STDERR instead of STDOUT. This can be useful when STDOUT is being redirected or captured.
--no-progressDisables the progress section of the default output (see Progress). Alternative output formats selected via
--testdox,--teamcity,--compact, or--debugare not affected by this option.--no-resultsDisables the test results and summary sections of the default output (see Test results and Summary). Alternative output formats selected via
--testdox,--teamcity,--compact, or--debugare not affected by this option.--no-outputDisables the default output of PHPUnit (runtime information, progress, test results, and summary). Alternative output formats selected via
--testdox,--teamcity,--compact, or--debugare not affected by this option and will still produce their own output.--display-incompleteDisplays details for incomplete tests in the test results. By default, only a count of incomplete tests is shown.
--display-skippedDisplays details for skipped tests in the test results. By default, only a count of skipped tests is shown.
--display-deprecationsDisplays details for deprecations triggered by tests. This shows the deprecation messages along with their source location.
--display-phpunit-deprecationsDisplays details for PHPUnit deprecations in the test results.
--display-phpunit-noticesDisplays details for PHPUnit notices in the test results. These are informational messages from PHPUnit about potential configuration or usage issues.
--display-errorsDisplays details for errors triggered by tests. This includes PHP errors such as
E_ERRORthat occurred during test execution.--display-noticesDisplays details for notices triggered by tests. This shows PHP notice messages along with their source location.
--display-warningsDisplays details for warnings triggered by tests. This shows PHP warning messages along with their source location.
--display-all-issuesDisplays details for all types of issues. This is a shorthand that enables all
--display-*options at once.
Backward Compatibility
Please note that if you use --display-all-issues then you opt in to
printing additional issues in later versions of PHPUnit that will be put
under the control of this CLI option. This is not considered to be a break of
backward compatibility and rather the expected behaviour of this CLI option.
--reverse-listPrints defects in reverse order. This shows the most recently encountered defects first, which can be useful for large test suites.
--compactReplaces the default progress and result output with a compact format that omits the progress section, the timing and memory usage line, and color codes. By default only errors, failures, risky tests, and the errors and warnings reported by PHPUnit itself are shown in detail; the
--display-*options can be used to include additional issues, which are otherwise only counted in the summary line. Compact output can also be activated by setting thePHPUNIT_COMPACT_OUTPUTenvironment variable to1. See Compact for details.--teamcityReplaces the default progress and result output with TeamCity format. This is used for integration with JetBrains TeamCity and other CI tools that support the TeamCity service message protocol.
--testdoxReplaces the default result output with TestDox format. TestDox renders test method names as human-readable sentences, providing a behavior-driven view of the test suite. To write TestDox output to a file instead, use
--testdox-htmlor--testdox-text(see Logging).--testdox-summaryRepeats the TestDox output for tests that had errors, failures, or issues at the end of the test run. This provides a focused summary of problematic tests in TestDox format. Requires
--testdox.--debugReplaces the default progress and result output with detailed debugging information. This shows event-by-event details of the test execution process.
--with-telemetryIncludes telemetry information such as timing and memory usage in the debugging output. This option is used in conjunction with
--debug.
Logging
--log-junit <file>Writes the test results in JUnit XML format to the specified file. This format is widely supported by CI/CD tools for test result reporting.
--log-otr <file>Writes the test results in Open Test Reporting XML format to the specified file. This is a newer, standardized format for test result reporting.
--include-git-informationIncludes Git information (such as branch and commit hash) in the Open Test Reporting XML logfile. This helps associate test results with specific code versions.
--log-teamcity <file>Writes the test results in TeamCity format to the specified file. This is useful when you need TeamCity-formatted output in a log file while using a different console output format.
--testdox-html <file>Writes the test results in TestDox format as an HTML file. This produces a browsable, human-readable document of test behaviors. This option is intended for writing a report to a file; for TestDox-formatted console output use
--testdoxinstead.--testdox-text <file>Writes the test results in TestDox format as a plain text file. This produces a simple text document of test behaviors. This option is intended for writing a report to a file; for TestDox-formatted console output use
--testdoxinstead.--log-events-text <file>Streams all test runner events as plain text to the specified file. This provides a comprehensive log of every event that occurs during the test run.
--log-events-verbose-text <file>Streams all test runner events as plain text with extended information to the specified file. This includes additional details compared to
--log-events-text.--no-loggingIgnores all logging configured in the XML configuration file. No log files will be written regardless of XML configuration settings.
Code Coverage
--coverage-clover <file>Writes the code coverage report in Clover XML format to the specified file. This format is supported by many CI tools and code quality platforms.
--coverage-openclover <file>Writes the code coverage report in OpenClover XML format to the specified file. OpenClover is the open-source continuation of the Clover format.
--coverage-cobertura <file>Writes the code coverage report in Cobertura XML format to the specified file. This format is commonly used by CI tools such as GitLab CI and Jenkins.
--coverage-crap4j <file>Writes the code coverage report in Crap4J XML format to the specified file. Crap4J combines code coverage with cyclomatic complexity to identify risky code.
--coverage-html <dir>Writes the code coverage report in HTML format to the specified directory. This produces a browsable report with line-by-line coverage highlighting.
--without-class-viewRenders the code coverage report in HTML format without the class view. The class view shows code coverage information aggregated by classes, traits, and functions.
--without-file-viewRenders the code coverage report in HTML format without the file view. The file view shows code coverage information organized by directories and files, including line-by-line coverage highlighting.
The class view and the file view cannot both be disabled. When both
--without-class-viewand--without-file-vieware used, PHPUnit emits a warning and renders both views.--coverage-jsonl <dir>Writes the code coverage report in JSONL format to the specified directory. This format reports the code that is not covered, together with the mapping of tests to the code they execute, for consumption by tooling. See The Code Coverage Report in JSONL Format.
--coverage-php <file>Writes serialized code coverage data to the specified file. This data can later be merged with other coverage data or processed programmatically.
--coverage-text[=<file>]Writes the code coverage report in plain text format. If a file is specified, the report is written there; otherwise it is written to standard output.
--only-summary-for-coverage-textWhen generating a text coverage report, only shows the summary without per-class details. This produces a more concise coverage overview.
--show-uncovered-for-coverage-textWhen generating a text coverage report, includes files that have no coverage at all. By default, completely uncovered files are omitted from the text report.
--coverage-xml <dir>Writes the code coverage report in XML format to the specified directory. This generates one XML file per source file along with an index file. For each line of code that was executed, this report records the tests that executed it as well as how often each of them executed it (see The <xml> Element).
--exclude-source-from-xml-coverageExcludes the
<source>element from the XML coverage report. This reduces the size of the generated XML files by omitting source code.--warm-coverage-cachePerforms static analysis of tested code and test code ahead of time and stores the result in the
code-coveragecache directory. Without this option, the static analysis that is needed for code coverage reporting is performed on the fly during the test suite run and the result is then stored in the cache.--coverage-filter <dir>Adds the specified directory to the code coverage filter. Only files within filtered directories will be included in the coverage report.
--branch-coverageEnables branch coverage reporting in addition to line coverage. Branch coverage tracks which branches of the code have been executed. This requires a code coverage driver that supports branch coverage.
--path-coverageEnables path coverage reporting in addition to line coverage. Path coverage tracks which execution paths through the code have been tested, providing deeper insight than line coverage alone.
--disable-coverage-ignoreDisables the
@codeCoverageIgnoremetadata. When this option is used, code annotated with coverage-ignore metadata will be included in the coverage report.--disable-coverage-targetingDisables the attributes that target units of code, such as
CoversClass,UsesClass, andCoversNothing. When this option is used, code coverage is collected for every test and is not limited to the targeted units of code.--no-coverageIgnores all code coverage reporting configured in the XML configuration file. No coverage data will be collected or reported.
Miscellaneous
-h,--helpPrints the usage information showing all available command-line options and then exits.
--versionPrints the PHPUnit version string and then exits.
--atleast-version <min>Checks whether the installed PHPUnit version is at least the specified minimum version. Exits with code 0 if the condition is met, or 1 otherwise.
--check-versionChecks whether the installed PHPUnit version is the latest available release. This requires an internet connection to query the latest version information.
--check-php-configurationChecks whether the current PHP configuration follows best practices for running PHPUnit. Reports any
php.inisettings that may cause issues during test execution.
PHP Archive (PHAR) Only
The following options are only available when PHPUnit is used from a PHP Archive (PHAR).
--manifestPrints the Software Bill of Materials (SBOM) for the PHP archive in plain-text format and then exits.
--sbomPrints the Software Bill of Materials (SBOM) for the PHP archive in CycloneDX XML format and then exits.
--composer-lockPrints the
composer.lockfile that was used to build the PHP archive and then exits.