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 4 Question 29 Discussion

Actual exam question for Adobe's AD0-E722 exam
Question #: 29
Topic #: 4
[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:

Temeka
17 days ago
What, no 'Magento' in the annotations? These developers are really testing the limits of creativity, aren't they?
upvoted 0 times
...
Gracia
19 days ago
Interesting. I'm leaning towards option A - creating two test classes with one method each. That way, the test setup and execution are neatly separated for each store view.
upvoted 0 times
Shawn
2 days ago
User 2: Definitely, it keeps things organized and ensures clarity in the testing process.
upvoted 0 times
...
Tamesha
10 days ago
I agree, having separate test classes for each store view makes it easier to manage.
upvoted 0 times
...
...
Adelina
1 months ago
I see both points, but I think option C is the way to go. Using the ExecuteinstoreContext class in both fixture and test seems logical to me.
upvoted 0 times
...
Kathrine
1 months ago
Ha! Looks like the Architect is trying to cover all the bases. I'd go with option C - using the ExecuteInStoreContext class twice should do the trick.
upvoted 0 times
Shannon
2 days ago
I see your point, but I still think option C is the best choice. Reusing the ExecuteInStoreContext class in both the fixture and the test method ensures consistency.
upvoted 0 times
...
Kathryn
8 days ago
I disagree, option B is more concise. Using emagentostorecontext 3 and amagentostorecontext 4 directly in the test methods is simpler.
upvoted 0 times
...
Britt
9 days ago
I think option A is the way to go. Using the @magentoExecuteinstoreContext annotations on the class level seems like the most organized approach.
upvoted 0 times
...
...
Ahmad
1 months ago
I disagree, I believe option B is better. Having one test class with two test methods is more efficient.
upvoted 0 times
...
Latia
2 months ago
Hmm, I'm not sure about that. Won't we need to create the product in the fixture and then test the logic in each store view? Option C looks more comprehensive.
upvoted 0 times
Gaston
9 days ago
Let's go with option C then.
upvoted 0 times
...
Wade
13 days ago
I agree, using the \Magento\TestFramework\store\ExecuteinstoreContext class in both the fixture and the test method seems like the right approach.
upvoted 0 times
...
Moon
1 months ago
Option C looks more comprehensive.
upvoted 0 times
...
Tayna
1 months ago
I think we need to create the product in the fixture and then test the logic in each store view.
upvoted 0 times
...
...
Kara
2 months ago
I think option A is the correct approach. It makes sense to have two test classes for two different store views.
upvoted 0 times
...
Jackie
2 months ago
Okay, this seems straightforward. I think option B is the way to go - create one test class with two methods, each using a different store view context.
upvoted 0 times
Lashandra
2 months ago
Yes, using one test class with two methods, each specifying a different store view context, is the best approach.
upvoted 0 times
...
Paul
2 months ago
I agree, option B is the most efficient way to meet the requirements.
upvoted 0 times
...
...

Save Cancel