Cyber Monday 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
2 months ago
What, no 'Magento' in the annotations? These developers are really testing the limits of creativity, aren't they?
upvoted 0 times
...
Gracia
2 months 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
Ronald
10 days ago
Yeah, I think having one test method for each store view in separate classes is the way to go.
upvoted 0 times
...
Lenny
17 days ago
I see your point, having separate test classes would definitely make it easier to manage.
upvoted 0 times
...
Cyndy
18 days ago
I think option B could work too, but having separate test classes might be clearer.
upvoted 0 times
...
Evangelina
20 days ago
I agree with you, option A seems like the best approach for keeping things organized.
upvoted 0 times
...
Sean
1 months ago
Shawn: Plus, using the annotations on the class level helps in clearly defining the context for each test.
upvoted 0 times
...
Shawn
1 months ago
User 2: Definitely, it keeps things organized and ensures clarity in the testing process.
upvoted 0 times
...
Tamesha
1 months ago
I agree, having separate test classes for each store view makes it easier to manage.
upvoted 0 times
...
...
Adelina
2 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
2 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
1 months 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
1 months 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
1 months 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
2 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
3 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
1 months ago
Let's go with option C then.
upvoted 0 times
...
Wade
1 months 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
2 months ago
Option C looks more comprehensive.
upvoted 0 times
...
Tayna
3 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
3 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
3 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
3 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
3 months ago
I agree, option B is the most efficient way to meet the requirements.
upvoted 0 times
...
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77