Tests failing on failing on 9.x core branches because of deprecation error

Created on 6 February 2023, about 2 years ago
Updated 8 February 2023, about 2 years ago

Problem/Motivation

See https://www.drupal.org/pift-ci-job/2584887 as an example

There was 1 warning:

1) Drupal\Tests\automatic_updates\Kernel\StatusCheck\RequestedUpdateValidatorTest::testErrorMessageOnEmptyCorePackages
Expecting E_ERROR and E_USER_ERROR is deprecated and will no longer be possible in PHPUnit 10.

/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Steps to reproduce

Proposed resolution

TBD

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States tedbow Ithaca, NY, USA

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

Comments & Activities

  • Issue created by @tedbow
  • Assigned to omkar.podey
  • @omkarpodey opened merge request.
  • 🇺🇸United States phenaproxima Massachusetts

    Well, this is problematic.

    Here's the PR where PHPUnit's expectErrorMessage() was removed: https://github.com/sebastianbergmann/phpunit/issues/5062

    This PR does not explain the rationale for the change in any helpful way. Sebastian says:

    There are no replacements. PHPUnit 10 no longer converts E_* to exceptions, therefore E_* can no longer be expected.

    Well, er...okay, then?

    @alexpott asked this but has so far received no reply:

    what is the recommended way of testing that an error is triggered in PHPUnit 10? If you want to assert that an E_USER_WARNING is thrown by your code what is the best way to do this? Should you replace the error handler as above or is there a better way?

  • Status changed to Needs work about 2 years ago
  • 🇺🇸United States phenaproxima Massachusetts

    Looking into this more closely...I think this worked only by coincidence.

    I'm not sure why $this->expectErrorMessage() was called, but I suspect it was simply an innocent mistake on the part of whoever wrote that line. Because PHPUnit defines that method, it didn't die with a "call to undefined method" or anything like that.

    Here's what $this->expectErrorMessage() does: https://github.com/sebastianbergmann/phpunit/commit/3812fd713359a21aed38...

    It's just a thin wrapper around $this->expectExceptionMessage()!

    So, indeed, the validator is legitimately raising a StageValidationException. We are expecting the correct message. We simply are using a deprecated method call to make that happen.

    Therefore, all we have to do here is call $this->expectExceptionMessage() directly instead, and this problem will go away forever. For clarity and explicitness, we should probably also add a $this->expectException(StageValidationException::class); beforehand, too.

  • Assigned to tedbow
  • Status changed to Needs review about 2 years ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to RTBC about 2 years ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Yes, core has been using that method for years. 👍

  • Status changed to Fixed about 2 years ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Issue was unassigned.
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024