BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Adobe AD0-E722 Exam - Topic 1 Question 5 Discussion

Posted by Rima on Nov 22, 2023 at 11:40 AM

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?

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

Get Premium AD0-E722 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
18 comments · newest first
FR
Francine 12 months ago
Totally agree with B, it's straightforward and clean!
VI
Vilma 1 year ago
Wait, can you really use the same context in one method?
CE
Ceola 1 year ago
C sounds a bit confusing, not sure it meets all requirements.
KR
Kris 1 year ago
I think A is better for clarity with separate classes.
BE
Bernardo 1 year ago
Option B seems like the most efficient way to handle this.
GO
Golda 1 year ago
I vaguely remember something about using the ExecuteInStoreContext class, but I thought it was more common to use it in separate methods rather than just once.
SH
Shawna 1 year ago
I feel like option B might be the right approach since it allows for clearer separation of the test methods, but I’m not completely confident.
EL
Eleni 1 year ago
I remember practicing a question where we had to use annotations for different store contexts, but I can't recall if it was one class or two.
MA
Maurine 1 year ago
I think option A sounds familiar, but I'm not entirely sure if we need separate classes for each store view.
RO
Roxane 1 year ago
I'm feeling pretty confident about this one. The key is to use the appropriate Magento testing framework classes and annotations to set up the store view context. I'll create a single test class with one method, and use the \Magento\TestFramework\Store\ExecuteInStoreContext class to handle the store view switching in the test.
NO
Noah 1 year ago
This seems a bit tricky with the multiple store view requirement. I'm thinking I might need to create two separate test classes, one for each store view, and use the @magentoExecuteInStoreContext annotation at the class level. That way, I can keep the test logic separate and ensure it runs in the correct context.
YA
Yaeko 1 year ago
Okay, I've got a plan. I'll create a single test class with two test methods, and use the @magentoStoreContext annotation to specify the store view ID in each method. That should cover the requirement to test in both store views.
MY
Myra 1 year ago
Hmm, I'm a bit unsure about the different store view IDs and how to properly set up the test context. I'll need to review the Magento testing framework documentation to make sure I understand the right approach here.
TR
Trinidad 1 year ago
This looks like a straightforward integration test setup. I think I can handle this - the key is to use the appropriate annotations to execute the test logic in the correct store view context.
LO
Louisa 1 year ago
I've got this! Case and Account are definitely going to be on the list. And since this is a support use case, Contract is a good choice too. I'm feeling confident about this one.
HY
Hyman 1 year ago
Based on the information provided, I believe the core file will be stored in the non-global zone's directory, as specified in the core dump configuration image.
AR
Arlette 1 year ago
Hmm, I'm not totally sure about this one. I'm thinking it could also be related to service discoverability, since hiding those implementation details could make it easier for consumers to find and use the service. But I'm not 100% confident.
BE
Bettyann 1 year ago
I might be mixing up some concepts, but I feel like there's definitely a range in how much miners can influence timestamps.
0/2000 characters

Save Cancel