Skip to content

Commit

Permalink
[Cart] Dispatch CartPickedUp after doctrine transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel committed Oct 30, 2019
1 parent c684c4d commit 17297cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion spec/Handler/Cart/PickupCartHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\ShopApiPlugin\Handler\Cart\PickupCartHandler;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;

final class PickupCartHandlerSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -66,7 +67,7 @@ function it_handles_cart_pickup_for_not_logged_in_user(

$cartPickedUp = new CartPickedUp('ORDERTOKEN');

$eventBus->dispatch($cartPickedUp)->willReturn(new Envelope($cartPickedUp))->shouldBeCalled();
$eventBus->dispatch($cartPickedUp, [new DispatchAfterCurrentBusStamp()])->willReturn(new Envelope($cartPickedUp))->shouldBeCalled();

$this(new PickupCart('ORDERTOKEN', 'CHANNEL_CODE'));
}
Expand Down
3 changes: 2 additions & 1 deletion src/Handler/Cart/PickupCartHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sylius\ShopApiPlugin\Command\Cart\PickupCart;
use Sylius\ShopApiPlugin\Event\CartPickedUp;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
use Webmozart\Assert\Assert;

final class PickupCartHandler
Expand Down Expand Up @@ -56,6 +57,6 @@ public function __invoke(PickupCart $pickupCart): void

$this->cartRepository->add($cart);

$this->eventBus->dispatch(new CartPickedUp($pickupCart->orderToken()));
$this->eventBus->dispatch(new CartPickedUp($pickupCart->orderToken()), [new DispatchAfterCurrentBusStamp()]);
}
}
1 change: 1 addition & 0 deletions src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ framework:
sylius_shop_api_plugin.command_bus:
middleware:
- doctrine_transaction
- messenger.middleware.dispatch_after_current_bus
sylius_shop_api_plugin.event_bus:
default_middleware: allow_no_handlers

Expand Down
5 changes: 5 additions & 0 deletions tests/Controller/Checkout/CompleteOrderApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public function it_allows_to_complete_checkout(): void
}
JSON;

$this->client->enableProfiler();

$response = $this->complete($token, $data);
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);

$mailCollector = $this->client->getProfile()->getCollector('swiftmailer');
$this->assertSame(1, $mailCollector->getMessageCount());
}

/**
Expand Down

0 comments on commit 17297cf

Please sign in to comment.