If you’ve ever worked on a long-term PHP project, you’re probably familiar with deprecation warnings flooding your tests. It is very common to see them suddenly aster upgrading from one minor version of Symfony to another pre-LTS one. At first, they’re easy to ignore, but as they grow, they become a real nuisance — cluttering your console output, slowing down your test analysis, and in some cases, even hiding more critical errors in the noise. Deprecation warnings are meant to help developers prepare for future Symfony (or any other framework) of PHP versions. But when it is in one of the Symfony’s core components there are nothing that you can do immediately to tackle them. As a result they can seriously disrupt your workflow.
Deprecation warnings can do more than clutter your local test runs—they can also disrupt your CI/CD pipeline, causing builds to fail if the pipeline is configured to treat warnings as errors.
Suppress Deprecation Warnings with PHPUnit Configuration
So, if running “composer update -W” is not an option or it simple does not help (as deprecations will be removed only in next LTS), PHPUnit allows you to configure your test suite to ignore these warnings, making the output easier to digest. To do this you need to define/change value of SYMFONY_DEPRECATIONS_HELPER environment variable. Values you may need are: “disabled” and “weak”.
For running the tests manually, just run:
SYMFONY_DEPRECATIONS_HELPER=disabled bin/phpunit
Or you can add it into the phpunit.xml/phpunit.xml.dist configuration file:
<phpunit xmlns:xsi ...>
...
<php>
...
<strong><env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" /></strong>
...
</php>
...
</phpunit>
Or add it into your .ent.test file in the Symfony project root:
...
SYMFONY_DEPRECATIONS_HELPER=disabled
...
When you run tests in Bitbucket CI/CD process add in your bitbucket-pipeline.yaml file:
image: php:8.0-cli
pipelines:
branches:
master:
- step:
name: Run Tests
...
script:
- apt-get update
...
- SYMFONY_DEPRECATIONS_HELPER=disabled
- ./vendor/bin/phpunit ./tests --testdox --colors=always
...
Happy testing, and may your console stay clean!