[8.x] Add flush handler to output buffer for streamed test response (bugfix) #42481
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.
This PR fixes a bug which may lead to missed content for a streamed test response.
Typically, code which wants to ensure that its output is really streamed to browser contains code lines like these
This is the recommended best practice to ensure that all buffers are flushed and the content is sent to the browser:
The current implementation of the test response does not work if one follows this practice. In particular,
ob_flush
sends all content of the output buffer to stdout in test mode and clears the buffer. The methodob_get_clean()
as used by the current implementation will always return the empty string. This meansTestResponse
misses all output.The correct way is to register a handler with
ob_start
which is called whenever the buffer is flushed. PHP Manual:Note, the bugfix always returns the empty string. During tests there is on browser and the output would be sent to stdout, if we were not returning the empty string.