![]() |
VOOZH | about |
<phpunit> ElementbackupGlobals AttributePossible values: true or false (default: false)
PHPUnit can optionally backup all global and super-global variables before each test and restore this backup after each test.
This attribute configures this operation for all tests. This configuration can be overridden using the BackupGlobals attribute on the test case class and test method level.
backupStaticProperties AttributePossible values: true or false (default: false)
PHPUnit can optionally backup all static properties in all declared classes before each test and restore this backup after each test.
This attribute configures this operation for all tests. This configuration can be overridden using the BackupStaticProperties attribute on the test case class and test method level.
bootstrap AttributeThis attribute configures the bootstrap script that is loaded before the tests are executed. This script usually only registers the autoloader callback that is used to load the code under test.
cacheDirectory AttributeThis attribute configures the directory in which PHPUnit stores data between test suite runs. The following data is stored in this directory:
test-results: Results of the previous test suite run (used for reordering tests based on previous defects or duration, for instance; see below)
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)
cacheResult AttributePossible values: true or false (default: true)
This attribute configures the storing of test results in the test-results cache file. This is required for ordering tests by defects or duration with the executionOrder attribute (see The executionOrder Attribute).
Use --do-not-cache-result on the command line or set this attribute to false to prevent the writing of the test-results cache file.
colors AttributePossible values: true or false (default: false)
This attribute configures whether colors are used in PHPUnit’s output.
Setting this attribute to true is equivalent to using the --colors=auto CLI option.
Setting this attribute to false is equivalent to using the --colors=never CLI option.
columns AttributePossible values: integer or string max (default: 80)
This attribute configures the number of columns to use for progress output.
If max is defined as value, the number of columns will be maximum of the current terminal.
controlGarbageCollector AttributePossible values: true or false (default: false)
When the PHP runtime automatically performs garbage collection then this may happen in the middle of the preparation (fixture setup) of a test or in the middle of the execution of a test. This can have a negative impact on test execution performance.
Configuring controlGarbageCollector="true" has the following effects:
Deactivate automatic garbage collection using gc_disable() before the first test is run
Trigger garbage collection using gc_collect_cycles() before the first test is run
Trigger garbage collection using gc_collect_cycles() after each n-th test
Trigger garbage collection after using gc_collect_cycles() after the last test was run
Activate automatic garbage collection using gc_enable() after the last test was run
The number of tests to execute before garbage collection is triggered is controlled by
numberOfTestsBeforeGarbageCollection (see below).
numberOfTestsBeforeGarbageCollection AttributePossible values: integer (default: 100)
Configures the number of tests to execute before garbage collection is triggered (see above).
requireCoverageMetadata AttributePossible values: true or false (default: false)
This attribute configures whether a test will be marked as risky (see Unintentionally Covered Code) when it does not indicate the code it intends to cover using an attribute.
processIsolation AttributePossible values: true or false (default: false)
This attribute configures whether each test should be run in a separate PHP process for increased isolation.
stopOnDefect AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first error, failure, warning, or risky test.
stopOnError AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first error.
stopOnFailure AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first failure.
stopOnWarning AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test warning.
stopOnRisky AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first risky test.
stopOnDeprecation AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after first test
that triggered a deprecation (E_DEPRECATED, E_USER_DEPRECATED, or PHPUnit deprecation).
stopOnNotice AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after first test
that triggered a notice (E_STRICT, E_NOTICE, or E_USER_NOTICE).
stopOnSkipped AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after first skipped test.
stopOnIncomplete AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after first incomplete test.
failOnAllIssues AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when an issue is triggered.
Backward Compatibility
Please note that if you configure failOnAllIssues to true
then you opt in to failing on additional issues in later versions of PHPUnit
that will be put under the control of this setting. This is not considered
to be a break of backward compatibility and rather the expected behaviour
of this setting.
failOnEmptyTestSuite AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when the configured test suite is empty.
failOnWarning AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that had warnings.
failOnRisky AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that were marked as risky.
failOnDeprecation AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that triggered a deprecation (E_DEPRECATED or E_USER_DEPRECATED).
failOnPhpunitDeprecation AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but PHPUnit deprecations were triggered.
failOnNotice AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that triggered a notice (E_STRICT, E_NOTICE, or E_USER_NOTICE).
failOnSkipped AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that were marked as skipped.
failOnIncomplete AttributePossible values: true or false (default: false)
This attribute configures whether the PHPUnit test runner should exit with a shell exit code that indicates failure when all tests are successful but there are tests that were marked as incomplete.
beStrictAboutChangesToGlobalState AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should mark a test as risky when global state is manipulated by the code under test (or the test code).
beStrictAboutOutputDuringTests AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should mark a test as risky when the code under test (or the test code) prints output.
beStrictAboutTestsThatDoNotTestAnything AttributePossible values: true or false (default: true)
This attribute configures whether PHPUnit should mark a test as risky when no assertions are performed (expectations are also considered).
beStrictAboutCoverageMetadata AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should mark a test as risky when it executes code that is not specified to be covered or used using an attribute.
enforceTimeLimit AttributePossible values: true or false (default: false)
This attribute configures whether time limits should be enforced.
defaultTimeLimit AttributePossible values: integer (default: 0)
This attribute configures the default time limit (in seconds).
timeoutForSmallTests AttributePossible values: integer (default: 1)
This attribute configures the time limit for tests attributed with Small (in seconds).
timeoutForMediumTests AttributePossible values: integer (default: 10)
This attribute configures the time limit for tests attributed with Medium (in seconds).
timeoutForLargeTests AttributePossible values: integer (default: 60)
This attribute configures the time limit for tests attributed with Large (in seconds).
defaultTestSuite AttributeThis attribute configures the name of the default test suite.
stderr AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should print its output to stderr instead of stdout.
reverseDefectList AttributePossible values: true or false (default: false)
This attribute configures whether tests that are not successful should be printed in reverse order.
registerMockObjectsFromTestArgumentsRecursively AttributePossible values: true or false (default: false)
This attribute configures whether arrays and object graphs that are passed from one test to another using the Depends* attributes should be recursively scanned for mock objects.
extensionsDirectory AttributeWhen phpunit.phar is used then this attribute may be used to configure a directory from which all *.phar files will be loaded as extensions for the PHPUnit test runner.
executionOrder AttributePossible values: default, defects, depends, no-depends, duration, random, reverse, size (default: default)
Using multiple values is possible. These need to be separated by ,.
This attribute configures the order in which tests are executed.
default: ordered in the order in which PHPUnit found the tests (does not use the result cache)
defects: ordered by defect (errored, failed, warning, incomplete, risky, skipped, unknown, passed), requires enabled result cache
depends: ordered by dependency (tests without dependencies first, dependent tests last)
depends,defects: ordered by dependency first, then ordered by defects
depends,duration: ordered by dependency first, then ordered by duration
depends,random: ordered by dependency first, then ordered randomly
depends,reverse: ordered by dependency first, then ordered in reverse
duration: ordered by duration (fastest test first, slowest test last), requires enabled result cache
no-depends: not ordered by dependency
no-depends,defects: not ordered by dependency, then ordered by defects
no-depends,duration: not ordered by dependency, then ordered by duration
no-depends,random: not ordered by dependency, then ordered randomly
no-depends,reverse: not ordered by dependency, then ordered in reverse
no-depends,size: not ordered by dependency, then ordered by size
random: ordered randomly
reverse: ordered as PHPUnit found the tests, then ordered in reverse
size: ordered by size (small, medium, large, unknown), also see (see Small, Medium, and Large)
resolveDependencies AttributePossible values: true or false (default: true)
This attribute configures whether dependencies between tests (expressed using the Depends* attributes) should be resolved.
testdox AttributePossible values: true or false (default: false)
This attribute configures whether the output should be printed in TestDox format.
displayDetailsOnAllIssues AttributePossible values: true or false (default: false)
This attribute configures whether details on all issues should be printed.
Backward Compatibility
Please note that if you configure displayDetailsOnAllIssues to true
then you opt in to printing additional issues in later versions of PHPUnit
that will be put under the control of this setting. This is not considered
to be a break of backward compatibility and rather the expected behaviour
of this setting.
displayDetailsOnIncompleteTests AttributePossible values: true or false (default: false)
This attribute configures whether details on incomplete tests should be printed.
displayDetailsOnSkippedTests AttributePossible values: true or false (default: false)
This attribute configures whether details on skipped tests should be printed.
displayDetailsOnTestsThatTriggerDeprecations AttributePossible values: true or false (default: false)
This attribute configures whether details on tests that triggered deprecations should be printed.
displayDetailsOnPhpunitDeprecations AttributePossible values: true or false (default: false)
This attribute configures whether details on PHPUnit deprecations should be printed.
displayDetailsOnTestsThatTriggerErrors AttributePossible values: true or false (default: false)
This attribute configures whether details on tests that triggered errors should be printed.
displayDetailsOnTestsThatTriggerNotices AttributePossible values: true or false (default: false)
This attribute configures whether details on tests that triggered notices should be printed.
displayDetailsOnTestsThatTriggerWarnings AttributePossible values: true or false (default: false)
This attribute configures whether details on tests that triggered warnings should be printed.
<testsuites> ElementParent element: <phpunit>
This element is the root for one or more <testsuite> elements that are used to configure the tests that are to be executed.
<testsuite> ElementParent element: <testsuites>
A <testsuite> element must have a name attribute and may have one or more <directory> and/or <file> child elements that configure directories and/or files, respectively, that should be searched for tests. Files and directories can be excluded by using <exclude> child elements.
<testsuites> <testsuitename="unit"> <directory>tests/unit</directory> </testsuite> <testsuitename="integration"> <directory>tests/integration</directory> </testsuite> <testsuitename="edge-to-edge"> <directory>tests/edge-to-edge</directory> <exclude>tests/edge-to-edge/pathToIgnore</exclude> </testsuite> <testsuitename="smoke"> <file>tests/smoke/FirstTest.php</file> <file>tests/smoke/SecondTest.php</file> </testsuite> </testsuites>
While the <directory> element adds all test classes found in a directory to the test suite, the <file> element adds the test class found in a single file. This is useful when only a few selected files from a directory should be part of a test suite.
phpVersion and phpVersionOperator AttributesPossible values: string
A required PHP version can be specified using the phpVersion and phpVersionOperator attributes:
<testsuites> <testsuitename="unit"> <directoryphpVersion="8.0.0"phpVersionOperator=">=">tests/unit</directory> </testsuite> </testsuites>
In the example above, the tests from the tests/unit directory are only added to the test suite if the PHP version is at least 8.0.0. The phpVersionOperator attribute is optional and defaults to >=.
<source> ElementParent element: <phpunit>
Configures the project’s source code files. This is used to restrict code coverage analysis and reporting of deprecations, notices, and warnings to your own code, for instance, while excluding code from third-party dependencies.
<include> ElementParent element: <source>
Configures a set of files to be included in the list of the project’s source code files.
<include> <directorysuffix=".php">src</directory> </include>
The example shown above instructs PHPUnit to include all source code files with .php suffix in the src directory and its sub-directories.
<exclude> ElementParent element: <source>
Configures a set of files to be excluded from the list of the project’s source code files.
<include> <directorysuffix=".php">src</directory> </include> <exclude> <directorysuffix=".php">src/generated</directory> <file>src/autoload.php</file> </exclude>
The example shown above instructs PHPUnit to include all source code files with .php suffix in the src directory and its sub-directories, but to exclude all files with .php suffix in the src/generated directory and its sub-directories as well as the src/autoload.php file.
<directory> ElementParent elements: <include>, <exclude>
Configures a directory and its sub-directories for inclusion in or exclusion from the list of the project’s source code files.
prefix AttributePossible values: string
Configures a prefix-based filter that is applied to the names of files in the directory and its sub-directories.
suffix AttributePossible values: string (default: '.php')
Configures a suffix-based filter that is applied to the names of files in the directory and its sub-directories.
<file> ElementParent elements: <include>, <exclude>
Configures a file for inclusion in or exclusion from the list of the project’s source code files.
<restrictDeprecations> AttributePossible values: true or false (default: false)
Restricts the reporting of E_DEPRECATED and E_USER_DEPRECATED
errors to the
list of the project’s source code files.
<restrictNotices> AttributePossible values: true or false (default: false)
Restricts the reporting of E_STRICT, E_NOTICE, and E_USER_NOTICE
errors to the
list of the project’s source code files.
<restrictWarnings> AttributePossible values: true or false (default: false)
Restricts the reporting of E_WARNING and E_USER_WARNING
errors to the
list of the project’s source code files.
<baseline> AttributePossible values: string
The baseline file to be used when running the test suite.
<ignoreSuppressionOfDeprecations> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_USER_DEPRECATED
errors.
<ignoreSuppressionOfPhpDeprecations> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_DEPRECATED
errors.
<ignoreSuppressionOfErrors> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_USER_ERROR
errors.
<ignoreSuppressionOfNotices> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_USER_NOTICE
errors.
<ignoreSuppressionOfPhpNotices> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_STRICT and E_NOTICE
errors.
<ignoreSuppressionOfWarnings> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_USER_WARNING
errors.
<ignoreSuppressionOfPhpWarnings> AttributePossible values: true or false (default: false)
Ignore the suppression (using the @ operator) of E_WARNING
errors.
<coverage> ElementParent element: <phpunit>
The <coverage> element and its children can be used to configure code coverage:
<coverageincludeUncoveredFiles="true" pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true"> <!-- ... --> </coverage>
includeUncoveredFiles AttributePossible values: true or false (default: true)
When set to true, all source code files that are configured to be considered for code coverage analysis will be included in the code coverage report(s). This includes source code files that are not executed while the tests are running.
ignoreDeprecatedCodeUnits AttributePossible values: true or false (default: false)
This attribute configures whether code units annotated with @deprecated should be ignored from code coverage.
pathCoverage AttributePossible values: true or false (default: false)
When set to false, only line coverage data will be collected, processed, and reported.
When set to true, line coverage, branch coverage, and path coverage data will be collected, processed, and reported. This requires a code coverage driver that supports path coverage. Path Coverage is currently only implemented by Xdebug.
disableCodeCoverageIgnore AttributePossible values: true or false (default: false)
This attribute configures whether metadata to ignore code should be ignored.
<report> ElementParent element: <coverage>
Configures the code coverage reports to be generated.
<report> <cloveroutputFile="clover.xml"/> <coberturaoutputFile="cobertura.xml"/> <crap4joutputFile="crap4j.xml"threshold="50"/> <htmloutputDirectory="html-coverage"lowUpperBound="50"highLowerBound="90"/> <phpoutputFile="coverage.php"/> <textoutputFile="coverage.txt"showUncoveredFiles="false"showOnlySummary="true"/> <xmloutputDirectory="xml-coverage"/> </report>
<clover> ElementParent element: <report>
Configures a code coverage report in Clover XML format.
outputFile AttributePossible values: string
The file to which the Clover XML report is written.
<cobertura> ElementParent element: <report>
Configures a code coverage report in Cobertura XML format.
outputFile AttributePossible values: string
The file to which the Cobertura XML report is written.
<crap4j> ElementParent element: <report>
Configures a code coverage report in Crap4J XML format.
outputFile AttributePossible values: string
The file to which the Crap4J XML report is written.
threshold AttributePossible values: integer (default: 50)
<html> ElementParent element: <report>
Configures a code coverage report in HTML format.
outputDirectory AttributeThe directory to which the HTML report is written.
lowUpperBound AttributePossible values: integer (default: 50)
The upper bound of what should be considered “low coverage”.
highLowerBound AttributePossible values: integer (default: 90)
The lower bound of what should be considered “high coverage”.
colorSuccessHigh AttributePossible values: string (default: #99cb84)
The color used to indicate that a line of code is covered by small (and larger) tests, for instance.
colorSuccessMedium AttributePossible values: string (default: #c3e3b5)
The color used to indicate that a line of code is covered by medium (and large) tests, for instance.
colorSuccessLow AttributePossible values: string (default: #dff0d8)
The color used to indicate that a line of code is covered by large tests, for instance.
colorWarning AttributePossible values: string (default: #fcf8e3)
The color used to indicate that a line of code cannot be covered, for instance.
colorDanger AttributePossible values: string (default: #f2dede)
The color used to indicate that a line of code can be covered but is not covered, for instance.
customCssFile AttributePossible values: string
The path to a custom CSS file.
<php> ElementParent element: <report>
Configures a code coverage report in PHP format.
outputFile AttributePossible values: string
The file to which the PHP report is written.
<text> ElementParent element: <report>
Configures a code coverage report in text format.
outputFile AttributePossible values: string
The file to which the text report is written.
showUncoveredFiles AttributePossible values: true or false (default: false)
showOnlySummary AttributePossible values: true or false (default: false)
<xml> ElementParent element: <report>
Configures a code coverage report in PHPUnit XML format.
outputDirectory AttributePossible values: string
The directory to which the PHPUnit XML report is written.
<logging> ElementParent element: <phpunit>
The <logging> element and its children can be used to configure the logging of the test execution.
<logging> <junitoutputFile="junit.xml"/> <teamcityoutputFile="teamcity.txt"/> <testdoxHtmloutputFile="testdox.html"/> <testdoxTextoutputFile="testdox.txt"/> </logging>
<junit> ElementParent element: <logging>
Configures a test result logfile in JUnit XML format.
outputFile AttributePossible values: string
The file to which the test result logfile in JUnit XML format is written.
<teamcity> ElementParent element: <logging>
Configures a test result logfile in TeamCity format.
outputFile AttributePossible values: string
The file to which the test result logfile in TeamCity format is written.
<testdoxHtml> ElementParent element: <logging>
Configures a test result logfile in TestDox HTML format.
outputFile AttributePossible values: string
The file to which the test result logfile in TestDox HTML format is written.
<testdoxText> ElementParent element: <logging>
Configures a test result logfile in TestDox text format.
outputFile AttributePossible values: string
The file to which the test result logfile in TestDox text format is written.
<groups> ElementParent element: <phpunit>
The <groups> element and its <include>, <exclude>, and <group> children can be used to select groups of tests marked with the Group attribute (documented in Group) that should (not) be run:
<groups> <include> <group>name</group> </include> <exclude> <group>name</group> </exclude> </groups>
The example shown above is equivalent to invoking the PHPUnit test runner with --group name --exclude-group name.
<extensions> ElementParent element: <phpunit>
The <extensions> element and its <bootstrap> children can be used to register test runner extensions.
<bootstrap> ElementParent element: <extensions>
<extensions> <bootstrapclass="Vendor\ExampleExtensionForPhpunit\Extension"/> </extensions>
<parameter> ElementParent element: <bootstrap>
The <parameter> element can be used to configure parameters that are passed
to the extension for bootstrapping.
<extensions> <bootstrapclass="Vendor\ExampleExtensionForPhpunit\Extension"> <parametername="message"value="the-message"/> </bootstrap> </extensions>
<php> ElementParent element: <phpunit>
The <php> element and its children can be used to configure PHP settings, constants, and global variables. It can also be used to prepend the include_path.
<includePath> ElementParent element: <php>
This element can be used to prepend a path to the include_path.
<ini> ElementParent element: <php>
This element can be used to set a PHP configuration setting using ini_set().
<php> <ininame="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
ini_set('foo', 'bar');
Note
Because the <ini> element uses ini_set() internally, it can only be used for PHP configuration
settings that can be changed at runtime. PHP configuration settings that can only be set in a
configuration file (php.ini, for instance) or on the command line (using PHP’s -d option) cannot
be set using the <ini> element.
<const> ElementParent element: <php>
This element can be used to set a global constant.
<php> <constname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
define('foo', 'bar');
<var> ElementParent element: <php>
This element can be used to set a global variable.
<php> <varname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$GLOBALS['foo'] = 'bar';
<env> ElementParent element: <php>
This element can be used to set a value in the super-global array $_ENV.
<php> <envname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_ENV['foo'] = 'bar';
By default, environment variables are not overwritten if they exist already.
To force overwriting existing variables, use the force attribute:
<php> <envname="foo"value="bar"force="true"/> </php>
<get> ElementParent element: <php>
This element can be used to set a value in the super-global array $_GET.
<php> <getname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_GET['foo'] = 'bar';
<post> ElementParent element: <php>
This element can be used to set a value in the super-global array $_POST.
<php> <postname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_POST['foo'] = 'bar';
<cookie> ElementParent element: <php>
This element can be used to set a value in the super-global array $_COOKIE.
<php> <cookiename="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_COOKIE['foo'] = 'bar';
<server> ElementParent element: <php>
This element can be used to set a value in the super-global array $_SERVER.
<php> <servername="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_SERVER['foo'] = 'bar';
<files> ElementParent element: <php>
This element can be used to set a value in the super-global array $_FILES.
<php> <filesname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_FILES['foo'] = 'bar';
<request> ElementParent element: <php>
This element can be used to set a value in the super-global array $_REQUEST.
<php> <requestname="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
$_REQUEST['foo'] = 'bar';