diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CatalogPromotionExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CatalogPromotionExampleFactory.php index 3fecdbef3f6..03540565f74 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CatalogPromotionExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/CatalogPromotionExampleFactory.php @@ -40,8 +40,6 @@ class CatalogPromotionExampleFactory extends AbstractExampleFactory implements E private ExampleFactoryInterface $catalogPromotionActionExampleFactory; - private AllProductVariantsCatalogPromotionsProcessorInterface $allProductVariantsCatalogPromotionsProcessor; - private Generator $faker; private OptionsResolver $optionsResolver; @@ -51,15 +49,13 @@ public function __construct( RepositoryInterface $localeRepository, ChannelRepositoryInterface $channelRepository, ExampleFactoryInterface $catalogPromotionScopeExampleFactory, - ExampleFactoryInterface $catalogPromotionActionExampleFactory, - AllProductVariantsCatalogPromotionsProcessorInterface $allProductVariantsCatalogPromotionsProcessor + ExampleFactoryInterface $catalogPromotionActionExampleFactory ) { $this->catalogPromotionFactory = $catalogPromotionFactory; $this->localeRepository = $localeRepository; $this->channelRepository = $channelRepository; $this->catalogPromotionScopeExampleFactory = $catalogPromotionScopeExampleFactory; $this->catalogPromotionActionExampleFactory = $catalogPromotionActionExampleFactory; - $this->allProductVariantsCatalogPromotionsProcessor = $allProductVariantsCatalogPromotionsProcessor; $this->faker = Factory::create(); $this->optionsResolver = new OptionsResolver(); @@ -110,8 +106,6 @@ public function create(array $options = []): CatalogPromotionInterface } } - $this->allProductVariantsCatalogPromotionsProcessor->process(); - return $catalogPromotion; } diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Listener/CatalogPromotionExecutorListener.php b/src/Sylius/Bundle/CoreBundle/Fixture/Listener/CatalogPromotionExecutorListener.php new file mode 100644 index 00000000000..bd611e550dd --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Listener/CatalogPromotionExecutorListener.php @@ -0,0 +1,39 @@ +fixture() instanceof CatalogPromotionFixture) { + $this->allCatalogPromotionsProcessor->process(); + } + } + + public function getName(): string + { + return 'catalog_promotion_processor_executor'; + } +} diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures/promotion.yaml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures/promotion.yaml index 1bfae0e7478..15075bcfef1 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures/promotion.yaml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures/promotion.yaml @@ -4,6 +4,8 @@ sylius_fixtures: suites: default: + listeners: + catalog_promotion_processor_executor: ~ fixtures: promotion: options: diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index cb3a16d38c3..a200a451f63 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -21,6 +21,7 @@ + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml index ae701654731..d43eee5b3b9 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_factories.xml @@ -21,7 +21,6 @@ - diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_listeners.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_listeners.xml new file mode 100644 index 00000000000..b0651707847 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_listeners.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/spec/Fixture/Listener/CatalogPromotionExecutorListenerSpec.php b/src/Sylius/Bundle/CoreBundle/spec/Fixture/Listener/CatalogPromotionExecutorListenerSpec.php new file mode 100644 index 00000000000..d933b649656 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/spec/Fixture/Listener/CatalogPromotionExecutorListenerSpec.php @@ -0,0 +1,61 @@ +beConstructedWith($allCatalogPromotionsProcessor); + } + + function it_implements_listener_interface(): void + { + $this->shouldImplement(ListenerInterface::class); + } + + function it_listens_for_after_fixture_events(): void + { + $this->shouldImplement(AfterFixtureListenerInterface::class); + } + + function it_triggers_catalog_promotion_processing_after_catalog_promotion_fixture_execution( + AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor, + SuiteInterface $suite, + CatalogPromotionFixture $catalogPromotionFixture + ): void { + $this->afterFixture(new FixtureEvent($suite->getWrappedObject(), $catalogPromotionFixture->getWrappedObject(), []), []); + + $allCatalogPromotionsProcessor->process()->shouldBeCalled(); + } + + function it_does_not_trigger_catalog_promotion_processing_after_any_other_fixture_execution( + AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor, + SuiteInterface $suite, + FixtureInterface $fixture + ): void { + $this->afterFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), []), []); + + $allCatalogPromotionsProcessor->process()->shouldNotBeCalled(); + } +}