Skip to content

fix(test): capture streamedresponse body in test client response#8235

Merged
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix/streamed-response-test-client-5780
Jun 4, 2026
Merged

fix(test): capture streamedresponse body in test client response#8235
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix/streamed-response-test-client-5780

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 4, 2026

Summary

Since Symfony 6.1 (symfony/symfony#46445), HttpFoundation\StreamedResponse::getContent() returns false because the body is streamed via a callback. The test client wrapper (ApiPlatform\Symfony\Bundle\Test\Response) cast that to string in its constructor, yielding an empty body so functional tests reading $response->getContent() against streamed endpoints saw "" instead of the actual response.

BrowserKit\HttpKernelBrowser::filterResponse already buffers the streamed output via ob_start() and stores it on the BrowserKit Response. The fix reads from the BrowserKit response when the kernel response is a StreamedResponse (covers StreamedJsonResponse too), avoiding both the empty-body case and any re-streaming.

Reproduction

A state provider (or controller) returning StreamedResponse invoked through ApiTestCase::createClient() produced an empty $response->getContent().

Test plan

  • Added failing test covering StreamedResponse and StreamedJsonResponse cases (tests/Symfony/Bundle/Test/ResponseTest.php).
  • Test passes after the fix.
  • vendor/bin/phpunit tests/Symfony/Bundle/Test — 66 tests, 108 assertions, all green.

Fixes #5780

Since Symfony 6.1 (symfony/symfony#46445), HttpFoundation's StreamedResponse::getContent()
returns false because the body is streamed via a callback and never buffered on the response
object. Casting that to string in the test client's Response wrapper yielded an empty body,
so assertions on streamed endpoints (e.g. a state provider returning StreamedResponse or
StreamedJsonResponse) read "" instead of the actual content.

BrowserKit's HttpKernelBrowser::filterResponse already buffers the streamed output via
ob_start() and stores it on the BrowserKit Response. The test client wrapper now reads
from the BrowserKit response when the kernel response is a StreamedResponse (covers
StreamedJsonResponse too), avoiding both the empty-body case and any re-streaming.

Fixes api-platform#5780
Comment thread src/Symfony/Bundle/Test/Response.php Outdated
@soyuka soyuka merged commit 8567366 into api-platform:4.3 Jun 4, 2026
104 of 106 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