Skip to content
Latchkey

PHPUnit Deprecation Handler Fails CI - failOnDeprecation & Triggers

PHPUnit can be configured to fail when tests trigger deprecations (failOnDeprecation, failOnPhpunitDeprecation, or --fail-on-deprecation). After a PHP or PHPUnit upgrade, previously-silent deprecations turn a green suite red even though no assertion failed.

What this error means

Every assertion passes, but PHPUnit exits non-zero reporting that tests triggered deprecations, with failOnDeprecation enabled. It commonly appears right after bumping PHP or PHPUnit.

PHPUnit output
OK, but there were issues!
Tests: 120, Assertions: 340, Deprecations: 4.

1) App\Tests\OrderTest::testTotal
Method ...::assertEquals() with 3+ arguments is deprecated (PHPUnit deprecation).
# exit code non-zero because failOnDeprecation="true"

Common causes

failOnDeprecation promotes notices to failures

With failOnDeprecation="true" (or --fail-on-deprecation), any triggered deprecation makes the run fail, regardless of assertions.

New deprecations after an upgrade

A newer PHP or PHPUnit deprecates APIs your tests use (or your code under test triggers), surfacing deprecations that were previously absent.

How to fix it

Fix the deprecation at its source

Update the deprecated API usage in tests or code so no deprecation is triggered.

PHP
// PHPUnit: use the dedicated assertion instead of extra args
$this->assertEqualsWithDelta($expected, $actual, 0.01);

See which deprecations fired

Show details so you can target each one.

Terminal
vendor/bin/phpunit --display-deprecations --display-phpunit-deprecations

Scope the handler deliberately

If you must defer, decide consciously whether to fail on deprecations.

phpunit.xml
<!-- phpunit.xml -->
<phpunit failOnDeprecation="false"
         failOnPhpunitDeprecation="false"
         displayDetailsOnTestsThatTriggerDeprecations="true">

How to prevent it

  • Run a CI matrix including the next PHP/PHPUnit to surface deprecations early.
  • Fix deprecations as a tracked backlog rather than permanently silencing them.
  • Keep displayDetails… on so deprecations stay visible even if not failing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →