I'm currently experiencing a weird issue. I've written a bunch of integration tests, and it is my understanding that I can use the @magentoDbIsolation
annotation to isolate my database transactions during a test (documentation).
However, I am currently in a situation where my test passes when @magentoDbIsolation
is disabled, but it fails when @magentoDbIsolation
is enabled. I'm asserting the actual data in the database to check if the product repository has written everything correct. The test:
/**
* @throws \Exception
* @magentoDbIsolation enabled
*/
public function testDifferentValuesForDifferentStores()
{
// Create default product:
$importValue = $this->createImportValue('abc', ['name' => 'Name', 'price' => 9.95, 'description' => 'Foo']);
$this->productLoader->importSingle($importValue);
// Create import values for every store code:
$stores = $this->storeManager->getStores();
foreach ($stores as $store) {
// Only the name differs per store:
$importValue = $this->createImportValue('abc', [
'name' => "Name ({$store->getCode()})",
'price' => 9.95
]);
$importValue->setStoreCode($store->getCode());
$this->productLoader->importSingle($importValue);
}
// Check if the values differ:
foreach ($stores as $store) {
$product = $this->productRepository->get('abc', false, $store->getId());
$this->assertEquals("Name ({$store->getCode()})", $product->getName());
// Check if there are no stupid duplicates stored:
// Should be one, since only the name differs:
// This assertion passes when dbIsolation is disabled, but fails when it's enabled
$this->assertEquals(1, $this->resource->getConnection()->fetchOne(
'SELECT COUNT(*) FROM `catalog_product_entity_varchar` WHERE `store_id` = ' . $store->getId() .
' AND attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = \'name\' AND entity_type_id = 4)'
));
}
}
Now the code that handles the importing does nothing fancy. It extracts the values from my import object, creates a product and saves it in the repository. It does this in an emulated environment, but I've also tested without this but the test still fails.
Does anyone has a clue what might be going on here? Are there specific situations where the @magentoDbIsolation
can trigger specific gotcha's that you should be aware of?