test: fix deprecations and warnings reported by phpunit 13 - #8558
Open
mislavjakopovic wants to merge 1 commit into
Open
mislavjakopovic wants to merge 1 commit into
mislavjakopovic wants to merge 1 commit into
Conversation
mislavjakopovic
marked this pull request as ready for review
September 21, 2026 20:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHPUnit 13 makes three things in our tests a problem:
with()on a test double (stub, mock) that never callsexpects()is deprecated (Deprecate usingwith*()on test stubs sebastianbergmann/phpunit#6510, PHPUnit 12.5.11) and PHPUnit 13.0 removed thewith*()methods from theInvocationStubberinterface - the runtime deprecation announces the removal in PHPUnit 14. PHPUnit 13 also emits a "No expectations were configured for the mock object" notice for such doubles ("No expectations were configured for the mock object ..." notice is emitted whenwith()is used withoutexpects()sebastianbergmann/phpunit#6509).any()matcher is deprecated (Deprecateany()matcher sebastianbergmann/phpunit#6461, soft in 12.5.5, hard in 13.0).assertEquals()emits a warning since PHPUnit 13.2.0 (sebastianbergmann/phpunit@08aedf2, built on Expose detection of closure comparisons sebastianbergmann/comparator#163), which fails the graphql component job because its configuration hasfailOnWarning.Currently PHPStan with PHPUnit 13 installed reports the 68
with()calls as calls to an undefined method onInvocationStubber.This fix adjusts the test files concerned:
willReturnMap()and are created withcreateStub();with()and get a real expectation,expects($this->once()), oratLeastOnce()for the one shared in asetUp();expects($this->any())becomesatLeastOnce();FieldsBuilderTestcompares resolver closures withassertSame().Additional clarification on why mocks were replaced with stubs
Without
with()doubles carry no expectation, and as mentioned in problem #1 above PHPUnit 12.4+ flags every suchcreateMock()object with "No expectations were configured for the mock object... use a test stub instead" (sebastianbergmann/phpunit#6509). Creating them as stubs does what the notice asks and keeps the notice count of every component suite unchanged; a stub is the same double minusexpects(), which these objects never used. Following this change, variables were also renamed from$*Mockto$*Stubwhere their creation changed.This pull request is part of several fixes needed to enable PHPUnit 13 support in PR #8537.