4

We are using the EcomDev package to test our Magento store, and one of the default tests is kicking up a fuss:

Running phpunit returns:

5) EcomDev_PHPUnitTest_Test_Helper_Customer::testCustomerSession with data set "jane_doe" (2)
Exception: Warning: session_module_name(): A session is active. You cannot change the session module's ini settings at this time  in /var/www/htdocs/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php on line 73

Fatal error: Uncaught exception 'Exception' with message 'Warning: Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct (tcp://tcp://127.0.0.1:11211?persistent=1&weight=2&timeout=10&retry_interval=10)

So far I established that:

  • Memcache seems to be on, and on the correct port
  • The same problem occurs when I set it up to use external (AWS) Memcache service
  • Same thing happens if I set the session to be handled by filesystem

The config for magento's session is:

<session_save><![CDATA[memcache]]></session_save>
<session_save_path><![CDATA[tcp://127.0.0.1:11211?persistent=1&weight;=2&timeout;=10&retry;_interval=10]]></session_save_path>
<session_cache_limiter><![CDATA[private]]></session_cache_limiter>
<lifetime>31536000</lifetime>

And php5-fpm php.ini has

session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211?persistent=1&weight;=2&timeout;=10&retry;_interval=10"
Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50

2 Answers2

0

I answered the wrong question it is kind of related so I will keep it, this is how to resolve

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

As I stumbled upon your questions I am going to awnser how I solve this problem, the case was when I created a test like so:

class Namespace_OrderMigration_Test_Controller_OrderController extends EcomDev_PHPUnit_Test_Case_Controller
{
    public function setUp()
    {
        // do some stuff
    }

    public function testListAction()
    {
        $this->dispatch('migration/order/list');
        $this->assertRequestRoute($route);
    }

}

The issue is that EcomDev_PHPUnit_Test_Case_Controller::setUp() sorts out the cookies and initialises the controller, so make sure you call parent::setUp();.

    public function setUp()
    {
        parent::setUp();
        // do some stuff
    }

Silly mistake I know but the other test cases do not use modify the setUp method, this is not the issue you are seeing. I did get the issue you are seeing and I just mocked the session.

If you still get this issue look @ Cannot send session cookie - headers already sent PHPUnit / Laravel which basically says use @session_start

Community
  • 1
  • 1
jzahedieh
  • 1,570
  • 1
  • 15
  • 27
0

So to attempt answer the original question, I also got this issue when my code was trying to use the normal customer/session.

I fixed (worked around?) it by mocking the session and replacing the singleton instance instead like so:

public function setUp()
{
    parent::setUp();

    $mockSession = $this->getModelMockBuilder('customer/session')
        ->disableOriginalConstructor()
        ->getMock();

    $this->replaceByMock('singleton', 'customer/session', $mockSession);

    /* @var $mockSession PHPUnit_Framework_MockObject_MockObject Stub */
    $mockSession = Mage::getSingleton('customer/session');
    $mockSession->expects($this->atLeastOnce())
        ->method('authenticate')
        ->willReturn(true);

    $mockSession->expects($this->atLeastOnce())
        ->method('getCustomer')
        ->willReturn(Mage::getModel('customer/customer')->setData('email', 'test@test.com'));
}

So that I could call Mage::getSingleton('customer/session')->getCustomer() and it would return my customer model which I could then call getEmail() on.

jzahedieh
  • 1,570
  • 1
  • 15
  • 27