Skip to content

fix(symfony): check HttpClientTrait before loading the test client - #8613

Open
aleksejs1 wants to merge 1 commit into
api-platform:5.0from
aleksejs1:fix/test-client-pass-http-client
Open

aleksejs1 wants to merge 1 commit into
api-platform:5.0from
aleksejs1:fix/test-client-pass-http-client

Conversation

@aleksejs1

Copy link
Copy Markdown
Q A
Branch? 5.0
Tickets Closes #8612
License MIT
Doc PR -

Since #8574, the container fails to compile when symfony/http-client is not installed. class_exists(Client::class) ran first and autoloaded Client, which uses HttpClientTrait. That is a fatal error, and the trait_exists(HttpClientTrait::class) guard that used to cover the case was never reached. The Client check now runs after the trait check.

Test: TestClientPassTest::testProcessWithoutHttpClient. It runs in a separate process and hides HttpClientTrait from the autoloaders, the same as an application without symfony/http-client.

Without the fix:

1) ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler\TestClientPassTest::testProcessWithoutHttpClient
Error: Trait "Symfony\Component\HttpClient\HttpClientTrait" not found

/app/src/Test/Client.php:32
/app/src/Symfony/Bundle/DependencyInjection/Compiler/TestClientPass.php:29

With the fix: OK (4 tests, 6 assertions). tests/Symfony/Bundle/DependencyInjection/ passes: 68 tests, 2 skipped. php-cs-fixer and PHPStan report nothing on the two changed files.

I left CHANGELOG.md alone because its entries link to the commit hash.

The Client class check added in api-platform#8574 ran first and autoloaded Client,
which uses HttpClientTrait. Without symfony/http-client that is a fatal
error, and the trait check that used to cover it was never reached.

Fixes api-platform#8612

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aleksejs1

Copy link
Copy Markdown
Author

The five red checks are not caused by this change:

  • PHPStan (PHP 8.5) and openapi (lowest, minimal-changes) fail the same way on the head of 5.0 (c092cd0). PHPStan reports 8 errors in OpenApiFactoryTest and PurgeHttpCacheListenerTest, and openapi fails testDeleteOperationWithDeserializeDocumentsRequestBody.
  • PHPUnit (no deprecations) and PHPUnit (Symfony dev) fail on the deprecation of ApiPlatform\Symfony\Bundle\Test\ApiTestCase, triggered outside of tests. fix(metadata): use operation shortName for resources without ApiResource #8609 fails "no deprecations" the same way.

The jobs that run TestClientPassTest pass.

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