With each release of Drupal 8 more and more things are being deprecated, which is awesome. It shows innovation, forward thinking, and a thought for backwards compatibility. However throwing notices or warnings when deprecated code is used can cause tests to fail. We already counter this a little by adding
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors"> to phpunit.xml.dist in core.
To quote the Symfony documentation:
By using the
weak_vendorsvalue, deprecations that are triggered outside the
vendorsdirectory will make the test suite fail, while deprecations triggered from a library inside it will not, giving you the best of both worlds.
This shows that deprecations within Drupal will still cause test fails, to combat that simply update the SYMFONY_DEPRECATIONS_HELPER setting to "weak" or "disabled", which would ignore the deprecations or disable the deprecation helper.
However if you're testing with run-test.sh this will interfere with the settings in your phpunit.xml file and use always use weak_vendors unless you have the suppress-deprecations argument set. Therefore use
run-tests.sh --suppress-deprecations and the SYMFONY_DEPRECATIONS_HELPER setting will be set to "disabled". See the
simpletest_script_run_one_test() function in run-tests.sh for more context.
Hopefully this helps, we found this really useful when testing Drupal modules with Travis, where we needed tests passing for Drupal 8.4 and 8.5.
Why don't we just remove the use of deprecated code? It should have been done before every minor Drupal core release..
My use case for this was a contrib module where I needed to support both 8.4.x and 8.5.x versions of core. Therefore couldn't remove the use of deprecated code.