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?
- 
 Can you please post your test?Maddy– Maddy2015年12月15日 19:47:07 +00:00Commented Dec 15, 2015 at 19:47
- 
 @Maddy I don't think it matters because the error appears before any line of the actual test code is executed. Anything can be in the test and it will show the same error.LDusan– LDusan2015年12月16日 06:48:35 +00:00Commented Dec 16, 2015 at 6:48
1 Answer 1
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:
<?php
namespace VendorName\ModuleName\Model;
class SomeTest extends \PHPUnit_Framework_TestCase
{
 public static function setUpBeforeClass()
 {
 require realpath(TESTS_TEMP_DIR . '/../testsuite/Magento/Store/_files/core_fixturestore.php');
 parent::setUpBeforeClass();
 }
 public static function tearDownAfterClass()
 {
 /** Teardown is necessary because this fixture was committed to DB in setUpBeforeClass */
 require realpath(TESTS_TEMP_DIR . '/../testsuite/Magento/Store/_files/core_fixturestore_rollback.php');
 parent::setUpBeforeClass();
 }
 /**
 * @magentoConfigFixture fixturestore some/config/field 1
 **/
 public function testSomething()
 {
 /** Test content */
 }
}
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.
- 
 Thanks that sounded like a nice solution but unfortunately it didn't work for me.LDusan– LDusan2015年12月16日 19:26:45 +00:00Commented Dec 16, 2015 at 19:26
- 
 @LDusan see updated responseAlex Paliarush– Alex Paliarush2015年12月17日 10:01:04 +00:00Commented Dec 17, 2015 at 10:01
- 
 1I assume the function tearDownAfterClass should use the parent call tearDownAfterClass. But thanks, I have now the rollback feature workingHerve Tribouilloy– Herve Tribouilloy2018年11月12日 14:25:39 +00:00Commented Nov 12, 2018 at 14:25
Explore related questions
See similar questions with these tags.