Skip to content

test: fix deprecations and warnings reported by phpunit 13 - #8558

Open
mislavjakopovic wants to merge 1 commit into
api-platform:5.0from
mislavjakopovic:test/fix-deprecations-and-warnings-reported-by-phpunit-13
Open

mislavjakopovic wants to merge 1 commit into
api-platform:5.0from
mislavjakopovic:test/fix-deprecations-and-warnings-reported-by-phpunit-13

Conversation

@mislavjakopovic

@mislavjakopovic mislavjakopovic commented Sep 21, 2026

Copy link
Copy Markdown
Q A
Branch? 5.0
Tickets none
PRs Preparation for #8537
License MIT
Doc PR n/a

PHPUnit 13 makes three things in our tests a problem:

Currently PHPStan with PHPUnit 13 installed reports the 68 with() calls as calls to an undefined method on InvocationStubber.

This fix adjusts the test files concerned:

  • doubles that only select a return value use willReturnMap() and are created with createStub();
  • doubles where the call itself was the point keep with() and get a real expectation, expects($this->once()), or atLeastOnce() for the one shared in a setUp();
  • expects($this->any()) becomes atLeastOnce();
  • FieldsBuilderTest compares resolver closures with assertSame().

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 such createMock() 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 minus expects(), which these objects never used. Following this change, variables were also renamed from $*Mock to $*Stub where their creation changed.

This pull request is part of several fixes needed to enable PHPUnit 13 support in PR #8537.

@mislavjakopovic
mislavjakopovic marked this pull request as ready for review September 21, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant