QuestionQ20

Store Operations and Admin

An Architect needs to create an Integration Test that does the following:

  • Adds a product through a data fixture.
  • Runs $this->someLogic->execute($product) on the product.
  • Verifies that the result is true.

$this->someLogic has the proper object assigned in the setUp() method.

Product creation and the tested logic must run in the contexts of two distinct store views, with IDs 3 and 4, which have been created and are available for the test. How should the Architect satisfy these requirements?

  • A Create one test class with one test method. Use the \Magento\TestFramework\Store\ExecuteInStoreContext class once in the fixture and another time in the test.
  • B Create two test classes with one test method each. Use the @magentoExecuteInStoreContext 3 and @magentoExecuteInStoreContext 4 annotations on the class level.
  • C Create one test class with two test methods. Use the @magentoStoreContext 3 annotation in one method and @magentoStoreContext 4 in the other one.
Explanation

\Magento\TestFramework\Store\ExecuteInStoreContext::execute() runs a callback with the specified store set as the current store and restores the original store afterward. Wrapping product creation in the fixture for one store view and wrapping the tested logic in the test for the other store view satisfies both store-context requirements while retaining one coherent test method.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!