EcomDev_PHPUnit icon indicating copy to clipboard operation
EcomDev_PHPUnit copied to clipboard

Headers already sent across tests

Open ScreamingDev opened this issue 12 years ago • 4 comments

First of all: The response object does not seem to be reset between test suites.

I got a simple test with at least these lines:

        // inline translation disabled
        $this->assertFalse(
             (bool) $this->app()->getStore()->getConfig('dev/translate_inline/active')
        );

        // dispatch
        $route = 'lemike_devmode/toolbox/clearCache';
        $this->dispatch($route);

Enough to make the next test fail with the message "Cannot send headers; headers already sent" from EcomDev_PHPUnit/app/code/community/EcomDev/PHPUnit/Controller/Response/Http.php:223

Even when the "clearCacheAction" that's first tested is completely empty the response tells me that this has been dispatched (getSentHeaders):

array(2) {
  [""]=>
  string(12) "HTTP/1.1 200"
  ["Content-Type"]=>
  string(24) "text/html; charset=UTF-8"
}

So I have to change Response::$headersSentThrowsException to false but this can't be the solution all the time. Because I run a test and another one that does nothing except a dispatch on an empty action and then it fails.

ScreamingDev avatar Oct 13 '13 06:10 ScreamingDev

This is not really a problem with EcomDev but with PHPUnit itself. As discussed in StackOverflow, PHPUnit gives you the option to @runInSeparateProcess

chernjie avatar Oct 25 '13 09:10 chernjie

I have put

static public function setUpBeforeClass()
    {
        Mage::$headersSentThrowsException = false;
        parent::setUpBeforeClass();
    }

inside my test class, this removed the exception

edi9999 avatar Apr 17 '15 07:04 edi9999

Any update to this problem ? I have problem writing Controller tests, does anyone have some working examples??

Ig0r-M-magic42 avatar Dec 05 '16 15:12 Ig0r-M-magic42

I remember opening this issue and that it has been solved. But I don't remember how and where. Please have a look at these tests and what edi said.

https://github.com/sourcerer-mike/magento-devMode/tree/develop/src/app/code/local/LeMike/DevModeTest/Test/Controller

Running them in a separate process is a way but not a good solution. Mocking could be a way. This issue is hard as it mostly comes down to the code written in the action :/

ScreamingDev avatar Dec 08 '16 07:12 ScreamingDev