I'm writing an integration test for Magento 2 where I have to emulate the admin area.
To do so, I use the @magentoAppArea
annotation:
/**
* @magentoAppArea adminhtml
*/
However, some things did not work as expected and I found out that the current store id is set to "1" (default store) instead of "0" (admin store)
Here's a failing test as minimum example:
/**
* @magentoAppArea adminhtml
*/
public function testAdminarea()
{
$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Store\Model\StoreManagerInterface::class);
$this->assertEquals(0, $storeManager->getStore()->getId());
}
How do I set up this test correctly?
What I found during debugging:
Magento\TestFramework\Application::loadArea('adminhtml')
is triggered correctly.The store id is first initialized in
Magento\Store\Model\StoreResolver::getStoresData()
:$cacheKey = 'resolved_stores_' . md5($this->runMode . $this->scopeCode); $cacheData = $this->cache->load($cacheKey);
Where
$this->runMode
is "website" and$this->scopeCode
is "null".