diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 444daa1..392cec6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,6 +100,11 @@ jobs: name: Run PHPStan run: vendor/bin/phpstan analyse if: always() && steps.end-of-setup.outcome == 'success' + + - + name: Run PHPSpec + run: vendor/bin/phpspec run --ansi -f progress --no-interaction + if: always() && steps.end-of-setup.outcome == 'success' tests: runs-on: ubuntu-latest diff --git a/spec/StateMachine/CancelAuthorizedOrderProcessorSpec.php b/spec/StateMachine/CancelOrderProcessorSpec.php similarity index 71% rename from spec/StateMachine/CancelAuthorizedOrderProcessorSpec.php rename to spec/StateMachine/CancelOrderProcessorSpec.php index f1346b4..138f1f5 100644 --- a/spec/StateMachine/CancelAuthorizedOrderProcessorSpec.php +++ b/spec/StateMachine/CancelOrderProcessorSpec.php @@ -11,11 +11,12 @@ use Payum\Core\Security\TokenFactoryInterface; use Payum\Core\Security\TokenInterface; use PhpSpec\ObjectBehavior; +use SM\Event\TransitionEvent; use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; -final class CancelAuthorizedOrderProcessorSpec extends ObjectBehavior +final class CancelOrderProcessorSpec extends ObjectBehavior { public function let( CancelRequestFactoryInterface $cancelRequestFactory, @@ -27,6 +28,7 @@ public function let( public function it_is_invokable( Payum $payum, PaymentInterface $payment, + TransitionEvent $event, PaymentMethodInterface $paymentMethod, GatewayConfigInterface $gatewayConfig, GatewayInterface $gateway, @@ -35,7 +37,6 @@ public function it_is_invokable( CancelRequestFactoryInterface $cancelRequestFactory, ModelAggregateInterface $request ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); @@ -46,21 +47,26 @@ public function it_is_invokable( $payum->getGateway($gatewayName)->willReturn($gateway); $payum->getTokenFactory()->willReturn($tokenFactory); - $tokenFactory->createToken($gatewayName, $payment, 'sylius_shop_order_after_pay')->willReturn($token); + $tokenFactory->createToken($gatewayName, $payment, 'payum_notify_do')->willReturn($token); $request->beConstructedWith([$token]); $cancelRequestFactory->createNewWithToken($token)->willReturn($request); $gateway->execute($request)->shouldBeCalled(); - $this->__invoke($payment); + $this->__invoke($payment, $event); } - public function it_do_nothing_when_it_is_not_an_authorized_state( - PaymentInterface $payment + public function it_do_nothing_when_gateway_is_unknown( + PaymentInterface $payment, + TransitionEvent $event, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED); + $payment->getMethod()->willReturn($paymentMethod); + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $gatewayConfig->getConfig()->willReturn(['factory' => 'foo']); - $this->__invoke($payment); + $this->__invoke($payment, $event); } } diff --git a/spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php b/spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php index b6819be..9efe7b9 100644 --- a/spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php +++ b/spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php @@ -11,6 +11,7 @@ use Payum\Core\Security\TokenFactoryInterface; use Payum\Core\Security\TokenInterface; use PhpSpec\ObjectBehavior; +use SM\Event\TransitionEvent; use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; @@ -27,6 +28,7 @@ public function let( public function it_is_invokable( Payum $payum, PaymentInterface $payment, + TransitionEvent $event, PaymentMethodInterface $paymentMethod, GatewayConfigInterface $gatewayConfig, GatewayInterface $gateway, @@ -35,7 +37,7 @@ public function it_is_invokable( CaptureRequestFactoryInterface $captureRequestFactory, ModelAggregateInterface $request ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); + $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); @@ -46,21 +48,37 @@ public function it_is_invokable( $payum->getGateway($gatewayName)->willReturn($gateway); $payum->getTokenFactory()->willReturn($tokenFactory); - $tokenFactory->createToken($gatewayName, $payment, 'sylius_shop_order_after_pay')->willReturn($token); + $tokenFactory->createToken($gatewayName, $payment, 'payum_notify_do')->willReturn($token); $request->beConstructedWith([$token]); $captureRequestFactory->createNewWithToken($token)->willReturn($request); $gateway->execute($request)->shouldBeCalled(); - $this->__invoke($payment); + $this->__invoke($payment, $event); } public function it_do_nothing_when_it_is_not_an_authorized_state( - PaymentInterface $payment + PaymentInterface $payment, + TransitionEvent $event + ): void { + $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); + + $this->__invoke($payment, $event); + } + + public function it_do_nothing_when_gateway_is_unknown( + PaymentInterface $payment, + TransitionEvent $event, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED); + $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); + + $payment->getMethod()->willReturn($paymentMethod); + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $gatewayConfig->getConfig()->willReturn(['factory' => 'foo']); - $this->__invoke($payment); + $this->__invoke($payment, $event); } } diff --git a/spec/StateMachine/RefundOrderProcessorSpec.php b/spec/StateMachine/RefundOrderProcessorSpec.php index fd788ea..a0133a6 100644 --- a/spec/StateMachine/RefundOrderProcessorSpec.php +++ b/spec/StateMachine/RefundOrderProcessorSpec.php @@ -11,6 +11,7 @@ use Payum\Core\Security\TokenFactoryInterface; use Payum\Core\Security\TokenInterface; use PhpSpec\ObjectBehavior; +use SM\Event\TransitionEvent; use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; @@ -27,6 +28,7 @@ public function let( public function it_is_invokable( Payum $payum, PaymentInterface $payment, + TransitionEvent $event, PaymentMethodInterface $paymentMethod, GatewayConfigInterface $gatewayConfig, GatewayInterface $gateway, @@ -35,7 +37,7 @@ public function it_is_invokable( RefundRequestFactoryInterface $refundRequestFactory, ModelAggregateInterface $request ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED); + $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); $payment->getMethod()->willReturn($paymentMethod); $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); @@ -46,21 +48,37 @@ public function it_is_invokable( $payum->getGateway($gatewayName)->willReturn($gateway); $payum->getTokenFactory()->willReturn($tokenFactory); - $tokenFactory->createToken($gatewayName, $payment, 'sylius_shop_order_after_pay')->willReturn($token); + $tokenFactory->createToken($gatewayName, $payment, 'payum_notify_do')->willReturn($token); $request->beConstructedWith([$token]); $refundRequestFactory->createNewWithToken($token)->willReturn($request); $gateway->execute($request)->shouldBeCalled(); - $this->__invoke($payment); + $this->__invoke($payment, $event); } public function it_do_nothing_when_it_is_not_a_completed_state( - PaymentInterface $payment + PaymentInterface $payment, + TransitionEvent $event + ): void { + $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); + + $this->__invoke($payment, $event); + } + + public function it_do_nothing_when_gateway_is_unknown( + PaymentInterface $payment, + TransitionEvent $event, + PaymentMethodInterface $paymentMethod, + GatewayConfigInterface $gatewayConfig ): void { - $payment->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); + $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); + + $payment->getMethod()->willReturn($paymentMethod); + $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); + $gatewayConfig->getConfig()->willReturn(['factory' => 'foo']); - $this->__invoke($payment); + $this->__invoke($payment, $event); } }