@@ -30,6 +30,8 @@ Installation
30
30
31
31
$ composer require --dev "symfony/phpunit-bridge:*"
32
32
33
+ Alternatively, you can clone the `<https://github.com/symfony/phpunit-bridge >`_ repository.
34
+
33
35
.. include :: /components/require_autoload.rst.inc
34
36
35
37
.. note ::
@@ -178,7 +180,7 @@ message, enclosed with ``/``. For example, with:
178
180
179
181
<php >
180
182
<server name =" KERNEL_CLASS" value =" App\Kernel" />
181
- <env name =" SYMFONY_DEPRECATIONS_HELPER" value =" /foobar/" />
183
+ <env name =" SYMFONY_DEPRECATIONS_HELPER" value =" regex= /foobar/" />
182
184
</php >
183
185
</phpunit >
184
186
@@ -188,39 +190,89 @@ message contains the ``"foobar"`` string.
188
190
Making Tests Fail
189
191
~~~~~~~~~~~~~~~~~
190
192
191
- By default, any non-legacy-tagged or any non-`@-silenced `_ deprecation notices
192
- will make tests fail. Alternatively, setting ``SYMFONY_DEPRECATIONS_HELPER `` to
193
- an arbitrary value (ex: ``320 ``) will make the tests fails only if a higher
194
- number of deprecation notices is reached (``0 `` is the default value). You can
195
- also set the value ``"weak" `` which will make the bridge ignore any deprecation
196
- notices. This is useful to projects that must use deprecated interfaces for
197
- backward compatibility reasons.
198
-
199
- When you maintain a library, having the test suite fail as soon as a dependency
200
- introduces a new deprecation is not desirable, because it shifts the burden of
201
- fixing that deprecation to any contributor that happens to submit a pull
202
- request shortly after a new vendor release is made with that deprecation. To
203
- mitigate this, you can either use tighter requirements, in the hope that
204
- dependencies will not introduce deprecations in a patch version, or even commit
205
- the Composer lock file, which would create another class of issues. Libraries
206
- will often use ``SYMFONY_DEPRECATIONS_HELPER=weak `` because of this. This has
207
- the drawback of allowing contributions that introduce deprecations but:
193
+ By default, any non-legacy-tagged or any non-`@-silenced `_ deprecation
194
+ notices will make tests fail. Alternatively, you can configure an
195
+ arbitrary threshold by setting ``SYMFONY_DEPRECATIONS_HELPER `` to
196
+ ``max[total]=320 `` for instance. It will make the tests fails only if a
197
+ higher number of deprecation notices is reached (``0 `` is the default
198
+ value).
199
+
200
+ You can even finer-grained control by using other keys of the ``max ``
201
+ array, which are ``internal ``, ``direct ``, and ``indirect ``. The
202
+ ``SYMFONY_DEPRECATIONS_HELPER `` environment variable accept a
203
+ url-encoded string, meaning you can combine thresholds and any other
204
+ configuration setting, like this:
205
+ ``SYMFONY_DEPRECATIONS_HELPER=max[total]=42&max[internal]=0&verbose=0 ``
206
+
207
+ Internal deprecations
208
+ .....................
209
+
210
+ When you maintain a library, having the test suite fail as soon as a
211
+ dependency introduces a new deprecation is not desirable, because it
212
+ shifts the burden of fixing that deprecation to any contributor that
213
+ happens to submit a pull request shortly after a new vendor release is
214
+ made with that deprecation. To mitigate this, you can either use tighter
215
+ requirements, in the hope that dependencies will not introduce
216
+ deprecations in a patch version, or even commit the Composer lock file,
217
+ which would create another class of issues. Libraries will often use
218
+ ``SYMFONY_DEPRECATIONS_HELPER=max[total]=999999 `` because of this. This
219
+ has the drawback of allowing contributions that introduce deprecations
220
+ but:
208
221
209
222
* forget to fix the deprecated calls if there are any;
210
223
* forget to mark appropriate tests with the ``@group legacy `` annotations.
211
224
212
- By using the ``"weak_vendors" `` value, deprecations that are triggered outside
213
- the ``vendors `` directory will make the test suite fail, while deprecations
214
- triggered from a library inside it will not, giving you the best of both
215
- worlds.
225
+ By using ``SYMFONY_DEPRECATIONS_HELPER=max[internal]=0 ``,
226
+ deprecations that are triggered outside the ``vendors `` directory will
227
+ be accounted for seperately, while deprecations triggered from a library
228
+ inside it will not (unless you reach 999999 of these), giving you
229
+ the best of both worlds.
230
+
231
+ Direct and indirect deprecations
232
+ ................................
233
+
234
+ When working on a project, you might be more interested in
235
+ ``max[direct] ``. Let's say you want to fix deprecations as soon as
236
+ they appear. A problem many people experience is that some dependencies
237
+ they have tend to lag behind their own dependencies, meaning they do not
238
+ fix deprecations as soon as possible, which means there is nothing you
239
+ can do to fix those (apart from a pull request on the outdated vendor).
240
+ This key allows you to put a threshold on direct deprecations only,
241
+ allowing you to notice when *your code * is using deprecated APIs, and to
242
+ keep up with the changes. You can of course still use ``max[indirect] ``
243
+ if you want to keep indirect deprecations under a given threshold.
244
+
245
+ Here is a summary that should help you pick the right configuration:
246
+
247
+ +------------------------+-----------------------------------------------------+
248
+ | Value | Recommended situation |
249
+ +========================+=====================================================+
250
+ | max[total]=0 | Recommended for actively maintained projects |
251
+ | | with little to no dependencies |
252
+ +------------------------+-----------------------------------------------------+
253
+ | max[direct]=0 | Recommended for projects with dependencies |
254
+ | | that fail to keep up with new deprecations. |
255
+ +------------------------+-----------------------------------------------------+
256
+ | max[internal]=0 | Recommended for libraries that use |
257
+ | | the deprecation system themselves and |
258
+ | | cannot afford to use one of the modes above. |
259
+ +------------------------+-----------------------------------------------------+
260
+
261
+ Disabling the verbose output
262
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263
+
264
+ By default, the brige will display a detailed output with the number of
265
+ deprecations and where they arise. If this is too much for you, you can
266
+ use ``SYMFONY_DEPRECATIONS_HELPER=verbose=0 `` to turn the verbose output
267
+ off.
216
268
217
269
Disabling the Deprecation Helper
218
270
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219
271
220
- Set the ``SYMFONY_DEPRECATIONS_HELPER `` environment variable to `` disabled `` to
221
- completely disable the deprecation helper. This is useful to make use of the
222
- rest of features provided by this component without getting errors or messages
223
- related to deprecations.
272
+ Set the ``SYMFONY_DEPRECATIONS_HELPER `` environment variable to
273
+ `` disabled=1 `` to completely disable the deprecation helper. This is
274
+ useful to make use of the rest of features provided by this component
275
+ without getting errors or messages related to deprecations.
224
276
225
277
.. _write-assertions-about-deprecations :
226
278
@@ -246,6 +298,9 @@ class autoloading time. This can be disabled with the ``debug-class-loader`` opt
246
298
</listener >
247
299
</listeners >
248
300
301
+ .. versionadded :: 4.2
302
+ The ``DebugClassLoader `` integration was introduced in Symfony 4.2.
303
+
249
304
Write Assertions about Deprecations
250
305
-----------------------------------
251
306
@@ -284,7 +339,7 @@ Running the following command will display the full stack trace:
284
339
285
340
.. code-block :: terminal
286
341
287
- $ 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
288
343
289
344
Time-sensitive Tests
290
345
--------------------
0 commit comments