Problem/Motivation

PHPUnit 13.2 deprecates TestCase::expectExceptionMessage() in favor of TestCase::expectExceptionMessageIs() (stricter) or TestCase::expectExceptionMessageIsOrContains() (equivalent to TestCase::expectExceptionMessage()).

See Improved API for exception message expectations

Proposed resolution

Focus on tests from the unit-component test suite and for tests extending directly from TestCase in this issue.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3613394

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

mondrake created an issue. See original summary.

mondrake changed the visibility of the branch 3613394-phpunit-13.2-- to hidden.

mondrake changed the visibility of the branch 3613394-phpunit-13.2-- to active.

mondrake’s picture

Status: Active » Needs review
dcam’s picture

Status: Needs review » Needs work

I found one issue with a failing test. Please review my comment on the MR.

Otherwise the changes look good. All uses of expectExceptionMessage() are replaced in the Component tests.

mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

Version: 11.x-dev » main
dcam’s picture

Status: Needs review » Reviewed & tested by the community

yeah, the exception message does have the period at the end. Maybe you tried on PHPUnit 13 that is stricter than 12 in the matching.

Oh. Of course. Yes, I was testing on 13.2.5. 🙄

I reran the tests on 13.2.5. There were no failures this time. I think this is good to go.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Not sure about using the trait in the test classes.

The idea behind the components is that they add implicit dependencies (or any dependencies) on code from other namespaces, but the test trait does this. Do we need to add drupal/core to require-dev or something?

mondrake’s picture

mondrake’s picture

The trait would be temporary until we bump to PHPUnit 13, though. We will have to remove it at that time, since the new methods in PHPUnit 13 are final and we would get fatals if we don’t.

mondrake’s picture

Issue tags: +blocker
dcam’s picture

Status: Needs review » Reviewed & tested by the community

I admit that I don't understand the point that was made in #10. But since a response was given to it, the issue is a blocker, and this has not been followed-up on in over a month I'm going to restore the RTBC status. FWIW it makes sense to me that we would have this temporary trait so that we can get started on these expectation conversions sooner.

  • catch committed f51df2af on main
    task: #3613394 PHPUnit 13.2 - Replace expectExceptionMessage() with...

  • catch committed dbd2f63e on 12.0.x
    task: #3613394 PHPUnit 13.2 - Replace expectExceptionMessage() with...
catch’s picture

Version: main » 12.0.x-dev
Status: Reviewed & tested by the community » Fixed

Ah sorry I missed the reply. Absolutely a good idea to move back to RTBC when the question is answered.

So the components directory is supposed to be self-contained, the code in there can depend on other components and not Drupal\Core. All the way before Drupal 8 was released the idea was to move more and more core code to components, which if it's happening is only happening at a glacial pace but also we've kept to that rule for the code that's there afaik and gradually moved a few things into it.

But... the tests for the components are in core/tests, not within the components themselves, and also given that this is temporary, it will be gone eventually anyway, so we shouldn't worry about it. And #3614056: Define Drupal\TestTools namespace in root composer.json is enough to maybe clean this up later.

Committed/pushed to main and 12.0.x, thanks!

I'm not sure if we need a backport to 11.x at this point, so marking fixed but please re-open if you think we do (did check, and it doesn't cherry-pick cleanly).

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mondrake’s picture

fwiw, when we used to have the PHPUnitCompatibility trait before we bumped PHPUnit to 12, that was living (and still is in D11) in the TestTools namespace anyway.

core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit11