6. Risky Tests

    PHPUnit is by default strict about tests that do not test anything. This check can be disabled by using the option on the or by setting beStrictAboutTestsThatDoNotTestAnything="false" in PHPUnit’s configuration file.

    A test that does not perform an assertion will be marked as risky when this check is enabled. Expectations on mock objects count as an assertion.

    PHPUnit can be strict about unintentionally covered code. This check can be enabled by using the --strict-coverage option on the command line or by setting beStrictAboutCoversAnnotation="true" in PHPUnit’s .

    A test that is annotated with @covers and executes code that is not listed using a or @uses annotation will be marked as risky when this check is enabled.

    PHPUnit can be strict about output during tests. This check can be enabled by using the --disallow-test-output option on the command line or by setting beStrictAboutOutputDuringTests="true" in PHPUnit’s .

    A test that emits output, for instance by invoking print in either the test code or the tested code, will be marked as risky when this check is enabled.

    A time limit can be enforced for the execution of a test if the package is installed and the extension is available. The enforcing of this time limit can be enabled by using the --enforce-time-limit option on the command line or by setting enforceTimeLimit="true" in PHPUnit’s .

    A test annotated with @large will be marked as risky if it takes longer than 60 seconds to execute. This timeout is configurable via the timeoutForLargeTests attribute in the configuration file.

    A test annotated with will be marked as risky if it takes longer than 1 second to execute. This timeout is configurable via the timeoutForSmallTests attribute in the .

    Note

    Tests need to be explicitly annotated by either @small, @medium, or @large to enable run time limits.

    To exit the test run with a non-zero exit code when tests overrun their time-limit, the --fail-on-risky option on the command line or the failOnRisky="true" setting in PHPUnit’s needs to be enabled.