Cannot get singleton session in EcomDev PHPUnit test

After some serious debugging that I discovered, I can’t call to get a session object in Magento when running a test with the EcomDev_PHPUnit module

any singleton / model call, i.e. Mage::getSingleton('admin/session')or Mage::getModel('customer/session')ultimately throws an exception from EcomDev_PHPUnit_Controller_Request_Http::getHttpHost()saying Cannot run controller test, because the host is not set for base url.that it is caused by the fact that the index is $_SERVER['HTTP_HOST']not set

Is there anything in the configuration that I could lose to cause this?

+5
source share
2 answers

, Magento, Magento. , -, Magento, php.

, EcomDev_PHPUnit_Test_Case.

$sessionMock = $this->getModelMockBuilder('admin/session')
        ->disableOriginalConstructor() // This one removes session_start and other methods usage
        ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
        ->getMock();
$this->replaceByMock('singleton', 'admin/session', $sessionMock);
+13

phpunit.xml

<phpunit ....>
    ...
    <php>
        <server name='HTTP_HOST' value='http://local.mysite.com' />
    </php>
</phpunit>
0

All Articles