Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BrowserKit] [HttpKernel] StreamedResponse is not working with BrowserKit after Symfony is upgraded to 6.1 #46445

Open
HtunHtunHtet opened this issue May 24, 2022 · 14 comments
Labels
BrowserKit Bug Help wanted Issues and PRs which are looking for volunteers to complete them. HttpFoundation Status: Reviewed

Comments

@HtunHtunHtet
Copy link
Contributor

Symfony version(s) affected

6.1

Description

Symfony\Component\HttpFoundation\StreamedResponse is not working in tests (BrowserKit) after Symfony is upgraded to 6.1 - the output is not rendered.

How to reproduce

When asserting that following StreamedResponse using BrowserKit produces 'test' output:

return new StreamedResponse(static function (): void {
    echo 'test';
});

the test is passing on Symfony 6.0 (see reproducer app: https://github.com/HtunHtunHtet/bug_app/tree/main) but starts to fail after upgrading to 6.1-RC1 (see: https://github.com/HtunHtunHtet/bug_app/tree/symfony-6.1) as the output is empty:

Below information is the output of the PHPUnit test.

Time: 00:00.150, Memory: 12.00 MB

There was 1 failure:

1) App\Tests\DefaultControllerTest::testSomething
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''

Only the tests are affected as navigating to the controller page returns a correct response.

Possible Solution

No response

Additional Context

It might be related to recent StreamedResponseListener deprecation: #45476

@HtunHtunHtet HtunHtunHtet changed the title StreamedResponse is not working with BrowserKit after Symfony is upgraded to 6.1 [BrowserKit] [HttpKernel] StreamedResponse is not working with BrowserKit after Symfony is upgraded to 6.1 May 24, 2022
@minorbug
Copy link

Thank you @HtunHtunHtet for creating this bug report! This indeed looks like a bug. I reproduced the bug in the "symfony-6.1" branch of https://github.com/HtunHtunHtet/bug_app.

Status: Reviewed

@m-idler
Copy link

m-idler commented Jun 1, 2022

I think i got a similar problem regarding a test for a StreamedResponse:

working test with symfony 6.0

ob_start();
$client->request(Request::METHOD_GET, 'myTestUrl');
$content = \ob_get_clean();
self::assertEquals('foo', $content);

What (know) works for me with symfony 6.1:

$client->request(Request::METHOD_GET, 'myTestUrl');
$content = $client->getInternalResponse()->getContent();
self::assertEquals('foo', $content);

@DaDeather
Copy link
Contributor

If it's currently still unclear why this is happening:
#45476 (comment)

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@IonBazan
Copy link
Contributor

IonBazan commented Mar 2, 2023

@carsonbot, the issue is still relevant. See also linked issue

@carsonbot carsonbot removed the Stalled label Mar 2, 2023
@miladrahimi
Copy link

miladrahimi commented Jul 25, 2023

I still see the issue in Symfony 6.3.
And hopefully the $client->getInternalResponse()->getContent() solution which @m-idler mentioned still works!

@nicolas-grekas
Copy link
Member

Anyone up to give this a try?

@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Jul 27, 2023
@encreinformatique
Copy link

encreinformatique commented Jul 28, 2023

The $client->getInternalResponse()->getContent() worked for me.

        self::$client = self::loggedIn();
        self::$client->request('GET', '/export');
        $content = self::$client->getInternalResponse()->getContent();

        self::assertResponseIsSuccessful();
        self::assertResponseHasHeader('Content-Disposition', 'attachment; filename=users.csv');
        self::assertStringStartsWith('xxx;yyy', $content);

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@miladrahimi
Copy link

miladrahimi commented Feb 12, 2024

Is there any pull request to fix that bug? If not, I think it should be fixed before closing, the bug is easily reproducible.

@carsonbot carsonbot removed the Stalled label Feb 12, 2024
@DaDeather
Copy link
Contributor

Is there any pull request to fix that bug? If not, I think it should be fixed before closing, the bug is easily reproducible.

Someone probably should check if it's not already fixed by the revert here:
#51396

And the ticket here:
#46743

@H4wKs
Copy link
Contributor

H4wKs commented Feb 20, 2024

@DaDeather #51396 did not fix this specific issue, the test still fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BrowserKit Bug Help wanted Issues and PRs which are looking for volunteers to complete them. HttpFoundation Status: Reviewed
Projects
None yet
Development

No branches or pull requests