BlackFriday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Adobe Exam AD0-E722 Topic 1 Question 18 Discussion

Actual exam question for Adobe's AD0-E722 exam
Question #: 18
Topic #: 1
[All AD0-E722 Questions]

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?

Show Suggested Answer Hide Answer
Suggested Answer: C

To create an integration test that executes different logic in different store views, the Architect needs to do the following steps:

Create one test class that extends MagentoTestFrameworkTestCaseAbstractController or MagentoTestFrameworkTestCaseAbstractBackendController, depending on the type of controller being tested1.

Create one test method that uses the @magentoDataFixture annotation to specify the data fixture file that creates the product2.

Use the MagentoTestFrameworkStoreExecuteInStoreContext class to execute the fixture and the tested logic in different store views. This class has a method called executeInStoreContext, which takes two parameters: the store ID and a callable function.The callable function will be executed in the context of the given store ID, and then the original store ID will be restored3. For example:

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

Contribute your Thoughts:

Jade
4 months ago
Woohoo, store views! Time to get my integration test groove on. Option B is the way to go, folks. Let's keep it simple and get this done.
upvoted 0 times
Gerry
3 months ago
Let's go with Option B then. It seems like the most efficient way to meet the requirements for the integration test.
upvoted 0 times
...
Breana
3 months ago
Using the annotations in separate test methods will ensure that the product creation and logic execution are done in the context of the correct store views.
upvoted 0 times
...
Stefania
3 months ago
I agree, having one test class with two test methods makes it easier to manage and execute the integration test for different store views.
upvoted 0 times
...
Arminda
4 months ago
Option B is definitely the way to go. Let's keep it simple and use emagentostorecontext 3 and amagentostorecontext 4 in two separate test methods.
upvoted 0 times
...
...
Jordan
4 months ago
I'm with Hui on this one. Option B is the simplest and most elegant solution to the problem.
upvoted 0 times
...
Brinda
4 months ago
Option A seems a bit overkill to me. Creating two separate test classes just for the two store views seems like unnecessary duplication. I'd go with B as well.
upvoted 0 times
Katie
3 months ago
Yeah, creating two separate classes for each store view does seem like overkill. Option B is the way to go.
upvoted 0 times
...
Elouise
3 months ago
I agree, option B seems more efficient. One class with two methods is simpler.
upvoted 0 times
...
...
Hui
5 months ago
Option C looks interesting, but using the ExecuteinstoreContext class directly in the fixture and test might make the code a bit more complex. I'd lean towards B.
upvoted 0 times
Elmer
4 months ago
Yes, it would make the test class more organized and easier to maintain in the long run.
upvoted 0 times
...
Bernardo
4 months ago
I agree, using separate test methods with different annotations seems like a cleaner approach.
upvoted 0 times
...
...
Alyce
5 months ago
I think option B is the way to go. It's clear and straightforward to handle the two different store views.
upvoted 0 times
Lyla
4 months ago
Option B seems like the most efficient way to meet the requirements for the Integration Test.
upvoted 0 times
...
Tayna
4 months ago
I agree, using emagentostorecontext 3 and amagentostorecontext 4 in separate test methods makes it easier to manage.
upvoted 0 times
...
Catina
5 months ago
I think option B is the way to go. It's clear and straightforward to handle the two different store views.
upvoted 0 times
...
...
Mitsue
5 months ago
I agree with Cristal, option A seems like the best approach for meeting the requirements.
upvoted 0 times
...
Cristal
5 months ago
I think the Architect should choose option A.
upvoted 0 times
...

Save Cancel