Skip to content

Commit

Permalink
Fix behat test when create a payment and fix test for 'go back' from …
Browse files Browse the repository at this point in the history
…Stripe
  • Loading branch information
Prometee committed Apr 7, 2020
1 parent 12f0b92 commit 9d407e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ Feature: Paying with Stripe during checkout
And I should be able to pay again

@ui
Scenario: Cancelling the payment
Scenario: Never pay on Stripe and click on "go back"
Given I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Stripe" payment method
When I confirm my order with Stripe payment
And I never fill any credit card field on my Stripe payment
Then I should be notified that my payment has been cancelled
And I click on "go back" during my Stripe payment
And I should be able to pay again
6 changes: 3 additions & 3 deletions tests/Behat/Context/Ui/Shop/StripeShopContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public function iTryToPayAgainStripePayment(): void
}

/**
* @Given /^I never fill any credit card field on my Stripe payment$/
* @When /^I click on "go back" during my Stripe payment$/
*/
public function iNeverFillAnyCreditCardFieldOnMyStripePayment()
public function IClickOnGoBackDuringMyStripePayment()
{
$this->stripeSessionCheckoutMocker->mockPaymentIntentRequiredStatus(function() {
$this->stripeSessionCheckoutMocker->mockPaymentIntentRequiresPaymentMethodStatus(function () {
$this->paymentPage->capture();
});
}
Expand Down
19 changes: 11 additions & 8 deletions tests/Behat/Mocker/StripeSessionCheckoutMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function mockCreatePayment(callable $action): void
{
$model = [
'id' => 'sess_1',
'object' => Session::OBJECT_NAME,
'payment_intent' => 'pi_1',
'metadata' => [
'token_hash' => '',
],
];

$mock = $this->mocker->mockService('tests.prometee.sylius_payum_stripe_checkout_session_plugin.behat.mocker.action.create_session', AbstractCreateAction::class);
Expand All @@ -50,39 +55,37 @@ public function mockCreatePayment(callable $action): void
->shouldReceive('execute')
->once()
->andReturnUsing(function (CreateSession $request) use ($model) {
$rModel = $request->getModel();
$model['metadata']['token_hash'] = $rModel['metadata']['token_hash'];
$request->setApiResource(Session::constructFrom($model));
})
;

$action();
$this->mockPaymentIntentRequiresPaymentMethodStatus($action);

$this->mocker->unmockAll();
}

public function mockCancelledPayment(
callable $notifyAction,
callable $captureAction
): void
{
): void {
$this->mockPaymentIntentSync($notifyAction, PaymentIntent::STATUS_CANCELED);
$this->mockPaymentIntentSync($captureAction, PaymentIntent::STATUS_CANCELED);
}

public function mockSuccessfulPayment(
callable $notifyAction,
callable $captureAction
): void
{
): void {
$this->mockPaymentIntentSync($notifyAction, PaymentIntent::STATUS_SUCCEEDED);
$this->mockPaymentIntentSync($captureAction, PaymentIntent::STATUS_SUCCEEDED);
}

/**
* @param callable $captureAction
*
* @see https://stripe.com/docs/payments/intents#payment-intent
*/
public function mockPaymentIntentRequiredStatus(callable $captureAction)
public function mockPaymentIntentRequiresPaymentMethodStatus(callable $captureAction)
{
$this->mockPaymentIntentSync($captureAction, PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD);
}
Expand Down

0 comments on commit 9d407e1

Please sign in to comment.