-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Catalog Promotion] Move catalog promotion processing after the fixtu…
…re execution
- Loading branch information
1 parent
66ab195
commit ee3a2da
Showing
7 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Sylius/Bundle/CoreBundle/Fixture/Listener/CatalogPromotionExecutorListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\Fixture\Listener; | ||
|
||
use Sylius\Bundle\CoreBundle\Fixture\CatalogPromotionFixture; | ||
use Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface; | ||
use Sylius\Bundle\FixturesBundle\Listener\AbstractListener; | ||
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface; | ||
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent; | ||
|
||
final class CatalogPromotionExecutorListener extends AbstractListener implements AfterFixtureListenerInterface | ||
{ | ||
public function __construct(private AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor) | ||
{ | ||
} | ||
|
||
public function afterFixture(FixtureEvent $fixtureEvent, array $options): void | ||
{ | ||
if ($fixtureEvent->fixture() instanceof CatalogPromotionFixture) { | ||
$this->allCatalogPromotionsProcessor->process(); | ||
} | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'catalog_promotion_processor_executor'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Sylius/Bundle/CoreBundle/Resources/config/services/fixtures_listeners.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<defaults public="true" /> | ||
|
||
<service id="sylius_fixtures.listener.catalog_promotion_executor" class="Sylius\Bundle\CoreBundle\Fixture\Listener\CatalogPromotionExecutorListener" public="false"> | ||
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface" /> | ||
<tag name="sylius_fixtures.listener" /> | ||
</service> | ||
</services> | ||
</container> |
61 changes: 61 additions & 0 deletions
61
src/Sylius/Bundle/CoreBundle/spec/Fixture/Listener/CatalogPromotionExecutorListenerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Bundle\CoreBundle\Fixture\Listener; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\CoreBundle\Fixture\CatalogPromotionFixture; | ||
use Sylius\Bundle\CoreBundle\Processor\AllProductVariantsCatalogPromotionsProcessorInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface; | ||
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent; | ||
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface; | ||
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface; | ||
|
||
final class CatalogPromotionExecutorListenerSpec extends ObjectBehavior | ||
{ | ||
function let(AllProductVariantsCatalogPromotionsProcessorInterface $allCatalogPromotionsProcessor): void | ||
{ | ||
$this->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(); | ||
} | ||
} |