Skip to content

Commit

Permalink
Tests BeHat and PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Nov 19, 2024
1 parent 3c6fbac commit a9cce87
Show file tree
Hide file tree
Showing 57 changed files with 1,977 additions and 256 deletions.
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"sylius/core-bundle": "^2.0-dev",
"sylius/core-bundle": "^2.0",
"stripe/stripe-php": "^16.1"
},
"require-dev": {
Expand All @@ -34,7 +34,7 @@
"robertfausk/behat-panther-extension": "^1.1",
"sylius-labs/coding-standard": "^4.1",
"sylius-labs/suite-tags-extension": "^0.2.0",
"sylius/sylius": "^2.0-dev",
"sylius/sylius": "^2.0",
"symfony/browser-kit": "^6.4|^7.1",
"symfony/debug-bundle": "^6.4|^7.1",
"symfony/dotenv": "^6.4|^7.1",
Expand All @@ -45,7 +45,11 @@
"nyholm/psr7": "^1.8",
"mockery/mockery": "^1.6",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-symfony": "^1.4"
"phpstan/phpstan-symfony": "^1.4",
"theofidry/alice-data-fixtures": "^1.7",
"doctrine/orm": "^2.20",
"doctrine/data-fixtures": "^1.8",
"lchrusciel/api-test-case": "^5.3"
},
"suggest": {
"sylius/shop-bundle": "Use the Sylius default front shop",
Expand Down
2 changes: 2 additions & 0 deletions config/services/command_providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
tags:
- name: flux_se.sylius_stripe.command_provider.checkout
action: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_CAPTURE
- name: flux_se.sylius_stripe.command_provider.checkout
action: !php/const Sylius\Component\Payment\Model\PaymentRequestInterface::ACTION_AUTHORIZE

flux_se.sylius_stripe.command_provider.checkout.status:
class: FluxSE\SyliusStripePlugin\CommandProvider\Checkout\StatusPaymentRequestCommandProvider
Expand Down
149 changes: 99 additions & 50 deletions config/services/providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,127 @@ parameters:
services:
# WEB ELEMENTS
flux_se.sylius_stripe.provider.web_elements.create.payment_intent_params:
class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\PaymentIntentParamsProvider
class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider
arguments:
- '@flux_se.sylius_stripe.provider.web_elements.amount'
- '@flux_se.sylius_stripe.provider.web_elements.currency'
- '@flux_se.sylius_stripe.provider.web_elements.payment_method_types'
- '@flux_se.sylius_stripe.provider.web_elements.metadata'
- !tagged_iterator flux_se.sylius_stripe.provider.web_elements.details

flux_se.sylius_stripe.provider.web_elements.amount:
class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\AmountProvider
tags:
- name: flux_se.sylius_stripe.provider.web_elements.details

flux_se.sylius_stripe.provider.web_elements.currency:
class: FluxSE\SyliusStripePlugin\Provider\WebElements\Create\CurrencyProvider

flux_se.sylius_stripe.provider.web_elements.customer_email:
class: FluxSE\SyliusStripePlugin\Provider\CustomerEmailProvider
tags:
- name: flux_se.sylius_stripe.provider.web_elements.details

flux_se.sylius_stripe.provider.web_elements.payment_method_types:
class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider
tags:
- name: flux_se.sylius_stripe.provider.web_elements.details

flux_se.sylius_stripe.provider.web_elements.token_hash_metadata:
class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider
tags:
- name: flux_se.sylius_stripe.provider.web_elements.details

flux_se.sylius_stripe.provider.web_elements.metadata:
class: FluxSE\SyliusStripePlugin\Provider\PaymentMetadataProvider
flux_se.sylius_stripe.provider.web_elements.capture_method.manual:
class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider
tags:
- name: flux_se.sylius_stripe.provider.web_elements.details

# CHECKOUT
flux_se.sylius_stripe.provider.checkout.create.checkout_session_params:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\CheckoutSessionParamsProvider
arguments:
- '@flux_se.sylius_stripe.provider.checkout.customer_email'
- '@flux_se.sylius_stripe.provider.checkout.mode'
- '@flux_se.sylius_stripe.provider.checkout.line_items'
- '@flux_se.sylius_stripe.provider.checkout.payment_method_types'
- '@flux_se.sylius_stripe.provider.checkout.metadata'
- '@flux_se.sylius_stripe.provider.checkout.after_url'

flux_se.sylius_stripe.provider.checkout.after_url.default:
class: FluxSE\SyliusStripePlugin\Provider\DefaultAfterUrlProvider
arguments:
- '%flux_se.sylius_stripe.checkout.after_urls%'

flux_se.sylius_stripe.provider.checkout.create.checkout_session_params:
class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider
arguments:
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.after_url:
class: FluxSE\SyliusStripePlugin\Provider\AfterUrlProvider
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\AfterUrlProvider
arguments:
- '@flux_se.sylius_stripe.provider.checkout.after_url.default'
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.mode:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ModeProvider
flux_se.sylius_stripe.provider.checkout.payment_mode:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ModePaymentProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.customer_email:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\CustomerEmailProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.payment_method_types:
class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.token_hash_metadata:
class: FluxSE\SyliusStripePlugin\Provider\TokenHashMetadataProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.payment_intent_data:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\PaymentIntentDataProvider
arguments:
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.payment_intent_data
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.payment_intent_data.capture_method.manual:
class: FluxSE\SyliusStripePlugin\Provider\PaymentIntentCaptureMethodManualProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.payment_intent_data

flux_se.sylius_stripe.provider.checkout.line_items:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItemsProvider
arguments:
- '@flux_se.sylius_stripe.provider.checkout.line_item'
- '@flux_se.sylius_stripe.provider.checkout.shipping_line_item'
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.order_item
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.shipment
tags:
- name: flux_se.sylius_stripe.provider.checkout.details

flux_se.sylius_stripe.provider.checkout.line_item:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItemProvider
flux_se.sylius_stripe.provider.checkout.line_item.order_item:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemLineItemProvider
arguments:
- '@flux_se.sylius_stripe.provider.checkout.line_item_images'
- '@flux_se.sylius_stripe.provider.checkout.line_item_name'
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner
tags:
- name: flux_se.sylius_stripe.provider.checkout.line_item.order_item

flux_se.sylius_stripe.provider.checkout.line_item_images:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItemImagesProvider
flux_se.sylius_stripe.provider.checkout.line_item.order_item.product_data.images:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemProductDataImagesProvider
arguments:
- '@liip_imagine.cache.manager'
- '%flux_se.sylius_stripe.line_item_image.imagine_filter%'
- '%flux_se.sylius_stripe.line_item_image.fallback_image%'
- '%flux_se.sylius_stripe.line_item_image.localhost_pattern%'
tags:
- name: flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner

flux_se.sylius_stripe.provider.checkout.line_item_name:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LinetItemNameProvider
flux_se.sylius_stripe.provider.checkout.line_item.order_item.product_data.name:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\OrderItemProductDataNameProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.line_item.order_item.inner

flux_se.sylius_stripe.provider.checkout.shipping_line_item:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ShippingLineItemProvider
flux_se.sylius_stripe.provider.checkout.line_item.shipment:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentLineItemProvider
arguments:
- '@flux_se.sylius_stripe.provider.checkout.shipping_line_item_name'

flux_se.sylius_stripe.provider.checkout.shipping_line_item_name:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\ShippingLineItemNameProvider

flux_se.sylius_stripe.provider.checkout.customer_email:
class: FluxSE\SyliusStripePlugin\Provider\CustomerEmailProvider

flux_se.sylius_stripe.provider.checkout.payment_method_types:
class: FluxSE\SyliusStripePlugin\Provider\PaymentMethodTypesProvider
- !tagged_iterator flux_se.sylius_stripe.provider.checkout.line_item.shipment.inner
tags:
- name: flux_se.sylius_stripe.provider.checkout.line_item.shipment

flux_se.sylius_stripe.provider.checkout.metadata:
class: FluxSE\SyliusStripePlugin\Provider\PaymentMetadataProvider
flux_se.sylius_stripe.provider.checkout.line_item.shipment.product_data.name:
class: FluxSE\SyliusStripePlugin\Provider\Checkout\Create\LineItem\ShipmentProductDataNameProvider
tags:
- name: flux_se.sylius_stripe.provider.checkout.line_item.shipment.inner

FluxSE\SyliusStripePlugin\Provider\StripeNotifyPaymentProvider:
arguments:
Expand All @@ -104,9 +141,21 @@ services:

# REFUND
flux_se.sylius_stripe.provider.refund.create:
class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\RefundParamsProvider
class: FluxSE\SyliusStripePlugin\Provider\CompositeParamsProvider
arguments:
- '@flux_se.sylius_stripe.provider.refund.metadata'
- !tagged_iterator flux_se.sylius_stripe.provider.refund.details

flux_se.sylius_stripe.provider.refund.metadata:
class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\RefundMetadataProvider
flux_se.sylius_stripe.provider.refund.metadata.amount:
class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\AmountProvider
tags:
- name: flux_se.sylius_stripe.provider.refund.details

flux_se.sylius_stripe.provider.refund.metadata.payment_intent:
class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\PaymentIntentProvider
tags:
- name: flux_se.sylius_stripe.provider.refund.details

flux_se.sylius_stripe.provider.refund.metadata.refund_token_hash:
class: FluxSE\SyliusStripePlugin\Provider\Refund\Create\RefundTokenHashMetadataProvider
tags:
- name: flux_se.sylius_stripe.provider.refund.details
10 changes: 8 additions & 2 deletions config/services/stripe/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ parameters:

services:

flux_se.sylius_stripe.stripe.http_client:
class: FluxSE\SyliusStripePlugin\Stripe\HttpClient\PsrClient
FluxSE\SyliusStripePlugin\Stripe\HttpClient\PsrClient:
abstract: true
arguments:
- '@sylius.http_client'
- '@sylius.http_client'
- '@sylius.http_client'
- '%flux_se.sylius_stripe.stripe.client.chunk_size%'

flux_se.sylius_stripe.stripe.http_client:
parent: FluxSE\SyliusStripePlugin\Stripe\HttpClient\PsrClient

flux_se.sylius_stripe.stripe.streaming_http_client:
parent: FluxSE\SyliusStripePlugin\Stripe\HttpClient\PsrClient
2 changes: 1 addition & 1 deletion config/services/stripe/configurator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ services:
arguments:
- '@logger'
- '@flux_se.sylius_stripe.stripe.http_client'
- '@flux_se.sylius_stripe.stripe.http_client'
- '@flux_se.sylius_stripe.stripe.streaming_http_client'
FluxSE\SyliusStripePlugin\Stripe\Configurator\StripeConfiguratorInterface:
alias: flux_se.sylius_stripe.stripe.configurator
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@managing_orders
Feature: Canceling an authorized order with Stripe Checkout Session
Feature: Canceling an authorized order with Stripe Checkout
In order to cancel an order already authorized
As an Administrator
I want to be able to cancel a Stripe authorized order
Expand All @@ -12,13 +12,13 @@ Feature: Canceling an authorized order with Stripe Checkout Session
And there is a customer "[email protected]" that placed an order "#00000001"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is already authorized as "pi_123" Stripe payment intent
And this order is not yet paid as "cs_test_123" Stripe Checkout Session
And I am logged in as an administrator

@ui @api
Scenario: Cancelling the order with an authorized payment
Given I am viewing the summary of this order
And I am prepared to cancel this order
And I am prepared to expire this order checkout session
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
Expand Down
17 changes: 9 additions & 8 deletions features/admin/stripe_checkout/cancel_order.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@managing_orders
Feature: Canceling an order with Stripe Checkout Session
Feature: Canceling an order with Stripe Checkout
In order to cancel a not paid order
As an Administrator
I want to be able to cancel a Stripe not paid order
Expand All @@ -9,26 +9,27 @@ Feature: Canceling an order with Stripe Checkout Session
And the store has a product "Green Arrow"
And the store ships everywhere for free
And the store has a payment method "Stripe" with a code "stripe" and Stripe Checkout payment gateway without using authorize
And there is a customer "[email protected]" that placed an order "#00000001"
And there is a customer "[email protected]" that placed an order "#00000022"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is not yet paid as "cs_123" Stripe Checkout Session
And this order is not yet paid as "cs_test_123" Stripe Checkout Session
And I am logged in as an administrator

@ui @api
Scenario: Cancelling the order when a checkout session is still available
Given I am viewing the summary of this order
And I am prepared to expire the checkout session on this order
And I am prepared to expire this order checkout session
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
And it should have payment state cancelled
And it should have payment state "Cancelled"

@ui @api
Scenario: Cancelling the order after the customer canceled the payment
Given this order payment has been canceled
And I am viewing the summary of this order
And I am prepared to cancel this order
Given I am viewing the summary of this order
And I am prepared to expire this order checkout session
And this order payment has been canceled
And I am prepared to expire this order checkout session
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
Expand Down
4 changes: 2 additions & 2 deletions features/admin/stripe_web_elements/cancel_order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature: Canceling an order with Stripe JS
@ui @api
Scenario: Cancelling the order when a payment intent is still available
Given I am viewing the summary of this order
And I am prepared to cancel the payment intent on this order
And I am prepared to cancel the payment intent
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
Expand All @@ -32,4 +32,4 @@ Feature: Canceling an order with Stripe JS
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
And it should have payment state cancelled
And it should have payment state "Cancelled"
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<php>
<ini name="error_reporting" value="-1" />

<server name="KERNEL_CLASS_PATH" value="/tests/Application/src/Kernel.php" />
<server name="KERNEL_CLASS" value="Tests\FluxSE\SyliusStripePlugin\App\Kernel" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />

<env name="APP_ENV" value="test"/>
Expand Down
14 changes: 12 additions & 2 deletions src/CommandHandler/Checkout/CancelPaymentRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace FluxSE\SyliusStripePlugin\CommandHandler\Checkout;

use FluxSE\SyliusStripePlugin\Command\Checkout\CancelPaymentRequest;
use FluxSE\SyliusStripePlugin\CommandHandler\FailedAwarePaymentRequestHandlerTrait;
use FluxSE\SyliusStripePlugin\Manager\Checkout\ExpireManagerInterface;
use FluxSE\SyliusStripePlugin\Manager\Checkout\RetrieveManagerInterface;
use FluxSE\SyliusStripePlugin\Processor\PaymentTransitionProcessorInterface;
Expand All @@ -17,13 +18,16 @@
#[AsMessageHandler]
final readonly class CancelPaymentRequestHandler
{
use FailedAwarePaymentRequestHandlerTrait;

public function __construct(
private PaymentRequestProviderInterface $paymentRequestProvider,
private RetrieveManagerInterface $retrieveCheckoutManager,
private ExpireManagerInterface $expireCheckoutManager,
private PaymentTransitionProcessorInterface $paymentTransitionProcessor,
private StateMachineInterface $stateMachine,
StateMachineInterface $stateMachine,
) {
$this->stateMachine = $stateMachine;
}

public function __invoke(CancelPaymentRequest $cancelPaymentRequest): void
Expand All @@ -32,7 +36,13 @@ public function __invoke(CancelPaymentRequest $cancelPaymentRequest): void

/** @var string|null $id */
$id = $paymentRequest->getPayment()->getDetails()['id'] ?? null;
Assert::notNull($id, 'An id is required to retrieve the related Stripe Checkout/Session.');
if (null === $id) {
$this->failWithReason(
$paymentRequest,
'An id is required to retrieve the related Stripe Checkout/Session.'
);
return;
}

$session = $this->retrieveCheckoutManager->retrieve($paymentRequest, $id);
if ($session::STATUS_OPEN !== $session->status) {
Expand Down
Loading

0 comments on commit a9cce87

Please sign in to comment.