Testing Magento with PHPUnit: Problems with Memcache Sessions

We use the EcomDev package to test our Magento store, and one of the tests makes noise by default:

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 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 have established that:

  • Memcache seems to be enabled, and on the correct port
  • The same problem occurs when I install it to use memcache service (AWS)
  • The same thing happens if I establish a session to be processed by the file system

Configuration for the magento session:

<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"
+3
source share
2 answers

I answered the wrong question because it is related to the fact that I will save it, here's 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

, , , , :

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);
    }

}

, EcomDev_PHPUnit_Test_Case_Controller::setUp() cookie , , parent::setUp();.

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

, , setUp, , . , , .

, @ cookie - PHPUnit/Laravel, , @session_start

0

, , customer/session.

( ?), singleton :

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'));
}

Mage::getSingleton('customer/session')->getCustomer(), , getEmail().

0

All Articles