What does PHPUnit Strict mode do?

Mike Graf picture Mike Graf · May 9, 2012 · Viewed 8k times · Source

I am wondering about what "strict mode is in PHPUnit" ?

eg:

phpunit --strict

or in phpunit.xml

<phpunit strict="true"/>

I turned it on just to try it and my tests started failing with

PHP_Invoker_TimeoutException: Execution aborted after 1 second

Answer

Crozin picture Crozin · May 9, 2012

Please note that PHPUnit swallows all output that is emitted during the execution of a test. In strict mode, a test that emits output will fail.

That's all I could find in documentation, but I'd also checked the sources and I found that in strict mode:

  1. Tests with no assertions might be marked as incomplete/failures.
  2. Each test might be run with execution time limit depending on it's size and the presence of the pcntl extension and PHP_Invoker library. There are three timeouts values:

    • timeoutForSmallTests (default value: 1)
    • timeoutForMediumTests (default value: 10)
    • timeoutForLargeTests (default value: 60)

    The test size (small, medium or large) is determined by the PHPUnit_Util_Test::getSize() method:

    • Test cases descending from PHPUnit_Extensions_Database_TestCase or PHPUnit_Extensions_SeleniumTestCase are large.
    • Test cases and individual tests can also be made large or medium by adding them to the 'large' or 'medum' groups, respectively.
    • Otherwise, the test is small.

It's seems that strict mode does only the above three changes, but I'm not absolutely sure about that. I have never studied PHPUnit's sources before, nor used strict mode.