EcomDev/EcomDev_PHPUnit

Cannot send session cookie

Closed this issue · 4 comments

So I get the following error on one of my block tests.

1) Namespace_TestingFootball_Test_Block_Adminhtml_Player_Grid::testCollectionType Exception: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/magento/vendor/phpunit/phpunit/src/Util/Printer.php:172) in /var/www/magento/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php on line 125

My test for reference:

protected function setUp()
{
    $this->_block = $this::app()->getLayout()->createBlock('namespace_testingfootball/adminhtml_player_grid');
}

/**
 * Make sure the correct collection is called.
 */
public function testCollectionType()
{
    // calls the _getCollection method so we can check it later.
    $this->_block->toHtml();

    $this->assertInstanceOf('Namespace_TestingFootball_Model_Resource_Player_Collection', $this->_block->getCollection());
}

The reasons are quite well researched here at stackoverflow

This is optional via the configuration now so you do not have to do phpunit --stderr.

Would this be valuable to add in the default phpunit.xml.dist as I think it is quite a common problem with Magento, unless I am doing something wrong then please tell me.

After using it for a couple of days, it should not be a default option as it disabled useful output, maybe it could be added to the documentation, or set to false.

Please submit a pull request to dev branch.

@IvanChepurnyi stdout is much more useful, I have reverted it locally.

To solve the original issue I followed some advice on stackoverflow which basically says do @session_start in setUp().

@IvanChepurnyi I agree with @jzahedieh here that directing to stderr is not ideal, but the solution he's provided is not ideal either. IMO it is a better approach though, and it might be nice to see those silencers added to the setUp() and tearDown() (@session_write_close()) higher up the chain in the EcomDev module than individual tests?