Skip to content

Commit

Permalink
Re-add phpspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Jan 4, 2024
1 parent a6ee2f4 commit b752b01
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +28,7 @@ public function let(
public function it_is_invokable(
Payum $payum,
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
GatewayInterface $gateway,
Expand All @@ -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);
Expand All @@ -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);
}
}
30 changes: 24 additions & 6 deletions spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ public function let(
public function it_is_invokable(
Payum $payum,
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
GatewayInterface $gateway,
Expand All @@ -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);
Expand All @@ -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);
}
}
30 changes: 24 additions & 6 deletions spec/StateMachine/RefundOrderProcessorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ public function let(
public function it_is_invokable(
Payum $payum,
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
GatewayInterface $gateway,
Expand All @@ -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);
Expand All @@ -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);
}
}

0 comments on commit b752b01

Please sign in to comment.