Closed (fixed)
Project:
Drupal core
Version:
main
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Dec 2025 at 13:08 UTC
Updated:
22 Apr 2026 at 06:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
mondrakeComment #4
dcam commentedComment #5
dcam commentedComment #7
dcam commentedAdded issues for all Core modules.
Comment #8
dcam commentedHow to Review These Issues
A basic review would consist of:
->expects($this->any())are removed from the altered classes.any()were deleted, for example->expects($this->once())or->expects($this->atLeastOnce()). Sometimes this was the easiest way to stop the notices. I tried to avoid doing this and also limit these changes to mocked services that were not the class under test. But it's possible that those expectations are actually critical to verifying the behavior of the tested class.If you would like to check the PHPUnit 12 output for yourself, then you'll have to do a little extra work on your local environment:
composer require --dev phpunit/phpunit:^12 -Wphpunitcommands normally.curl https://www.drupal.org/files/issues/2026-01-25/phpunit12.patch | git apply--display-phpunit-notices --display-phpunit-deprecationsto see the notices and deprecations. Example command:ddev exec vendor/bin/phpunit --display-phpunit-notices --display-phpunit-deprecations core/modules/block/tests/src/UnitComment #9
dcam commentedStrategies for Fixing Notices
createMock()or worsegetMockBuilder()and then nothing is done with the resultingMockObject. These are easily replaced withcreateStub().->expects($this->any())was removed, then it may be replaced by->expects($this->atLeastOnce()). This strategy isn't viable in a lot of cases, such as when mocks are instantiated insetUp()functions, but aren't used in all of the class's tests.setUp()function that only sets one or two expectations in a large class, check those expectations. The expectations may be a "nice to have" and not critical the functionality being tested. In those cases, the expectations might be removed. When an expectation is removed (other thanany()), reviewers should be extra careful to validate the change.Comment #10
mondrakeGreat work, @dcam.
Comment #12
dcam commentedComment #13
longwaveI just read https://phpunit.expert/articles/the-stub-mock-intervention.html and there is a solution to this: the
#[AllowMockObjectsWithoutExpectations]attribute (which if we use it, should be used sparingly for this kind of situation - probably only where setup is done in a base class, and we don't know how subclasses will use it?)Comment #14
dcam commentedIf I'm not mistaken, we can't use
#[AllowMockObjectsWithoutExpectations]until we're actually using PHPUnit 12.5. So my focus has been entirely on fixing the notices without ignoring some instances with the attribute.Comment #15
dcam commentedComment #16
dcam commentedComment #17
dcam commentedComment #18
smustgrave commentedThat's 9 in RTBC, lets see if those land
Comment #20
dcam commentedComment #21
dcam commentedWe are SO CLOSE to being done with this project. Figuratively speaking, my pencil is down. I've found all of the notices that I'm able or willing to find at the moment. There may be some in Functional tests or areas of Core where there are tests of which I'm not aware. Those can all be found by the PHPUnit 12 upgrade issue.
Comment #22
quietone commentedComment #23
dcam commentedAll child issues have been fixed.
Comment #25
mondrakeFiled #3583606: Fix usage of with*() without expects() in mocks