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

API tests stream response in terminal #91

Closed
lexdevelop opened this issue Sep 12, 2018 · 11 comments
Closed

API tests stream response in terminal #91

lexdevelop opened this issue Sep 12, 2018 · 11 comments

Comments

@lexdevelop
Copy link

  • Codeception issue: My symfony controllers may return Symfony\Component\HttpFoundation\StreamedResponse which causes the problem when i run test in terminal, even without --debug or --steps i got weird characters in my terminal like:

`Codeception PHP Testing Framework v2.4.5
Powered by PHPUnit 7.3.4 by Sebastian Bergmann and contributors.

[1mApi Tests (12) [22m--------------------------------------------------------------------------------------------------------------------------------
Testing api

  • [35;1mInvoiceCest:[39;22m Test Try to get individual membership renewal link without authentication
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to get individual membership renewal link without authentication [32m(0.06s)[39m
  • [35;1mInvoiceCest:[39;22m Test membership renewal link by individual with auth
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to get individual membership renewal link [32m(14.70s)[39m
  • [35;1mInvoiceCest:[39;22m Test Try to get organization membership renewal link without authentication
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to get organization membership renewal link without authentication [32m(0.04s)[39m
  • [35;1mInvoiceCest:[39;22m Test membership renewal link by organization with auth
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to get organization membership renewal link [32m(14.35s)[39m
  • [35;1mInvoiceCest:[39;22m Test Try to check if organization invoice exists without authentication
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to check if organization invoice exists without authentication [32m(0.03s)[39m
  • [35;1mInvoiceCest:[39;22m Test does invoice exist by organization with auth
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to check if organization invoice exists [32m(14.25s)[39m
  • [35;1mInvoiceCest:[39;22m Test Try to check if individual invoice exists without authentication
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to check if individual invoice exists without authentication [32m(0.03s)[39m
  • [35;1mInvoiceCest:[39;22m Test does invoice exist by individual with auth
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to check if individual invoice exists [32m(15.56s)[39m
  • [35;1mInvoiceCest:[39;22m Test Try to get customer organization invoice without authentication
    [32;1m✔[39;22m [35;1mInvoiceCest:[39;22m Test try to get customer organization invoice without authentication [32m(0.03s)[39m
  • [35;1mInvoiceCest:[39;22m Test get member invoice by organization with auth
    %PDF-1.4
    1 0 obj
    <<
    /Title (��)
    /Creator (��wkhtmltopdf 0.12.5)
    /Producer (��Qt 4.8.7)
    /CreationDate (D:20180912115057+02'00')

endobj
3 0 obj
<<
/Type /ExtGState
/SA true
/SM 0.02
/ca 1.0
/CA 1.0
/AIS false
/SMask /None>>
endobj
4 0 obj
[/Pattern /DeviceRGB]
endobj
6 0 obj
<<
/Type /XObject`
The content is huge, this is just one part.

Test is always finished successfully, but this is really annoying output.

@Naktibalda
Copy link
Member

Can you do something with this type of response in Symfony Connector to prevent it from making an output?

@lexdevelop
Copy link
Author

@Naktibalda not sure since i'm using sendGet() from REST module.
$I->sendGET('url/i/want');
My api.suite.yml

actor: ApiTester
modules:
    enabled:
        - \Helper\Api
        - Symfony:
              app_path: 'app'
              environment: 'test'
              debug: true
        - REST:
              url: '/'
              depends: Symfony
              part: Json

@Naktibalda
Copy link
Member

REST module calls request method of Connector (indirectly).

@lexdevelop
Copy link
Author

I have try to play with doRequest() but didn't find the way to solve this.
Even when i try to run test with --silent flag i got this response, sounds like content from response populate output buffer of the tests.

@bmorrical-ICC
Copy link

Same issue, looking for resolution. Thanks,

@lexdevelop
Copy link
Author

lexdevelop commented Oct 2, 2018

ob_start();
$I->sendGET('link/to/streamed/response');
$content = ob_get_clean();

This way you will not get streamed response in your terminal.
Maybe we can check for such response and turn on output buffering.
Symfony connector extends \Symfony\Component\HttpKernel\Client which has protected function to support StreamedResponse.

protected function filterResponse($response)
    {
        // this is needed to support StreamedResponse
        ob_start();
        $response->sendContent();
        $content = ob_get_clean();

        return new DomResponse($content, $response->getStatusCode(), $response->headers->all());
    }

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 5, 2021
@TavoNiievez
Copy link
Member

This was also asked in the Symfony repository, and in that thread the how and why is explained very well.

Some answers suggest decorating the Symfony\Component\HttpKernel\EventListener\StreamedResponseListener class.

So, 'Closing as everything is well described here, and that's how things work.'

@TerjeBr
Copy link

TerjeBr commented Nov 21, 2022

The corresponding issue was closed in Symfony, but it should be fixed here. Please reopen this issue.

@Naktibalda
Copy link
Member

Corresponding issue was closed 2 years earlier than this issue.
Workaround was documented in the linked comment symfony/symfony#25005 (comment)

@TerjeBr
Copy link

TerjeBr commented Nov 22, 2022

Yes, that is a workaround. But the issue is still there. And the issue is with codeception. Do you not want to fix this issue? Should the users of codeception just continue to be surprised that this does not work, search the internet for a soution, and then each have to apply this workaround? I would hope you instead would want to fix this in the codeception code.

@Naktibalda
Copy link
Member

It seems that workaroud requires configuration change in the application, so is it even possible to fix it in Codeception code?

Please raise pull request if you can get it working.

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

No branches or pull requests

5 participants