An Architect wants to create an Integration Test that does the following:
* Adds a product using a data fixture
* Executes $this->someLogic->execute($product) on the product
* Checks if the result is true.
$this->someLogic has the correct object assigned in the setup() method.
Product creation and the tested logic must be executed in the context of two different store views with IDs of 3 and 4, which have been created and are available for the test.
How should the Architect meet these requirements?
To create an integration test that executes different logic in different store views, the Architect needs to do the following steps:
PHPAI-generated code. Review and use carefully.More info on FAQ.
public function testSomeLogic()
{
// Get the product from the fixture
$product = $this->getProduct();
// Get the ExecuteInStoreContext instance from the object manager
$executeInStoreContext = $this->_objectManager->get(MagentoTestFrameworkStoreExecuteInStoreContext::class);
// Execute the fixture in store view 3
$executeInStoreContext->executeInStoreContext(3, function () use ($product) {
// Do some operations on the product in store view 3
});
// Execute the tested logic in store view 4
$result = $executeInStoreContext->executeInStoreContext(4, function () use ($product) {
// Call the tested logic on the product in store view 4
return $this->someLogic->execute($product);
});
// Assert that the result is true
$this->assertTrue($result);
}
Integration tests | Magento 2 Developer Documentation
Data fixtures | Magento 2 Developer Documentation
MagentoTestFrameworkStoreExecuteInStoreContext | Magento 2 Developer Documentation
Temeka
2 months agoGracia
2 months agoRonald
10 days agoLenny
17 days agoCyndy
18 days agoEvangelina
20 days agoSean
1 months agoShawn
1 months agoTamesha
1 months agoAdelina
2 months agoKathrine
2 months agoShannon
1 months agoKathryn
1 months agoBritt
1 months agoAhmad
2 months agoLatia
3 months agoGaston
1 months agoWade
1 months agoMoon
2 months agoTayna
3 months agoKara
3 months agoJackie
3 months agoLashandra
3 months agoPaul
3 months ago