tddwizard / magento2-fixtures

Fixture library for Magento 2 integration tests by @schmengler (@integer-net)
http://tddwizard.com/
MIT License
141 stars 28 forks source link

Allow store selection in CategoryBuilder, use default store root category for "top level categories" #44

Open schmengler opened 4 years ago

schmengler commented 4 years ago

We currently use code like this in test cases where no "current store" is set:

        /*
         * A current store is needed to determine root category automatically
         */
        /** @var Emulation $emulation */
        $emulation = $this->objectManager->get(Emulation::class);
        $emulation->startEnvironmentEmulation(1);
        $this->categoryFixture = new CategoryFixture(
            CategoryBuilder::topLevelCategory()->build()
        );
        $emulation->stopEnvironmentEmulation();

Since 0.10.0 the path for "top categories" is always set to "1/2" and category data saved in global scope, independent of the "current store" state, so it won't be necessary anymore.

It would be better to have more control over this, e.g. with a builder factory like

topLevelCategoryInStore($storeId)