Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] Switch to Symfony Messenger #419

Merged
merged 3 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ The latest documentation is available [here](https://app.swaggerhub.com/apis/Syl
{
return array_merge(parent::registerBundles(), [
new \Sylius\ShopApiPlugin\ShopApiPlugin(),
new \League\Tactician\Bundle\TacticianBundle(),
]);
}
```
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* The requests have been moved to the appropriate directories depending on the context.
* The views have been moved to the appropriate directories depending on the context.
* This might require changing the serializer settings in your application
* Tactician has been replaced with Symfony Messenger.
* Used `League\Tactician\CommandBus` has been replaced with `Symfony\Component\Messenger\MessageBusInterface`
* The commands are now dispatched using `dispatch()` method instead of `handle()`
* The method name in handlers has been changed from `handle()` to `__invoke()`

# UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"php": "^7.2",

"sylius/sylius": "^1.3",
"league/tactician-bundle": "^1.1",
"league/tactician-doctrine": "^1.1"
"symfony/messenger": "^4.2"
},
"require-dev": {
"lchrusciel/api-test-case": "^3.1",
Expand All @@ -21,10 +20,10 @@
"phpunit/phpunit": "^6.5",
"sensiolabs/security-checker": "^5.0",
"sylius-labs/coding-standard": "^2.0",
"symfony/debug-bundle": "^3.4|^4.1",
"symfony/dotenv": "^3.4|^4.1",
"symfony/web-profiler-bundle": "^3.4|^4.1",
"symfony/web-server-bundle": "^3.4|^4.1"
"symfony/debug-bundle": "^4.1",
"symfony/dotenv": "^4.1",
"symfony/web-profiler-bundle": "^4.1",
"symfony/web-server-bundle": "^4.1"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 9 additions & 5 deletions spec/EventListener/UserRegistrationListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace spec\Sylius\ShopApiPlugin\EventListener;

use Doctrine\Common\Persistence\ObjectManager;
use League\Tactician\CommandBus;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand All @@ -14,11 +13,13 @@
use Sylius\ShopApiPlugin\Command\Customer\GenerateVerificationToken;
use Sylius\ShopApiPlugin\Command\Customer\SendVerificationToken;
use Sylius\ShopApiPlugin\Event\CustomerRegistered;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

final class UserRegistrationListenerSpec extends ObjectBehavior
{
function let(
CommandBus $bus,
MessageBusInterface $bus,
ChannelRepositoryInterface $channelRepository,
UserRepositoryInterface $userRepository,
ObjectManager $userManager
Expand All @@ -27,16 +28,19 @@ function let(
}

function it_generates_and_sends_verification_token_if_channel_requires_verification(
CommandBus $bus,
MessageBusInterface $bus,
ChannelRepositoryInterface $channelRepository,
ChannelInterface $channel
): void {
$channelRepository->findOneByCode('WEB_GB')->willReturn($channel);

$channel->isAccountVerificationRequired()->willReturn(true);

$bus->handle(new GenerateVerificationToken('shop@example.com'))->shouldBeCalled();
$bus->handle(new SendVerificationToken('shop@example.com', 'WEB_GB'))->shouldBeCalled();
$firstCommand = new GenerateVerificationToken('shop@example.com');
$bus->dispatch($firstCommand)->willReturn(new Envelope($firstCommand))->shouldBeCalled();

$secondCommand = new SendVerificationToken('shop@example.com', 'WEB_GB');
$bus->dispatch($secondCommand)->willReturn(new Envelope($secondCommand))->shouldBeCalled();

$this->handleUserVerification(new CustomerRegistered(
'shop@example.com',
Expand Down
8 changes: 4 additions & 4 deletions spec/Handler/AddressBook/CreateAddressHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function it_creates_new_address_for_current_user(
$customer->addAddress($address)->shouldBeCalled();
$addressRepository->add($address)->shouldBeCalled();

$this->handle(new CreateAddress(Address::createFromArray([
$this(new CreateAddress(Address::createFromArray([
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
'city' => 'London',
Expand Down Expand Up @@ -105,7 +105,7 @@ function it_creates_new_address_with_province_for_current_user(

$addressRepository->add($address)->shouldBeCalled();

$this->handle(new CreateAddress(Address::createFromArray([
$this(new CreateAddress(Address::createFromArray([
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
'city' => 'London',
Expand All @@ -126,7 +126,7 @@ function it_throws_exception_if_country_code_is_invalid(
$customerRepository->findOneBy(['email' => 'jure@locastic.com'])->willReturn($customer);
$countryRepository->findOneBy(['code' => 'WRONG_COUNTRY_CODE'])->willReturn(null);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [new CreateAddress(Address::createFromArray([
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [new CreateAddress(Address::createFromArray([
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
'city' => 'London',
Expand Down Expand Up @@ -171,7 +171,7 @@ function it_throws_exception_if_province_code_is_invalid(

$addressRepository->add($address)->shouldNotBeCalled();

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [new CreateAddress(Address::createFromArray([
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [new CreateAddress(Address::createFromArray([
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
'city' => 'London',
Expand Down
2 changes: 1 addition & 1 deletion spec/Handler/AddressBook/RemoveAddressHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ function it_removes_address_from_address_book(

$addressRepository->remove($address)->shouldBeCalled();

$this->handle(new RemoveAddress('ADDRESS_ID', 'user@email.com'));
$this(new RemoveAddress('ADDRESS_ID', 'user@email.com'));
}
}
6 changes: 3 additions & 3 deletions spec/Handler/AddressBook/SetDefaultAddressHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function it_handles_setting_default_address_for_user(

$customer->setDefaultAddress($address)->shouldBeCalled();

$this->handle(new SetDefaultAddress(1, 'user@email.com'));
$this(new SetDefaultAddress(1, 'user@email.com'));
}

function it_throws_exception_if_address_does_not_belong_to_current_user(
Expand All @@ -65,7 +65,7 @@ function it_throws_exception_if_address_does_not_belong_to_current_user(
$customer->getId()->willReturn('CUSTOMER_ID');
$anotherCustomer->getId()->willReturn('ANOTHER_CUSTOMER_ID');

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new SetDefaultAddress(1, 'user@email.com'),
]);
}
Expand All @@ -83,7 +83,7 @@ function it_throws_exception_if_address_is_not_associated_with_any_user(

$user->getCustomer()->shouldNotBeCalled();

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new SetDefaultAddress(1, 'user@email.com'),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function it_updates_address(

$addressRepository->add($address)->shouldBeCalled();

$this->handle(new UpdateAddress(Address::createFromArray([
$this(new UpdateAddress(Address::createFromArray([
'id' => 'ADDRESS_ID',
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
Expand Down Expand Up @@ -107,7 +107,7 @@ function it_throws_an_exception_if_current_user_is_not_address_owner(

$addressRepository->add($address)->shouldNotBeCalled();

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [new UpdateAddress(Address::createFromArray([
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [new UpdateAddress(Address::createFromArray([
'id' => 'ADDRESS_ID',
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
Expand Down Expand Up @@ -141,7 +141,7 @@ function it_throws_an_exception_if_country_does_not_exists(

$addressRepository->add($address)->shouldNotBeCalled();

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [new UpdateAddress(Address::createFromArray([
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [new UpdateAddress(Address::createFromArray([
'id' => 'ADDRESS_ID',
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
Expand Down Expand Up @@ -193,7 +193,7 @@ function it_throws_an_exception_if_province_code_does_not_exists(
$address->setProvinceName(null)->shouldNotBeCalled();
$addressRepository->add($address)->shouldNotBeCalled();

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [new UpdateAddress(Address::createFromArray([
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [new UpdateAddress(Address::createFromArray([
'id' => 'ADDRESS_ID',
'firstName' => 'Sherlock',
'lastName' => 'Holmes',
Expand Down
8 changes: 4 additions & 4 deletions spec/Handler/Cart/AddCouponHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ function it_handles_adding_coupon_to_cart(
$order->setPromotionCoupon($coupon)->shouldBeCalled();
$orderProcessor->process($order)->shouldBeCalled();

$this->handle(new AddCoupon('ORDERTOKEN', 'COUPON_CODE'));
$this(new AddCoupon('ORDERTOKEN', 'COUPON_CODE'));
}

function it_throws_an_exception_if_order_does_not_exist(
OrderRepositoryInterface $orderRepository
): void {
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn(null);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new AddCoupon('ORDERTOKEN', 'COUPON_CODE'),
]);
}
Expand All @@ -72,7 +72,7 @@ function it_throws_an_exception_if_coupon_does_not_exist(
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($order);
$couponRepository->findOneBy(['code' => 'COUPON_CODE'])->willReturn(null);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new AddCoupon('ORDERTOKEN', 'COUPON_CODE'),
]);
}
Expand All @@ -89,7 +89,7 @@ function it_throws_an_exception_if_order_is_not_eligible_for_coupon(

$couponEligibilityChecker->isEligible($order, $coupon)->willReturn(false);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new AddCoupon('ORDERTOKEN', 'COUPON_CODE'),
]);
}
Expand Down
8 changes: 4 additions & 4 deletions spec/Handler/Cart/AddressOrderHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function it_handles_order_shipment_addressing(
$stateMachine->can('address')->willReturn(true);
$stateMachine->apply('address')->shouldBeCalled();

$this->handle(new AddressShipmentCommand(
$this(new AddressShipmentCommand(
'ORDERTOKEN',
Address::createFromArray([
'firstName' => 'Sherlock',
Expand Down Expand Up @@ -121,7 +121,7 @@ function it_does_not_create_new_addresses_for_already_addressed_order(
$stateMachine->can('address')->willReturn(true);
$stateMachine->apply('address')->shouldBeCalled();

$this->handle(new AddressShipmentCommand(
$this(new AddressShipmentCommand(
'ORDERTOKEN',
Address::createFromArray([
'firstName' => 'Sherlock',
Expand Down Expand Up @@ -149,7 +149,7 @@ function it_throws_an_exception_if_order_does_not_exist(
): void {
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn(null);

$this->shouldThrow(\LogicException::class)->during('handle', [
$this->shouldThrow(\LogicException::class)->during('__invoke', [
new AddressShipmentCommand(
'ORDERTOKEN',
Address::createFromArray([
Expand Down Expand Up @@ -185,7 +185,7 @@ function it_throws_an_exception_if_order_cannot_be_addressed(
$stateMachineFactory->get($order, OrderCheckoutTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->can('address')->willReturn(false);

$this->shouldThrow(\LogicException::class)->during('handle', [
$this->shouldThrow(\LogicException::class)->during('__invoke', [
new AddressShipmentCommand(
'ORDERTOKEN',
Address::createFromArray([
Expand Down
8 changes: 4 additions & 4 deletions spec/Handler/Cart/ChangeItemQuantityHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function it_handles_putting_new_item_to_cart(
$orderItemModifier->modify($orderItem, 5)->shouldBeCalled();
$orderProcessor->process($order)->shouldBeCalled();

$this->handle(new ChangeItemQuantity('ORDERTOKEN', 1, 5));
$this(new ChangeItemQuantity('ORDERTOKEN', 1, 5));
}

function it_throws_an_exception_if_order_has_not_been_found(OrderRepositoryInterface $orderRepository): void
{
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN', 'state' => OrderInterface::STATE_CART])->willReturn(null);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new ChangeItemQuantity('ORDERTOKEN', 1, 5),
]);
}
Expand All @@ -60,7 +60,7 @@ function it_throws_an_exception_if_order_item_has_not_been_found(
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN', 'state' => OrderInterface::STATE_CART])->willReturn($order);
$orderItemRepository->find(1)->willReturn(null);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new ChangeItemQuantity('ORDERTOKEN', 1, 5),
]);
}
Expand All @@ -76,7 +76,7 @@ function it_throws_an_exception_if_order_item_does_not_belongs_to_order(

$order->hasItem($orderItem)->willReturn(false);

$this->shouldThrow(\InvalidArgumentException::class)->during('handle', [
$this->shouldThrow(\InvalidArgumentException::class)->during('__invoke', [
new ChangeItemQuantity('ORDERTOKEN', 1, 5),
]);
}
Expand Down
10 changes: 5 additions & 5 deletions spec/Handler/Cart/ChoosePaymentMethodHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function it_assignes_choosen_payment_method_to_specified_payment(
$payment->setMethod($paymentMethod)->shouldBeCalled();
$stateMachine->apply('select_payment')->shouldBeCalled();

$this->handle(new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'));
$this(new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'));
}

function it_throws_an_exception_if_order_with_given_token_has_not_been_found(
Expand All @@ -59,7 +59,7 @@ function it_throws_an_exception_if_order_with_given_token_has_not_been_found(

$this
->shouldThrow(\InvalidArgumentException::class)
->during('handle', [
->during('__invoke', [
new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'),
])
;
Expand All @@ -83,7 +83,7 @@ function it_throws_an_exception_if_order_cannot_have_payment_selected(

$this
->shouldThrow(\InvalidArgumentException::class)
->during('handle', [
->during('__invoke', [
new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'),
])
;
Expand All @@ -107,7 +107,7 @@ function it_throws_an_exception_if_payment_method_with_given_code_has_not_been_f

$this
->shouldThrow(\InvalidArgumentException::class)
->during('handle', [
->during('__invoke', [
new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'),
])
;
Expand All @@ -133,7 +133,7 @@ function it_throws_an_exception_if_ordered_payment_has_not_been_found(

$this
->shouldThrow(\InvalidArgumentException::class)
->during('handle', [
->during('__invoke', [
new ChoosePaymentMethod('ORDERTOKEN', 0, 'CASH_ON_DELIVERY_METHOD'),
])
;
Expand Down
Loading