Headers already sent across tests
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.
This is not really a problem with EcomDev but with PHPUnit itself. As discussed in
StackOverflow, PHPUnit gives you the option to @runInSeparateProcess
I have put
static public function setUpBeforeClass()
{
Mage::$headersSentThrowsException = false;
parent::setUpBeforeClass();
}
inside my test class, this removed the exception
Any update to this problem ? I have problem writing Controller tests, does anyone have some working examples??
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 :/