2014-01-31 12 views
3

我們使用EcomDev軟件來測試我們的Magento的店,默認測試的一個問題是惹得大驚小怪:測試Magento的PHPUnit的:用Memcache的會議

運行PHPUnit的回報:

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) 

到目前爲止,我確定了:

  • Memcache的似乎是,和正確的端口
  • 上發生時,I S同樣的問題等它使用外部(AWS)內存緩存服務
  • 如果我設置會話由文件系統

爲Magento的會話配置處理

  • 同樣的事情發生是:

    <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> 
    

    而且php5- FPM php.ini中有

    session.save_handler = memcache 
    session.save_path = "tcp://127.0.0.1:11211?persistent=1&weight;=2&timeout;=10&retry;_interval=10" 
    
  • 回答

    0

    我回答錯誤的問題它是一種相關,所以我會保持它,這是如何解決

    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

    當我偶然發現了你的問題,我要awnser我如何解決這個問題,該案時,我創建了像這樣一個測試:

    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()整理cookies並初始化控制器,因此請確保您致電parent::setUp();

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

    愚蠢的錯誤,但我知道其他的測試案例不使用修改setUp方法,這是不是你所看到的問題。我確實遇到了你所看到的問題,並且我只是嘲笑了會議。

    如果你還碰到這個問題看@Cannot send session cookie - headers already sent PHPUnit/Laravel這基本上是說使用@session_start

    0

    所以試圖回答原來的問題,我也有,當我的代碼試圖用正常customer/session這個問題。

    我固定的(工作圍繞?)它通過嘲笑會話和更換單個實例,而不是像這樣:

    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', '[email protected]')); 
    } 
    

    ,這樣我可以稱之爲Mage::getSingleton('customer/session')->getCustomer(),它會回到我的客戶模型,我可以然後致電getEmail()