Skip to content

Commit

Permalink
[API] Remove catalog promotion created event, replace with catalog pr…
Browse files Browse the repository at this point in the history
…omotion rule
  • Loading branch information
SirDomin committed Sep 21, 2021
1 parent c83f6ee commit b2f86a2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Feature: Creating a catalog promotion
When I create a new catalog promotion with "winter_sale" code and "Winter sale" name
Then there should be 1 new catalog promotion on the list
And it should have "winter_sale" code and "Winter sale" name
And this catalog promotion should be usable

@api @ui @javascript
Scenario: Creating a catalog promotion
Expand Down Expand Up @@ -44,4 +43,3 @@ Feature: Creating a catalog promotion
Then there should be 1 new catalog promotion on the list
And it should have "winter_sale" code and "Winter sale" name
And the catalog promotion "Winter sale" should be available in channel "United States"
And this catalog promotion should be usable
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Sylius\Component\Core\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Promotion\Event\CatalogPromotionCreated;
use Sylius\Component\Promotion\Event\CatalogPromotionUpdated;
use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface;
use Symfony\Component\Messenger\MessageBusInterface;
Expand Down Expand Up @@ -481,10 +480,7 @@ public function itShouldHaveRule(ProductVariantInterface $firstVariant, ProductV
*/
public function thisCatalogPromotionShouldBeUsable(): void
{
Assert::oneOf(
get_class($this->messageBus->getDispatchedMessages()[0]['message']),
[CatalogPromotionCreated::class, CatalogPromotionUpdated::class]
);
Assert::isInstanceOf($this->messageBus->getDispatchedMessages()[0]['message'], CatalogPromotionUpdated::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Doctrine\Persistence\Event\LifecycleEventArgs;
use Sylius\Component\Core\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Promotion\Event\CatalogPromotionCreated;
use Sylius\Component\Promotion\Event\CatalogPromotionUpdated;
use Sylius\Component\Promotion\Model\CatalogPromotionInterface;
use Symfony\Component\Messenger\MessageBusInterface;
Expand All @@ -33,10 +32,6 @@ public function postPersist(LifecycleEventArgs $args): void
{
$entity = $args->getObject();

if ($entity instanceof CatalogPromotionInterface) {
$this->eventBus->dispatch(new CatalogPromotionCreated($entity->getCode()));
}

if ($entity instanceof CatalogPromotionRuleInterface) {
$this->eventBus->dispatch(new CatalogPromotionUpdated($entity->getCatalogPromotion()->getCode()));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@
<tag name="doctrine.event_listener" event="postUpdate" connection="default" />
</service>

<service id="Sylius\Bundle\CoreBundle\Listener\CatalogPromotionCreateListener">
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\CatalogPromotionProcessorInterface" />
<argument type="service" id="sylius.repository.catalog_promotion" />
<tag name="messenger.message_handler" bus="sylius.event_bus" />
</service>

<service id="Sylius\Bundle\CoreBundle\Listener\CatalogPromotionUpdateListener">
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\CatalogPromotionClearerInterface" />
<argument type="service" id="Sylius\Bundle\CoreBundle\Processor\CatalogPromotionProcessorInterface" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\CoreBundle\EventListener\CatalogPromotionEventListener;
use Sylius\Component\Promotion\Event\CatalogPromotionCreated;
use Sylius\Component\Core\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Promotion\Event\CatalogPromotionUpdated;
use Sylius\Component\Promotion\Model\CatalogPromotionInterface;
use Symfony\Component\Messenger\Envelope;
Expand All @@ -35,26 +35,28 @@ function it_is_initializable(): void
$this->shouldHaveType(CatalogPromotionEventListener::class);
}

function it_sends_catalog_promotion_created_after_persisting_catalog_promotion(
function it_does_not_send_catalog_promotion_updated_after_persisting_other_entity(
MessageBusInterface $eventBus,
LifecycleEventArgs $args,
CatalogPromotionInterface $entity
LifecycleEventArgs $args
): void {
$args->getObject()->willReturn($entity);
$entity->getCode()->willReturn('winter_sale');

$message = new CatalogPromotionCreated('winter_sale');
$eventBus->dispatch($message)->willReturn(new Envelope($message))->shouldBeCalled();
$args->getObject()->willReturn(new \stdClass());
$eventBus->dispatch(Argument::any())->shouldNotBeCalled();

$this->postPersist($args);
}

function it_does_not_send_catalog_promotion_updated_after_persisting_other_entity(
function it_sends_catalog_promotion_updated_after_persisting_catalog_promotion_rule(
MessageBusInterface $eventBus,
LifecycleEventArgs $args
LifecycleEventArgs $args,
CatalogPromotionRuleInterface $entity,
CatalogPromotionInterface $catalogPromotion
): void {
$args->getObject()->willReturn(new \stdClass());
$eventBus->dispatch(Argument::any())->shouldNotBeCalled();
$args->getObject()->willReturn($entity);
$entity->getCatalogPromotion()->willReturn($catalogPromotion);
$catalogPromotion->getCode()->willReturn('winter_sale');

$message = new CatalogPromotionUpdated('winter_sale');
$eventBus->dispatch($message)->willReturn(new Envelope($message))->shouldBeCalled();

$this->postPersist($args);
}
Expand All @@ -72,4 +74,20 @@ function it_sends_catalog_promotion_updated_after_updating_catalog_promotion(

$this->postUpdate($args);
}

function it_sends_catalog_promotion_updated_after_updating_catalog_promotion_rule(
MessageBusInterface $eventBus,
LifecycleEventArgs $args,
CatalogPromotionRuleInterface $entity,
CatalogPromotionInterface $catalogPromotion
): void {
$args->getObject()->willReturn($entity);
$entity->getCatalogPromotion()->willReturn($catalogPromotion);
$catalogPromotion->getCode()->willReturn('winter_sale');

$message = new CatalogPromotionUpdated('winter_sale');
$eventBus->dispatch($message)->willReturn(new Envelope($message))->shouldBeCalled();

$this->postUpdate($args);
}
}

This file was deleted.

24 changes: 0 additions & 24 deletions src/Sylius/Component/Promotion/Event/CatalogPromotionCreated.php

This file was deleted.

0 comments on commit b2f86a2

Please sign in to comment.