@@ -29,7 +29,7 @@ Installation
2929
3030.. code-block :: terminal
3131
32- $ composer require --dev " symfony/phpunit-bridge:*"
32+ $ composer require --dev symfony/phpunit-bridge
3333
3434 .. include :: /components/require_autoload.rst.inc
3535
@@ -179,7 +179,7 @@ message, enclosed with ``/``. For example, with:
179179
180180 <php >
181181 <server name =" KERNEL_CLASS" value =" App\Kernel" />
182- <env name =" SYMFONY_DEPRECATIONS_HELPER" value =" /foobar/" />
182+ <env name =" SYMFONY_DEPRECATIONS_HELPER" value =" regex= /foobar/" />
183183 </php >
184184 </phpunit >
185185
@@ -189,37 +189,85 @@ message contains the ``"foobar"`` string.
189189Making Tests Fail
190190~~~~~~~~~~~~~~~~~
191191
192- By default, any non-legacy-tagged or any non-`@-silenced `_ deprecation notices
193- will make tests fail. Alternatively, setting ``SYMFONY_DEPRECATIONS_HELPER `` to
194- an arbitrary value (ex: ``320 ``) will make the tests fails only if a higher
195- number of deprecation notices is reached (``0 `` is the default value). You can
196- also set the value ``"weak" `` which will make the bridge ignore any deprecation
197- notices. This is useful to projects that must use deprecated interfaces for
198- backward compatibility reasons.
192+ By default, any non-legacy-tagged or any non-`@-silenced `_ deprecation
193+ notices will make tests fail. Alternatively, you can configure an
194+ arbitrary threshold by setting ``SYMFONY_DEPRECATIONS_HELPER `` to
195+ ``max[total]=320 `` for instance. It will make the tests fails only if a
196+ higher number of deprecation notices is reached (``0 `` is the default
197+ value).
198+
199+ You can have even finer-grained control by using other keys of the ``max ``
200+ array, which are ``self ``, ``direct ``, and ``indirect ``. The
201+ ``SYMFONY_DEPRECATIONS_HELPER `` environment variable accepts an URL-encoded
202+ string, meaning you can combine thresholds and any other configuration setting,
203+ like this: ``SYMFONY_DEPRECATIONS_HELPER=max[total]=42&max[self]=0&verbose=0 ``
204+
205+ Internal deprecations
206+ .....................
199207
200208When you maintain a library, having the test suite fail as soon as a dependency
201209introduces a new deprecation is not desirable, because it shifts the burden of
202- fixing that deprecation to any contributor that happens to submit a pull
203- request shortly after a new vendor release is made with that deprecation. To
204- mitigate this, you can either use tighter requirements, in the hope that
210+ fixing that deprecation to any contributor that happens to submit a pull request
211+ shortly after a new vendor release is made with that deprecation.
212+
213+ To mitigate this, you can either use tighter requirements, in the hope that
205214dependencies will not introduce deprecations in a patch version, or even commit
206- the Composer lock file, which would create another class of issues. Libraries
207- will often use ``SYMFONY_DEPRECATIONS_HELPER=weak `` because of this. This has
208- the drawback of allowing contributions that introduce deprecations but:
215+ the ``composer.lock `` file, which would create another class of issues.
216+ Libraries will often use ``SYMFONY_DEPRECATIONS_HELPER=max[total]=999999 ``
217+ because of this. This has the drawback of allowing contributions that introduce
218+ deprecations but:
209219
210220* forget to fix the deprecated calls if there are any;
211221* forget to mark appropriate tests with the ``@group legacy `` annotations.
212222
213- By using the ``"weak_vendors" `` value, deprecations that are triggered outside
214- the ``vendors `` directory will make the test suite fail, while deprecations
215- triggered from a library inside it will not, giving you the best of both
216- worlds.
223+ By using ``SYMFONY_DEPRECATIONS_HELPER=max[self]=0 ``, deprecations that are
224+ triggered outside the ``vendors `` directory will be accounted for seperately,
225+ while deprecations triggered from a library inside it will not (unless you reach
226+ 999999 of these), giving you the best of both worlds.
227+
228+ Direct and Indirect Deprecations
229+ ................................
230+
231+ When working on a project, you might be more interested in ``max[direct] ``.
232+ Let's say you want to fix deprecations as soon as they appear. A problem many
233+ developers experience is that some dependencies they have tend to lag behind
234+ their own dependencies, meaning they do not fix deprecations as soon as
235+ possible, which means you should create a pull request on the outdated vendor,
236+ and ignore these deprecations until your pull request is merged.
237+
238+ The ``max[direct] `` config allows you to put a threshold on direct deprecations
239+ only, allowing you to notice when *your code * is using deprecated APIs, and to
240+ keep up with the changes. You can still use ``max[indirect] `` if you want to
241+ keep indirect deprecations under a given threshold.
242+
243+ Here is a summary that should help you pick the right configuration:
244+
245+ +------------------------+-----------------------------------------------------+
246+ | Value | Recommended situation |
247+ +========================+=====================================================+
248+ | max[total]=0 | Recommended for actively maintained projects |
249+ | | with robust/no dependencies |
250+ +------------------------+-----------------------------------------------------+
251+ | max[direct]=0 | Recommended for projects with dependencies |
252+ | | that fail to keep up with new deprecations. |
253+ +------------------------+-----------------------------------------------------+
254+ | max[self]=0 | Recommended for libraries that use |
255+ | | the deprecation system themselves and |
256+ | | cannot afford to use one of the modes above. |
257+ +------------------------+-----------------------------------------------------+
258+
259+ Disabling the Verbose Output
260+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261+
262+ By default, the bridge will display a detailed output with the number of
263+ deprecations and where they arise. If this is too much for you, you can use
264+ ``SYMFONY_DEPRECATIONS_HELPER=verbose=0 `` to turn the verbose output off.
217265
218266Disabling the Deprecation Helper
219267~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220268
221- Set the ``SYMFONY_DEPRECATIONS_HELPER `` environment variable to ``disabled `` to
222- completely disable the deprecation helper. This is useful to make use of the
269+ Set the ``SYMFONY_DEPRECATIONS_HELPER `` environment variable to ``disabled=1 ``
270+ to completely disable the deprecation helper. This is useful to make use of the
223271rest of features provided by this component without getting errors or messages
224272related to deprecations.
225273
@@ -247,6 +295,10 @@ class autoloading time. This can be disabled with the ``debug-class-loader`` opt
247295 </listener >
248296 </listeners >
249297
298+ .. versionadded :: 4.2
299+
300+ The ``DebugClassLoader `` integration was introduced in Symfony 4.2.
301+
250302Write Assertions about Deprecations
251303-----------------------------------
252304
@@ -287,7 +339,7 @@ Running the following command will display the full stack trace:
287339
288340.. code-block :: terminal
289341
290- $ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
342+ $ SYMFONY_DEPRECATIONS_HELPER='regex= /Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
291343
292344 Time-sensitive Tests
293345--------------------
0 commit comments