From a115722c49c99b7e690881996579deaba1297bb1 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 4 Jan 2024 13:56:57 +0100 Subject: [PATCH] Re-add phpspec --- .github/workflows/build.yml | 11 ++++++- ...rSpec.php => CancelOrderProcessorSpec.php} | 22 +++++++++----- .../CompleteAuthorizedOrderProcessorSpec.php | 30 +++++++++++++++---- .../StateMachine/RefundOrderProcessorSpec.php | 30 +++++++++++++++---- 4 files changed, 72 insertions(+), 21 deletions(-) rename spec/StateMachine/{CancelAuthorizedOrderProcessorSpec.php => CancelOrderProcessorSpec.php} (71%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 444daa1..9a1767f 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 @@ -215,7 +220,11 @@ jobs: if: matrix.sylius == '~1.11.0' run: | composer require "nyholm/psr7" --no-update --no-scripts --no-interaction - + - + name: Fix build with PHP 8.3 + if: matrix.php == '8.3' + run: | + composer remove "phpspec/phpspec" --no-update --no-scripts --no-interaction - name: Install PHP dependencies run: composer install --no-interaction 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); } }