![]() |
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 annotation on the test case class and test method level.
backupStaticAttributes AttributePossible values: true or false (default: false)
PHPUnit can optionally backup all static attributes 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 @backupStaticAttributes annotation 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.
cacheResult AttributePossible values: true or false (default: true)
This attribute configures the caching of test results. This caching is required for certain other features to work.
cacheResultFile AttributeThis attribute configures the file in which the test result cache (see above) is stored.
cacheTokens AttributePossible values: true or false (default: false)
This attribute configures the in-memory cache of the token streams that are used for code coverage analysis.
When more than one code coverage report is generated in a single run, enabling this cache will increase memory usage and may reduce the time to generate the reports.
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.
convertDeprecationsToExceptions AttributePossible values: true or false (default: false)
This attribute configures whether E_DEPRECATED and E_USER_DEPRECATED events triggered by the code under test are converted to an exception (and mark the test as error).
convertErrorsToExceptions AttributePossible values: true or false (default: true)
This attribute configures whether E_ERROR and E_USER_ERROR events triggered by the code under test are converted to an exception (and mark the test as error).
convertNoticesToExceptions AttributePossible values: true or false (default: true)
This attribute configures whether E_STRICT, E_NOTICE, and E_USER_NOTICE events triggered by the code under test are converted to an exception (and mark the test as error).
convertWarningsToExceptions AttributePossible values: true or false (default: true)
This attribute configures whether E_WARNING and E_USER_WARNING events triggered by the code under test are converted to an exception (and mark the test as error).
disableCodeCoverageIgnore AttributePossible values: true or false (default: false)
This attribute configures whether the @codeCoverageIgnore* annotations should be ignored.
forceCoversAnnotation 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 have a @covers annotation.
printerClass AttributeDefault: PHPUnit\TextUI\ResultPrinter
This attribute configures the name of a class that either is PHPUnit\TextUI\ResultPrinter or that extends PHPUnit\TextUI\ResultPrinter. An object of this class is used to print progress and test results.
printerFile AttributeThis attribute can be used to configure the path to the sourcecode file that declares the class configured with printerClass in case that class cannot be autoloaded.
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.
stopOnError AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “error”.
stopOnFailure AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “failure”.
stopOnIncomplete AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “incomplete”.
stopOnRisky AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “risky”.
stopOnSkipped AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “skipped”.
stopOnWarning AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with status “warning”.
stopOnDefect AttributePossible values: true or false (default: false)
This attribute configures whether the test suite execution should be stopped after the first test finished with a status “error”, “failure”, “risky” or “warning”.
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.
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.
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.
beStrictAboutResourceUsageDuringSmallTests AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should mark a test that is annotated with @small as risky when it invokes a PHP built-in function or method that operates on resource variables.
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).
beStrictAboutTodoAnnotatedTests AttributePossible values: true or false (default: false)
This attribute configures whether PHPUnit should mark a test as risky when it is annotated with @todo.
beStrictAboutCoversAnnotation 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 using @covers or @uses.
ignoreDeprecatedCodeUnitsFromCodeCoverage AttributePossible values: true or false (default: false)
This attribute configures whether code units annotated with @deprecated should be ignored from code coverage.
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 annotated with @small (in seconds).
timeoutForMediumTests AttributePossible values: integer (default: 10)
This attribute configures the time limit for tests annotated with @medium (in seconds).
timeoutForLargeTests AttributePossible values: integer (default: 60)
This attribute configures the time limit for tests annotated with @large (in seconds).
testSuiteLoaderClass AttributeDefault: PHPUnit\Runner\StandardTestSuiteLoader
This attribute configures the name of a class that implements the PHPUnit\Runner\TestSuiteLoader interface. An object of this class is used to load the test suite.
testSuiteLoaderFile AttributeThis attribute can be used to configure the path to the sourcecode file that declares the class configured with testSuiteLoaderClass in case that class cannot be autoloaded.
defaultTestSuite AttributeThis attribute configures the name of the default test suite.
verbose AttributePossible values: true or false (default: false)
This attribute configures whether more verbose output should be printed.
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 annotation 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
Using multiple values is possible. These need to be separated by ,.
This attribute configures the order in which tests are executed.
resolveDependencies AttributePossible values: true or false (default: true)
This attribute configures whether dependencies between tests (expressed using the @depends annotation) should be resolved.
testdox AttributePossible values: true or false (default: false)
This attribute configures whether the output should be printed in TestDox format.
noInteraction AttributePossible values: true or false (default: false)
This attribute configures whether progress should be animated when TestDox format is used, for instance.
<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.
<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> </testsuite> </testsuites>
Using the phpVersion and phpVersionOperator attributes, a required PHP version can be specified:
<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 >=.
<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 annotation (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.
<testdoxGroups> ElementParent element: <phpunit>
… TBD …
<filter> ElementParent element: <phpunit>
The <filter/whitelist> element and its children can be used to configure the whitelist for the code coverage reporting:
<filter> <whitelistprocessUncoveredFilesFromWhitelist="true"> <directorysuffix=".php">src</directory> <exclude> <file>src/autoload.php</file> </exclude> </whitelist> </filter>
<listeners> ElementParent element: <phpunit>
The <listeners> element and its <listener> children can be used to attach additional test listeners to the test execution.
<listener> ElementParent element: <listeners>
<listeners> <listenerclass="MyListener"file="/optional/path/to/MyListener.php"> <arguments> <array> <elementkey="0"> <string>Sebastian</string> </element> </array> <integer>22</integer> <string>April</string> <double>19.78</double> <null/> <objectclass="stdClass"/> </arguments> </listener> </listeners>
The XML configuration above corresponds to attaching the
$listener object (see below) to the test execution:
$listener = new MyListener( ['Sebastian'], 22, 'April', 19.78, null, new stdClass );
Note
Please note that the PHPUnit\Framework\TestListener interface is
deprecated and will be removed in the future. TestRunner extensions
should be used instead of test listeners.
<extensions> ElementParent element: <phpunit>
The <extensions> element and its <extension> children can be used to register test runner extensions.
<extension> ElementParent element: <extensions>
<extensions> <extensionclass="Vendor\MyExtension"/> </extensions>
<arguments> ElementParent element: <extension>
The <arguments> element can be used to configure a single <extension>.
Accepts a list of elements of types, which are then used to configure individual
extensions. The arguments are passed to the extension class’ __constructor
method in the order they are defined in the configuration.
Available types:
<boolean>
<integer>
<string>
<double> (float)
<array>
<object>
<extensionclass="Vendor\MyExtension"> <arguments> <integer>1</integer> <integer>2</integer> <integer>3</integer> <string>helloworld</string> <boolean>true</boolean> <double>1.23</double> <array> <elementindex="0"> <string>value1</string> </element> <elementindex="1"> <string>value2</string> </element> </array> <objectclass="Vendor\MyPhpClass"> <string>constructorarg1</string> <string>constructorarg2</string> </object> </arguments> </extension>
<logging> ElementParent element: <phpunit>
The <logging> element and its <log> children can be used to configure the logging of the test execution.
<log> ElementParent element: <logging>
<logging> <logtype="coverage-html"target="/tmp/report"lowUpperBound="35"highLowerBound="70"/> <logtype="coverage-clover"target="/tmp/coverage.xml"/> <logtype="coverage-php"target="/tmp/coverage.serialized"/> <logtype="coverage-text"target="php://stdout"showUncoveredFiles="false"/> <logtype="junit"target="/tmp/logfile.xml"/> <logtype="testdox-html"target="/tmp/testdox.html"/> <logtype="testdox-text"target="/tmp/testdox.txt"/> </logging>
The XML configuration above corresponds to invoking the TextUI test runner with the following options:
--coverage-html /tmp/report
--coverage-clover /tmp/coverage.xml
--coverage-php /tmp/coverage.serialized
--coverage-text
> /tmp/logfile.txt
--log-junit /tmp/logfile.xml
--testdox-html /tmp/testdox.html
--testdox-text /tmp/testdox.txt
The lowUpperBound, highLowerBound, and showUncoveredFiles attributes have no equivalent TextUI test runner option.
lowUpperBound: Maximum coverage percentage to be considered “lowly” covered.
highLowerBound: Minimum coverage percentage to be considered “highly” covered.
showUncoveredFiles: Show all whitelisted files in --coverage-text output not just the ones with coverage information.
showOnlySummary: Show only the summary in --coverage-text output.
<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.
<php> <ininame="foo"value="bar"/> </php>
The XML configuration above corresponds to the following PHP code:
ini_set('foo', 'bar');
<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';