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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tedbow created an issue. See original summary.

omkar.podey’s picture

Assigned: Unassigned » omkar.podey

phenaproxima’s picture

Well, this is problematic.

Here's the PR where PHPUnit's expectErrorMessage() was deprecate: 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?

phenaproxima’s picture

Status: Active » Needs work

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 are simply setting up that expectation in a deprecated way.

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.

phenaproxima’s picture

Assigned: omkar.podey » tedbow
Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

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

phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed
wim leers’s picture

Assigned: tedbow » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.