Let's say I have a method in my integration test with annotations like this:
/**
* @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
* @magentoConfigFixture secondstore_store some/config/field 1
**/
When I run the test it fails with:
PHP Fatal error: Uncaught exception
'Magento\Framework\Exception\NoSuchEntityException' with message
'Requested store is not found' in
/var/www/html/magento2/app/code/Magento/Store/Model/StoreRepository.php:60
I think that this is because config fixtures are loaded before data fixtures in dev/tests/integration/framework/Magento/TestFramework/Bootstrap/DocBlock.php and in this case we need data fixture to create the store.
Is there a way to load config fixtures after data fixtures so that stores would be available?
Best Answer
This looks to be impossible for now using annotations mechanism. Even if data fixture is declared on class level it will be executed for every test after config fixture.
The following approach works:
Such approach also makes sense from performance standpoint, because store creation is pretty heavy operation, and now it will be done only once per test case.