From c1f47dbc6817d3381a11ef4871d9db6cb3eb7fc6 Mon Sep 17 00:00:00 2001 From: maciekpaprocki Date: Wed, 13 Oct 2021 20:33:35 +0100 Subject: [PATCH 1/3] Fix state machine exception on order creation When dealing with virtual products or ( when only one shipping method is enabled and channel skipping_shipping_step_allowed ) --- src/EventListener/OrderCreationListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/EventListener/OrderCreationListener.php b/src/EventListener/OrderCreationListener.php index 0eb9cec1..83752ef2 100644 --- a/src/EventListener/OrderCreationListener.php +++ b/src/EventListener/OrderCreationListener.php @@ -41,7 +41,9 @@ public function completeOrderBeforeCreation(GenericEvent $event): void $stateMachine = $this->stateMachineFactory->get($order, 'sylius_order_checkout'); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING); + if ($stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)) { + $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING); + } if ($stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)) { $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT); } From bc253879d17d51207f6cc545568c0099d573d623 Mon Sep 17 00:00:00 2001 From: maciekpaprocki Date: Thu, 28 Oct 2021 17:06:19 +0100 Subject: [PATCH 2/3] added phpspec tests --- .phpunit.result.cache | 1 + .../OrderCreationListenerSpec.php | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 00000000..2de2a6da --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":[]} \ No newline at end of file diff --git a/spec/EventListener/OrderCreationListenerSpec.php b/spec/EventListener/OrderCreationListenerSpec.php index e222948d..c3c000b4 100644 --- a/spec/EventListener/OrderCreationListenerSpec.php +++ b/spec/EventListener/OrderCreationListenerSpec.php @@ -44,6 +44,7 @@ function it_completes_order_before_creation( $stateMachineFactory->get($order, 'sylius_order_checkout')->willReturn($stateMachine); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->willReturn(true); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->shouldBeCalled(); $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->willReturn(true); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->shouldBeCalled(); @@ -62,6 +63,7 @@ function it_completes_order_without_payment_before_creation( $stateMachineFactory->get($order, 'sylius_order_checkout')->willReturn($stateMachine); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->willReturn(true); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->shouldBeCalled(); $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->willReturn(false); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->shouldNotBeCalled(); @@ -70,18 +72,35 @@ function it_completes_order_without_payment_before_creation( $this->completeOrderBeforeCreation($event); } + function it_completes_order_without_shipping_before_creation( + FactoryInterface $stateMachineFactory, + GenericEvent $event, + StateMachineInterface $stateMachine, + OrderInterface $order + ) { + $event->getSubject()->willReturn($order); + + $stateMachineFactory->get($order, 'sylius_order_checkout')->willReturn($stateMachine); + $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->willReturn(false); + $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->shouldNotBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->willReturn(true); + $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->shouldBeCalled(); + $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_COMPLETE)->shouldBeCalled(); + + $this->completeOrderBeforeCreation($event); + } + function it_throws_exception_if_event_subject_is_not_order(GenericEvent $event) { $event->getSubject()->willReturn('badObject', 'badObject'); $this ->shouldThrow(\InvalidArgumentException::class) - ->during('processOrderBeforeCreation', [$event]) - ; + ->during('processOrderBeforeCreation', [$event]); $this ->shouldThrow(\InvalidArgumentException::class) - ->during('completeOrderBeforeCreation', [$event]) - ; + ->during('completeOrderBeforeCreation', [$event]); } } From 10bf4b5e10092cd1288f915900ca777c21cdf339 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 25 Feb 2022 13:56:43 +0100 Subject: [PATCH 3/3] Remove PHPUnit cache file --- .gitignore | 2 ++ .phpunit.result.cache | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 .phpunit.result.cache diff --git a/.gitignore b/.gitignore index a5fa0f9a..2fba55ec 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /tests/Application/yarn.lock /web/media + +/.phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 2de2a6da..00000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":[]} \ No newline at end of file