Deprecation fails when testing Drupal 8
Deprecation fails when testing Drupal 8
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"></env>
to phpunit.xml.dist in core.
To quote the Symfony documentation:
By using the
weak_vendors
value, deprecations that are triggered outside thevendors
directory 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.
timmillwood
Mon, 26/02/2018 - 08:57
Tags
drupal planet
drupal-planet
drupal
drupal8
drupal 8
testing
drupal testing
Add new comment