Change record status: 
Project: 
Introduced in branch: 
8.5.x
Introduced in version: 
8.5.0
Description: 

As of #2488860: Bring phpunit bridge into drupal and use it for unit tests and simpletest to handle Deprecation we have a new way to test for deprecated code. If code follows Drupal core deprecation policy and uses @trigger_error('deprecation message', E_USER_DEPRECATED) to mark code deprecated this will be caught by tests. If this is not expected then this will result in a test error. This is the default behaviour.

Update your phpunit.xml

Note that the following class was removed and changed by Change Record: PHPUnit 6 is used for testing on PHP 7.0+.

If you have a custom phpunit.xml then you will need to add DeprecationListener and SymfonyTestsListener to the listeners in the file.

    <listener class="\Drupal\Tests\Listeners\DeprecationListener">
    </listener>
    <!-- The Symfony deprecation listener has to come after the Drupal
    deprecation listener -->
    <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">

Update your CI

If you use run-tests.sh to run all your tests, you can now specify --suppress-deprecations on the command line, and this will ignore deprecation errors during test runs.

Using phpunit to run tests, you can specify SYMFONY_DEPRECATIONS_HELPER=disabled as an environmental variable. You can also specify SYMFONY_DEPRECATIONS_HELPER=strict to explicitly cause deprecations to fail. The best place to specify this is in a custom phpunit.xml.

Testing deprecated code

When you want to not fail some specific tests put @group legacy onto the method, see https://symfony.com/doc/current/components/phpunit_bridge.html#mark-test... for more possibilities.

In case you want to explicitly test that a certain function call see https://symfony.com/doc/current/components/phpunit_bridge.html#write-ass...

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done