fix(test): capture streamedresponse body in test client response#8235
Merged
soyuka merged 2 commits intoJun 4, 2026
Merged
Conversation
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
soyuka
commented
Jun 4, 2026
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.
Summary
Since Symfony 6.1 (symfony/symfony#46445),
HttpFoundation\StreamedResponse::getContent()returnsfalsebecause 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::filterResponsealready buffers the streamed output viaob_start()and stores it on the BrowserKitResponse. The fix reads from the BrowserKit response when the kernel response is aStreamedResponse(coversStreamedJsonResponsetoo), avoiding both the empty-body case and any re-streaming.Reproduction
A state provider (or controller) returning
StreamedResponseinvoked throughApiTestCase::createClient()produced an empty$response->getContent().Test plan
StreamedResponseandStreamedJsonResponsecases (tests/Symfony/Bundle/Test/ResponseTest.php).vendor/bin/phpunit tests/Symfony/Bundle/Test— 66 tests, 108 assertions, all green.Fixes #5780