From 68fa984cbe0c97d53d4de3508626ae9cf12b361d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Wed, 26 Jun 2024 13:47:06 +0200 Subject: [PATCH] Make method more clear --- .../shop/stripe_checkout_session/api.feature | 4 +- tests/Behat/Context/Api/Shop/CartContext.php | 53 ++++++++----------- .../Shop/StripeCheckoutSessionShopContext.php | 4 +- .../Context/Ui/Shop/StripeJsShopContext.php | 4 +- .../Mocker/StripeCheckoutSessionMocker.php | 2 +- tests/Behat/Mocker/StripeJsMocker.php | 5 +- .../Page/Admin/PaymentMethod/CreatePage.php | 2 + 7 files changed, 35 insertions(+), 39 deletions(-) diff --git a/features/shop/stripe_checkout_session/api.feature b/features/shop/stripe_checkout_session/api.feature index 757eead..9ba96b4 100644 --- a/features/shop/stripe_checkout_session/api.feature +++ b/features/shop/stripe_checkout_session/api.feature @@ -17,7 +17,7 @@ Feature: Paying with Stripe Checkout Session during checkout Given the store has a payment method "Stripe" with a code "stripe" and Stripe Checkout Session payment gateway without using authorize And I added product "PHP T-Shirt" to the cart And I have proceeded selecting "Stripe" payment method - When I see the payment configuration + When I see the payment configuration for Stripe Checkout Session Then I should be able to get "publishable_key" with value "pk_test_publishablekey" And I should be able to get "use_authorize" with a boolean value 0 And I should be able to get "stripe_checkout_session_url" with value "https://checkout.stripe.com/c/pay/cs_1" @@ -27,7 +27,7 @@ Feature: Paying with Stripe Checkout Session during checkout Given the store has a payment method "Stripe authorize" with a code "stripe_authorize" and Stripe Checkout Session payment gateway using authorize And I added product "PHP T-Shirt" to the cart And I have proceeded selecting "Stripe authorize" payment method - When I see the payment configuration + When I see the payment configuration for Stripe Checkout Session Then I should be able to get "publishable_key" with value "pk_test_publishablekey" And I should be able to get "use_authorize" with a boolean value 1 And I should be able to get "stripe_checkout_session_url" with value "https://checkout.stripe.com/c/pay/cs_1" diff --git a/tests/Behat/Context/Api/Shop/CartContext.php b/tests/Behat/Context/Api/Shop/CartContext.php index 79ed3fc..bd97ff7 100644 --- a/tests/Behat/Context/Api/Shop/CartContext.php +++ b/tests/Behat/Context/Api/Shop/CartContext.php @@ -41,24 +41,12 @@ public function __construct( } /** - * @When /^I see the payment configuration$/ + * @When /^I see the payment configuration for Stripe Checkout Session$/ */ - public function iSeeThePaymentConfiguration(): void + public function iSeeThePaymentConfigurationForStripeCheckoutSession(): void { - $this->stripeCheckoutSessionMocker->mockCreatePayment(function () { - $tokenValue = $this->getCartTokenValue(); - - $this->shopClient->show( - Resources::ORDERS, - sprintf( - '%s/%s/%s/configuration', - $tokenValue, - Resources::PAYMENTS, - $this->getCart()['payments'][0]['id'] - ) - ); - - $this->sharedStorage->set('response', $this->shopClient->getLastResponse()); + $this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () { + $this->showPaymentConfiguration(); }); } @@ -67,20 +55,8 @@ public function iSeeThePaymentConfiguration(): void */ public function iSeeThePaymentConfigurationForStripeJs(): void { - $this->stripeJsMocker->mockCreatePayment(function () { - $tokenValue = $this->getCartTokenValue(); - - $this->shopClient->show( - Resources::ORDERS, - sprintf( - '%s/%s/%s/configuration', - $tokenValue, - Resources::PAYMENTS, - $this->getCart()['payments'][0]['id'] - ) - ); - - $this->sharedStorage->set('response', $this->shopClient->getLastResponse()); + $this->stripeJsMocker->mockCaptureOrAuthorize(function () { + $this->showPaymentConfiguration(); }); } @@ -104,6 +80,23 @@ public function iShouldBeAbleToGetWithABooleanValue(string $key, bool $expectedV Assert::eq($value, $expectedValue); } + function showPaymentConfiguration(): void + { + $tokenValue = $this->getCartTokenValue(); + + $this->shopClient->show( + Resources::ORDERS, + sprintf( + '%s/%s/%s/configuration', + $tokenValue, + Resources::PAYMENTS, + $this->getCart()['payments'][0]['id'] + ) + ); + + $this->sharedStorage->set('response', $this->shopClient->getLastResponse()); + } + private function getCart(): array { return $this->responseChecker->getResponseContent($this->shopClient->show(Resources::ORDERS, $this->getCartTokenValue())); diff --git a/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php b/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php index 4a614c9..198fad3 100644 --- a/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php +++ b/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php @@ -42,7 +42,7 @@ public function __construct( */ public function iConfirmMyOrderWithStripePayment(): void { - $this->stripeCheckoutSessionMocker->mockCreatePayment(function () { + $this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () { $this->summaryPage->confirmOrder(); }); } @@ -147,7 +147,7 @@ public function iClickOnGoBackDuringMyStripePayment(): void */ public function iTryToPayAgainWithStripePayment(): void { - $this->stripeCheckoutSessionMocker->mockCreatePayment(function () { + $this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () { $this->orderDetails->pay(); }); } diff --git a/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php b/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php index 270c9d5..ad1ee7a 100644 --- a/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php +++ b/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php @@ -126,7 +126,7 @@ public function theStripeJsFormIsDisplayedAndICompleteThePaymentWithoutWebhookUs */ public function iConfirmMyOrderWithStripePayment(): void { - $this->stripeJsMocker->mockCreatePayment(function () { + $this->stripeJsMocker->mockCaptureOrAuthorize(function () { $this->summaryPage->confirmOrder(); }); } @@ -147,7 +147,7 @@ public function iClickOnGoBackDuringMyStripePayment(): void */ public function iTryToPayAgainWithStripePayment(): void { - $this->stripeJsMocker->mockCreatePayment(function () { + $this->stripeJsMocker->mockCaptureOrAuthorize(function () { $this->orderDetails->pay(); }); } diff --git a/tests/Behat/Mocker/StripeCheckoutSessionMocker.php b/tests/Behat/Mocker/StripeCheckoutSessionMocker.php index f98f1d5..8b5f205 100644 --- a/tests/Behat/Mocker/StripeCheckoutSessionMocker.php +++ b/tests/Behat/Mocker/StripeCheckoutSessionMocker.php @@ -33,7 +33,7 @@ public function __construct( $this->refundMocker = $refundMocker; } - public function mockCreatePayment(callable $action): void + public function mockCaptureOrAuthorize(callable $action): void { $this->checkoutSessionMocker->mockCreateAction(); diff --git a/tests/Behat/Mocker/StripeJsMocker.php b/tests/Behat/Mocker/StripeJsMocker.php index 789d8ff..c2eb92b 100644 --- a/tests/Behat/Mocker/StripeJsMocker.php +++ b/tests/Behat/Mocker/StripeJsMocker.php @@ -27,10 +27,11 @@ public function __construct( $this->refundMocker = $refundMocker; } - public function mockCreatePayment(callable $action): void + public function mockCaptureOrAuthorize(callable $action): void { - $this->paymentIntentMocker->mockCreateAction(); + $this->mocker->unmockAll(); + $this->paymentIntentMocker->mockCreateAction(); $this->mockPaymentIntentSync( $action, PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD diff --git a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php index d14d0bd..31b859a 100644 --- a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php +++ b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php @@ -56,6 +56,8 @@ public function setStripeIsAuthorized(bool $isAuthorized): void } else { $this->getElement('use_authorize')->uncheck(); } + + sleep(1); } /**