April 18, 2016 Javier Eguiluz

The PHPUnitBridge component is mostly used for its "deprecation helper" which detects the deprecated features used by your application. This is possible thanks to the @trigger_error() function call used by Symfony and many other PHP applications. Detecting deprecations is very important because you can't upgrade to Symfony 3 if your application uses any deprecated feature.

In Symfony 3.1, the deprecation helper has been improved to help you find and fix deprecations more easily. The deprecation helper now supports different working modes. All of them are enabled depending on the value of the SYMFONY_DEPRECATIONS_HELPER environment variable. The easiest way to configure this variable is in your phpunit.xml configuration file:

1 2 3 4 5 6 7 8 9 10 <phpunit xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "http://schema.phpunit.de/4.1/phpunit.xsd" > <!-- ... --> <php> <server name= "KERNEL_DIR" value= "app/" /> <env name= "SYMFONY_DEPRECATIONS_HELPER" value= "..." /> </php> </phpunit>

Ignoring triggered deprecations¶ This mode is useful when you want to use some PHPUnitBridge features, such as clock mocking or network mocking, but don't care about the possible deprecations of your application. Set the variable to disabled and PHPUnit won't list the deprecations and it won't make your test suite fail: 1 <env name= "SYMFONY_DEPRECATIONS_HELPER" value= "disabled" />

Showing the full stack trace of a specific deprecation¶ Some deprecations may be difficult to solve. That's why you can tell PHPUnitBridge to stop the test suite when some specific deprecation is triggered and to display its full stack trace. In previous Symfony versions, this feature was already available, but the value of the SYMFONY_DEPRECATIONS_HELPER defined the class and method of the test you want to inspect. In Symfony 3.1, the value of the variable is matched as a regular expression against the deprecation message: 1 2 3 4 5 <!-- stopping at a specific deprecation --> <env name= "SYMFONY_DEPRECATIONS_HELPER" value= "/Passing callable strings .*/" /> <!-- stopping at several deprecations --> <env name= "SYMFONY_DEPRECATIONS_HELPER" value= "/Passing callable strings .*|Passing a boolean flag .*/" />