Suppress symfony 4 response body in phpunit test












0














I am migrating a Silex app to Symfony Flex and everything is working so far, except that when I run the phpunit tests I get the response body output into the phpunit output.



ie.



> bin/phpunit
#!/usr/bin/env php
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

Testing unit
.......<http://data.nobelprize.org/resource/laureate/914> a <http://data.nobelprize.org/terms/Laureate> , <http://xmlns.com/foaf/0.1/Person> ;
<http://www.w3.org/2000/01/rdf-schema#label> "Malala Yousafzai" ;
<http://data.nobelprize.org/terms/laureateAward> <http://data.nobelprize.org/resource/laureateaward/974> ;
<http://data.nobelprize.org/terms/nobelPrize> <http://data.nobelprize.org/resource/nobelprize/Peace/2014> ;


the entire RDF document then



 .                                                            8 / 8 (100%)

Time: 1.07 seconds, Memory: 14.00MB

OK (8 tests, 71 assertions)

Generating code coverage report in Clover XML format ... done


So it is working fine, but I can't figure out how to disable this output?



The request is simply



$this->client->request('GET', "/nobel_914.ttl", , , ['HTTP_ACCEPT' => $request_mime]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed.");
$response = $this->client->getResponse();
$charset = $response->getCharset();


etc.



and the client is setup in a base class like this



class MyAppTestBase extends WebTestCase
{
/**
* @var SymfonyComponentBrowserKitClient
*/
protected $client;

/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->client = static::createClient();
$this->client->catchExceptions(false);
}


I'm sure I'm missing something obvious but this is new to me. I am running in the 'test' environment and with 'debug' == false.



Any help appreciated.










share|improve this question






















  • Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
    – whikloj
    Nov 20 at 21:53












  • Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
    – whikloj
    Nov 20 at 21:54










  • I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
    – Robbie Averill
    Nov 20 at 22:19
















0














I am migrating a Silex app to Symfony Flex and everything is working so far, except that when I run the phpunit tests I get the response body output into the phpunit output.



ie.



> bin/phpunit
#!/usr/bin/env php
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

Testing unit
.......<http://data.nobelprize.org/resource/laureate/914> a <http://data.nobelprize.org/terms/Laureate> , <http://xmlns.com/foaf/0.1/Person> ;
<http://www.w3.org/2000/01/rdf-schema#label> "Malala Yousafzai" ;
<http://data.nobelprize.org/terms/laureateAward> <http://data.nobelprize.org/resource/laureateaward/974> ;
<http://data.nobelprize.org/terms/nobelPrize> <http://data.nobelprize.org/resource/nobelprize/Peace/2014> ;


the entire RDF document then



 .                                                            8 / 8 (100%)

Time: 1.07 seconds, Memory: 14.00MB

OK (8 tests, 71 assertions)

Generating code coverage report in Clover XML format ... done


So it is working fine, but I can't figure out how to disable this output?



The request is simply



$this->client->request('GET', "/nobel_914.ttl", , , ['HTTP_ACCEPT' => $request_mime]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed.");
$response = $this->client->getResponse();
$charset = $response->getCharset();


etc.



and the client is setup in a base class like this



class MyAppTestBase extends WebTestCase
{
/**
* @var SymfonyComponentBrowserKitClient
*/
protected $client;

/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->client = static::createClient();
$this->client->catchExceptions(false);
}


I'm sure I'm missing something obvious but this is new to me. I am running in the 'test' environment and with 'debug' == false.



Any help appreciated.










share|improve this question






















  • Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
    – whikloj
    Nov 20 at 21:53












  • Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
    – whikloj
    Nov 20 at 21:54










  • I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
    – Robbie Averill
    Nov 20 at 22:19














0












0








0







I am migrating a Silex app to Symfony Flex and everything is working so far, except that when I run the phpunit tests I get the response body output into the phpunit output.



ie.



> bin/phpunit
#!/usr/bin/env php
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

Testing unit
.......<http://data.nobelprize.org/resource/laureate/914> a <http://data.nobelprize.org/terms/Laureate> , <http://xmlns.com/foaf/0.1/Person> ;
<http://www.w3.org/2000/01/rdf-schema#label> "Malala Yousafzai" ;
<http://data.nobelprize.org/terms/laureateAward> <http://data.nobelprize.org/resource/laureateaward/974> ;
<http://data.nobelprize.org/terms/nobelPrize> <http://data.nobelprize.org/resource/nobelprize/Peace/2014> ;


the entire RDF document then



 .                                                            8 / 8 (100%)

Time: 1.07 seconds, Memory: 14.00MB

OK (8 tests, 71 assertions)

Generating code coverage report in Clover XML format ... done


So it is working fine, but I can't figure out how to disable this output?



The request is simply



$this->client->request('GET', "/nobel_914.ttl", , , ['HTTP_ACCEPT' => $request_mime]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed.");
$response = $this->client->getResponse();
$charset = $response->getCharset();


etc.



and the client is setup in a base class like this



class MyAppTestBase extends WebTestCase
{
/**
* @var SymfonyComponentBrowserKitClient
*/
protected $client;

/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->client = static::createClient();
$this->client->catchExceptions(false);
}


I'm sure I'm missing something obvious but this is new to me. I am running in the 'test' environment and with 'debug' == false.



Any help appreciated.










share|improve this question













I am migrating a Silex app to Symfony Flex and everything is working so far, except that when I run the phpunit tests I get the response body output into the phpunit output.



ie.



> bin/phpunit
#!/usr/bin/env php
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

Testing unit
.......<http://data.nobelprize.org/resource/laureate/914> a <http://data.nobelprize.org/terms/Laureate> , <http://xmlns.com/foaf/0.1/Person> ;
<http://www.w3.org/2000/01/rdf-schema#label> "Malala Yousafzai" ;
<http://data.nobelprize.org/terms/laureateAward> <http://data.nobelprize.org/resource/laureateaward/974> ;
<http://data.nobelprize.org/terms/nobelPrize> <http://data.nobelprize.org/resource/nobelprize/Peace/2014> ;


the entire RDF document then



 .                                                            8 / 8 (100%)

Time: 1.07 seconds, Memory: 14.00MB

OK (8 tests, 71 assertions)

Generating code coverage report in Clover XML format ... done


So it is working fine, but I can't figure out how to disable this output?



The request is simply



$this->client->request('GET', "/nobel_914.ttl", , , ['HTTP_ACCEPT' => $request_mime]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed.");
$response = $this->client->getResponse();
$charset = $response->getCharset();


etc.



and the client is setup in a base class like this



class MyAppTestBase extends WebTestCase
{
/**
* @var SymfonyComponentBrowserKitClient
*/
protected $client;

/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->client = static::createClient();
$this->client->catchExceptions(false);
}


I'm sure I'm missing something obvious but this is new to me. I am running in the 'test' environment and with 'debug' == false.



Any help appreciated.







phpunit symfony4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 18:56









whikloj

1




1












  • Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
    – whikloj
    Nov 20 at 21:53












  • Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
    – whikloj
    Nov 20 at 21:54










  • I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
    – Robbie Averill
    Nov 20 at 22:19


















  • Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
    – whikloj
    Nov 20 at 21:53












  • Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
    – whikloj
    Nov 20 at 21:54










  • I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
    – Robbie Averill
    Nov 20 at 22:19
















Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
– whikloj
Nov 20 at 21:53






Here is full execution if you want to see it. ci.appveyor.com/project/acoburn/static-ldp/builds/20444722#L302
– whikloj
Nov 20 at 21:53














Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
– whikloj
Nov 20 at 21:54




Additionally here is the PR with all the code changes I am implementing. github.com/trellis-ldp/static-ldp/pull/39 You can see the test code, etc in case that helps.
– whikloj
Nov 20 at 21:54












I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
– Robbie Averill
Nov 20 at 22:19




I'm not familiar with WebTestCase, but since it's an integration test or functional test rather than a unit test, you could always buffer the output
– Robbie Averill
Nov 20 at 22:19












1 Answer
1






active

oldest

votes


















0














So this was probably a problem all along but just started being exposed in the switch from Silex to Symfony Flex.



We were streaming responses via



$filename = $this->path;
$stream = function () use ($filename) {
readfile($filename);
};
return new StreamedResponse($stream, 200, $res->headers->all());


and the readfile was throwing the content to the output buffer. Switching the readfile to file_get_contents resolved this



$filename = $this->path;
$stream = function () use ($filename) {
file_get_contents($filename);
};
return new StreamedResponse($stream, 200, $res->headers->all());





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399745%2fsuppress-symfony-4-response-body-in-phpunit-test%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So this was probably a problem all along but just started being exposed in the switch from Silex to Symfony Flex.



    We were streaming responses via



    $filename = $this->path;
    $stream = function () use ($filename) {
    readfile($filename);
    };
    return new StreamedResponse($stream, 200, $res->headers->all());


    and the readfile was throwing the content to the output buffer. Switching the readfile to file_get_contents resolved this



    $filename = $this->path;
    $stream = function () use ($filename) {
    file_get_contents($filename);
    };
    return new StreamedResponse($stream, 200, $res->headers->all());





    share|improve this answer


























      0














      So this was probably a problem all along but just started being exposed in the switch from Silex to Symfony Flex.



      We were streaming responses via



      $filename = $this->path;
      $stream = function () use ($filename) {
      readfile($filename);
      };
      return new StreamedResponse($stream, 200, $res->headers->all());


      and the readfile was throwing the content to the output buffer. Switching the readfile to file_get_contents resolved this



      $filename = $this->path;
      $stream = function () use ($filename) {
      file_get_contents($filename);
      };
      return new StreamedResponse($stream, 200, $res->headers->all());





      share|improve this answer
























        0












        0








        0






        So this was probably a problem all along but just started being exposed in the switch from Silex to Symfony Flex.



        We were streaming responses via



        $filename = $this->path;
        $stream = function () use ($filename) {
        readfile($filename);
        };
        return new StreamedResponse($stream, 200, $res->headers->all());


        and the readfile was throwing the content to the output buffer. Switching the readfile to file_get_contents resolved this



        $filename = $this->path;
        $stream = function () use ($filename) {
        file_get_contents($filename);
        };
        return new StreamedResponse($stream, 200, $res->headers->all());





        share|improve this answer












        So this was probably a problem all along but just started being exposed in the switch from Silex to Symfony Flex.



        We were streaming responses via



        $filename = $this->path;
        $stream = function () use ($filename) {
        readfile($filename);
        };
        return new StreamedResponse($stream, 200, $res->headers->all());


        and the readfile was throwing the content to the output buffer. Switching the readfile to file_get_contents resolved this



        $filename = $this->path;
        $stream = function () use ($filename) {
        file_get_contents($filename);
        };
        return new StreamedResponse($stream, 200, $res->headers->all());






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 14:51









        whikloj

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399745%2fsuppress-symfony-4-response-body-in-phpunit-test%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen