Problem/Motivation

PHPUnit 13 deprecates usage of with*() without expects() in mocks.

See pipeline raw logs in #3574681: [Nov 2026] Introduce support for PHPUnit 13.5 for full report.

Proposed resolution

Before adopting PHPUnit 13, fix the usages, either converting the mocks to stubs, or adding explicit expectations on the calls to the mocked method.

In this issue, do a first round with a limited number of fixes to establish a proper pattern.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3583606

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’s picture

Title: Fix usage of with*() without expects() in mocks » Fix usage of with*() without expects() in mocks - round 1
Issue summary: View changes

mondrake’s picture

Status: Active » Needs review
smustgrave’s picture

What's the scope of this one?

dcam’s picture

Status: Needs review » Needs work

I found a couple of documentation things to comment on. Otherwise, it looks good to me.

mondrake’s picture

Status: Needs work » Needs review

The scope is "do a first round with a limited number of fixes to establish a proper pattern", from the IS.

These changes are tricky and IMHO makes sense not to go too far ahead, if something needs to be redone, better with a limited patch,

If the question is why these tests and not others - just went through the raw job log of the failures in #3574681: [Nov 2026] Introduce support for PHPUnit 13.5 and picked the first ones I came across, stopping when the MR started becoming too large.

nitinkumar_7’s picture

I reviewed and tested the changes on this branch locally under PHP 8.4.

The approach is correct and clean. Explicitly adding expectations like `expects($this->once())` or `expects($this->exactly(2))` to the mock method chains is the correct way to resolve these deprecations for PHPUnit 13.
Testing : Ran the modified test suites (including `EntityUnitTest`, `AccessResultTest`, `TwigExtensionTest`, and `FieldTest`) and confirmed that they all compile and pass perfectly with zero issues.

The changes look solid and are ready!

dcam’s picture

Status: Needs review » Reviewed & tested by the community

My feedback was addressed. It looks good to me.

amateescu’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 78f32f6b9fc to main. Thanks!

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.

  • amateescu committed 78f32f6b on main
    task: #3583606 Fix usage of with*() without expects() in mocks - round 1...

Status: Fixed » Closed (fixed)

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