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 13 Discussion

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

Laticia
4 months ago
That's a valid point, Leslee. It's important to consider the organization and readability of the test code as well.
upvoted 0 times
...
Leslee
4 months ago
I see your point, Myong. But I think option C) Create one test class with one test method might also be a good choice. It keeps everything in one place for easier reference.
upvoted 0 times
...
Myong
4 months ago
Well, having two test methods within one class makes it easier to manage and organize the tests. It's more efficient than creating two separate classes.
upvoted 0 times
...
Laticia
5 months ago
Why do you think that? Can you explain your rationale?
upvoted 0 times
...
Myong
5 months ago
I disagree. I believe the correct answer is B) Create one test class with two test methods.
upvoted 0 times
...
Laticia
5 months ago
I think the answer is A) Create two test classes with one test method each.
upvoted 0 times
...
Thaddeus
5 months ago
I think option C) makes more sense, using the class once in the fixture and another time in the test.
upvoted 0 times
...
Beth
6 months ago
But wouldn't using the annotations on the class level be more organized?
upvoted 0 times
...
Caprice
6 months ago
I disagree, I believe the correct answer is B) Create one test class with two test methods.
upvoted 0 times
...
Beth
6 months ago
I think the answer is A) Create two test classes with one test method each.
upvoted 0 times
...
Merissa
7 months ago
Ah, the joys of Magento testing. I'm with Karrie on this one - option B seems like the cleanest approach. Keep it simple, two test methods, one for each store view. Who needs all that fancy ExecuteInStoreContext nonsense, am I right?
upvoted 0 times
...
Madelyn
7 months ago
Personally, I'd go with option C. Using the ExecuteInStoreContext class directly gives you more control and flexibility, in case the test requirements change down the line. Plus, it keeps everything nicely encapsulated in a single test method.
upvoted 0 times
Olga
6 months ago
Agreed. Having everything in one test method using the ExecuteInStoreContext class seems clean.
upvoted 0 times
...
Paris
6 months ago
Option C sounds like the best approach. It keeps everything simple and easy to follow.
upvoted 0 times
...
...
Heike
7 months ago
Hmm, I'm not sure. Option A with the @magentoExecuteInStoreContext annotations seems like it might be a bit more reusable if we need to test in other store views in the future. But I can see the appeal of keeping it all in one test class.
upvoted 0 times
...
Karrie
7 months ago
I'm leaning towards option B. Creating two test methods, one for each store view, seems like a cleaner approach than having to use the ExecuteInStoreContext class manually. Plus, the annotations make it pretty clear what's happening.
upvoted 0 times
...
Stevie
7 months ago
Oof, Magento testing, that's a whole can of worms. I'd say option C looks the most straightforward - using the ExecuteInStoreContext class to handle the store view switching. But I'm curious to hear what the others think.
upvoted 0 times
...
Moira
7 months ago
Hmm, this seems like a tricky question. I'm not sure I fully understand the context of the Magento test framework and how the store views work. But I think the key is making sure we test the product creation and logic execution in the context of both store views 3 and 4.
upvoted 0 times
...

Save Cancel