QuestionQ23

VerifiedUtilize Commerce test frameworks throughout the whole workflow

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

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

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

Product creation and the logic being tested must run in the contexts of two separate store views, with IDs 3 and 4, which have already been created and are available for the test.

How should the Architect satisfy these requirements?

Explanation

Magento\TestFramework\Store\ExecuteInStoreContext::execute() temporarily sets the specified store as the current store while it invokes a callback, then restores the original store. Using it in the fixture for store view 3 and in the test for store view 4 ensures that product creation and the tested logic execute in their required store contexts within a single test.

Learn more

Community Discussion

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