Skip to content

test(openapi): fix factory test for phpunit 13 - #8567

Merged
soyuka merged 1 commit into
api-platform:5.0from
soyuka:fix/phpstan-openapi-factory-test-5.0
Sep 23, 2026
Merged

soyuka merged 1 commit into
api-platform:5.0from
soyuka:fix/phpstan-openapi-factory-test-5.0

Conversation

@soyuka

@soyuka soyuka commented Sep 23, 2026

Copy link
Copy Markdown
Member

PHPStan (PHP 8.5) is currently red on 5.0 itself. This fixes it. 11 errors, one file,
two independent causes, both from test code that only ever compiled on 4.4.

I introduced this. #8562 landed on 4.4 green, and my 4.4 → 5.0 merge-up (81f2cdfe9)
carried it across with no textual conflict.

InvocationStubber::with(), 10 errors

Call to an undefined method PHPUnit\Framework\MockObject\InvocationStubber::with()

5.0 runs PHPUnit 13 since #8537, which changed what method() returns on a stubbed
double, so with() is gone from it. The five filter-locator doubles move to createStub
plus willReturnMap, matching the pattern the phpunit 13 migration already used in
src/State/Tests/CallableProcessorTest.php.

Worth noting these doubles assert nothing about being called, so createStub was the
correct tool all along and createMock was the wrong one before PHPUnit 13 ever made it an
error.

DefinitionNameFactory, 1 error

Class ApiPlatform\JsonSchema\DefinitionNameFactory does not have a constructor
and must be instantiated without any parameters.

__construct(?array $distinctFormats = null) exists on 4.4 and was removed on 5.0. The
helper no longer passes an argument. No other call site under src/OpenApi/Tests/ passes
one.

Verification

PHPStan on the file: 11 errors before, [OK] No errors after. The before state was
confirmed by swapping in the upstream/5.0 copy of the file rather than inferred.

All six affected tests pass individually.

Not addressed

Three untouched createMock() calls in the same helper raise a PHPUnit 13 notice
recommending createStub. They are notices, not errors, and PHPStan does not flag them, so
they are left out to keep this fix minimal while 5.0 is red. Worth a follow-up cleanup.

This test code came from 4.4 through the up-merge and only compiled there. PHPUnit 13, now
on 5.0, no longer exposes with() on what method() returns for a stubbed double, so the five
filter-locator doubles move to createStub plus willReturnMap. They assert nothing about
being called, so createStub was always the right tool.

DefinitionNameFactory::__construct was removed on 5.0, so the helper no longer passes an
argument to it.
@soyuka
soyuka merged commit 882239d into api-platform:5.0 Sep 23, 2026
114 of 117 checks passed
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