Skip to content

Commit

Permalink
added phpspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekpaprocki authored and GSadee committed Feb 25, 2022
1 parent c1f47db commit bc25387
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":[],"times":[]}
27 changes: 23 additions & 4 deletions spec/EventListener/OrderCreationListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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]);
}
}

0 comments on commit bc25387

Please sign in to comment.