Introduce PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION

Created on 14 June 2025, 9 days ago

Problem/Motivation

PHPUnit 11 separated reporting/failing on PHP deprecations vs on PHPUnit internal ones.

PHP deprecations use the @trigger_error('...', E_USER_DEPRECATED); mechanism; PHPUnit internal use PHPUnit's event system. The two streams are reported separately in PHPUnit CLI with two specific arguments, --fail-on-deprecation and --fail-on-phpunit-deprecation.

run-tests.sh by default sets both options; in core, the PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION environment variable can be used to disable PHPUnit deprecations while keeping the PHP ones failing the tests.

See https://git.drupalcode.org/project/drupal/-/blob/11.x/.gitlab-ci.yml?ref...

Proposed resolution

Introduce the same variable in the template.
Default value to be discussed.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Component

gitlab-ci

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mondrake
  • 🇬🇧United Kingdom jonathan1055

    This is a good idea. I saw this issue a few days ago, and thought 'yes nice'. But now that I am hitting the PHPUnit deprecations in my work to add attributes, it has become 'yes must' !

  • 🇬🇧United Kingdom jonathan1055

    Are you saying that we just need to set the environment variable PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION to 1 or 0 and the phpunit binary will use that value? I've just looked in run-tests.sh and there is no reference to that variable or the --fail-on-phpunit-deprecation option.

    I will try it and see what happens.

  • Pipeline finished with Success
    5 days ago
    Total: 139s
    #525552
  • 🇮🇹Italy mondrake 🇮🇹

    No it's a Drupal thing, not PHPUnit.

    Drupal's PHPUnit bootstrap script activates DeprecationHandler, that introspects PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION in its ::getConfiguration() method. That method is invoked by PhpUnitTestRunner::runCommand that does this

        // If the deprecation handler bridge is active, we need to fail when there
        // are deprecations that get reported (i.e. not ignored or expected).
        $deprecationConfiguration = DeprecationHandler::getConfiguration();
        if ($deprecationConfiguration !== FALSE) {
          $command[] = '--fail-on-deprecation';
          if ($deprecationConfiguration['failOnPhpunitDeprecation']) {
            $command[] = '--fail-on-phpunit-deprecation';
          }
        }
    
    

    that is, it adds (or not) --fail-on-phpunit-deprecation to the PHPUnit CLI sub-process spawned by run-tests.sh.

  • 🇬🇧United Kingdom jonathan1055

    Thanks for that. In #3527579-9: Add #[Group] attributes for Core 11.2 and PHPUnit 11 I used your suggestion of setting the plain variable PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION: 0 and this does prevent the internal phpunit deprecation log messages. I am also working on making some changes in our downstream test branches to demonstrate the issue.

    To implement this, we could just add the new variable to the hidden-variables file and document how to use it. But I think it may be better to add our own differently-named variable that we set, and the users can customise, or enter in the pipeline form, then we convert that to the actual value for PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATION: 0 in the script. This will give us the ability to add further options or enhancements in future, if they become available. I will add that to the MR and see how it looks.

Production build 0.71.5 2024