diff --git a/composer.json b/composer.json
index 5b5dbb79..43037430 100644
--- a/composer.json
+++ b/composer.json
@@ -19,10 +19,10 @@
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
+ "friends-of-behat/mink-debug-extension": "^2.0",
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
- "friends-of-behat/mink-debug-extension": "^2.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev",
@@ -40,7 +40,8 @@
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/web-server-bundle": "^4.4|^5.0",
"vimeo/psalm": "3.11.4",
- "rector/rector": "^0.11.53"
+ "rector/rector": "^0.11.53",
+ "lchrusciel/api-test-case": "^5.1"
},
"conflict": {
"symfony/doctrine-bridge": "4.4.16",
diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php
index b958a8e0..4fcad584 100644
--- a/tests/Application/config/bundles.php
+++ b/tests/Application/config/bundles.php
@@ -53,4 +53,6 @@
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
+ Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true],
+ Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true],
];
diff --git a/tests/Application/config/services_test.yaml b/tests/Application/config/services_test.yaml
index 8d1e8c8d..c8de3dd9 100644
--- a/tests/Application/config/services_test.yaml
+++ b/tests/Application/config/services_test.yaml
@@ -1,3 +1,25 @@
imports:
- { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" }
- { resource: "../../Behat/Resources/services.xml" }
+
+services:
+ Sylius\PayPalPlugin\Downloader\ReportDownloaderInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\DummyPayoutsReportDownloader
+
+ Sylius\PayPalPlugin\Processor\PaymentCompleteProcessorInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\VoidPayPalPaymentCompleteProcessor
+
+ Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\DummyAuthorizeClientApi
+
+ Sylius\PayPalPlugin\Api\OrderDetailsApiInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\DummyOrderDetailsApi
+
+ Sylius\PayPalPlugin\Api\RefundPaymentApiInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\DummyRefundPaymentApi
+
+ Sylius\PayPalPlugin\Provider\PayPalRefundDataProviderInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\DummyPayPalRefundDataProvider
+
+ Sylius\PayPalPlugin\Api\CreateOrderApiInterface:
+ class: Tests\Sylius\PayPalPlugin\Service\FakeCreateOrderApi
diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml
index 2659ec8d..cccf5a97 100644
--- a/tests/Behat/Resources/services.xml
+++ b/tests/Behat/Resources/services.xml
@@ -48,35 +48,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/DataFixtures/ORM/resources/new_cart.yaml b/tests/DataFixtures/ORM/resources/new_cart.yaml
new file mode 100644
index 00000000..b3b4c2f6
--- /dev/null
+++ b/tests/DataFixtures/ORM/resources/new_cart.yaml
@@ -0,0 +1,30 @@
+Sylius\Component\Core\Model\Order:
+ new_cart:
+ channel: "@channel_web"
+ items: ["@sw_mug_item"]
+ currencyCode: "USD"
+ localeCode: "en_US"
+ customer: "@customer_oliver"
+ state: "cart"
+ checkoutState: "shipping_selected"
+ tokenValue: "TOKEN"
+ payments: ["@paypal_payment"]
+
+Sylius\Component\Core\Model\OrderItem:
+ sw_mug_item:
+ units: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"]
+ variant: "@mug_sw"
+ order: "@new_cart"
+
+Sylius\Component\Core\Model\OrderItemUnit:
+ sw_mug_item_unit1:
+ __construct: ["@sw_mug_item"]
+ sw_mug_item_unit2:
+ __construct: ["@sw_mug_item"]
+
+Sylius\Component\Core\Model\Payment:
+ paypal_payment:
+ method: "@paypal"
+ currencyCode: "USD"
+ amount: 40
+ state: "cart"
diff --git a/tests/DataFixtures/ORM/resources/new_order.yaml b/tests/DataFixtures/ORM/resources/new_order.yaml
new file mode 100644
index 00000000..12f90748
--- /dev/null
+++ b/tests/DataFixtures/ORM/resources/new_order.yaml
@@ -0,0 +1,30 @@
+Sylius\Component\Core\Model\Order:
+ new_order:
+ channel: "@channel_web"
+ items: ["@sw_mug_item"]
+ currencyCode: "USD"
+ localeCode: "en_US"
+ customer: "@customer_oliver"
+ state: "new"
+ checkoutState: "completed"
+ tokenValue: "TOKEN"
+ payments: ["@paypal_payment"]
+
+Sylius\Component\Core\Model\OrderItem:
+ sw_mug_item:
+ units: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"]
+ variant: "@mug_sw"
+ order: "@new_order"
+
+Sylius\Component\Core\Model\OrderItemUnit:
+ sw_mug_item_unit1:
+ __construct: ["@sw_mug_item"]
+ sw_mug_item_unit2:
+ __construct: ["@sw_mug_item"]
+
+Sylius\Component\Core\Model\Payment:
+ paypal_payment:
+ method: "@paypal"
+ currencyCode: "USD"
+ amount: 40
+ state: "new"
diff --git a/tests/DataFixtures/ORM/resources/shop.yaml b/tests/DataFixtures/ORM/resources/shop.yaml
new file mode 100644
index 00000000..2c149940
--- /dev/null
+++ b/tests/DataFixtures/ORM/resources/shop.yaml
@@ -0,0 +1,111 @@
+Sylius\Component\Core\Model\Product:
+ mug:
+ code: "MUG"
+ channels: ["@channel_web"]
+ currentLocale: "en_US"
+ translations:
+ en_US: "@mug_translation"
+
+Sylius\Component\Core\Model\ProductTranslation:
+ mug_translation:
+ slug: "mug"
+ locale: "en_US"
+ name: "Mug"
+ description: ""
+ translatable: "@mug"
+
+Sylius\Component\Core\Model\ProductVariant:
+ mug_sw:
+ code: "MUG_SW"
+ product: "@mug"
+ currentLocale: "en_US"
+ translations:
+ en_US: "@sw_mug_translation"
+ updatedAt: "<(new \\DateTime('2015-10-10'))>"
+ channelPricings:
+ WEB: "@sw_mug_web_channel_pricing"
+ mug_lotr:
+ code: "MUG_LOTR"
+ product: "@mug"
+ currentLocale: "en_US"
+ translations:
+ en_US: "@lotr_mug_translation"
+ updatedAt: "<(new \\DateTime('2015-10-04'))>"
+ channelPricings:
+ WEB: "@lotr_mug_web_channel_pricing"
+
+Sylius\Component\Product\Model\ProductVariantTranslation:
+ sw_mug_translation:
+ locale: "en_US"
+ name: "Star wars mug"
+ translatable: "@mug_sw"
+ lotr_mug_translation:
+ locale: "en_US"
+ name: "Lotr mug"
+ translatable: "@mug_lotr"
+
+Sylius\Component\Core\Model\Channel:
+ channel_web:
+ code: "WEB"
+ name: "Web Channel"
+ hostname: "localhost"
+ description: "Lorem ipsum"
+ baseCurrency: "@currency"
+ defaultLocale: "@locale"
+ locales: ["@locale"]
+ color: "black"
+ enabled: true
+ taxCalculationStrategy: "order_items_based"
+
+Sylius\Component\Currency\Model\Currency:
+ currency:
+ code: "USD"
+
+Sylius\Component\Locale\Model\Locale:
+ locale:
+ code: "en_US"
+
+Sylius\Component\Core\Model\Customer:
+ customer_oliver:
+ firstName: "Oliver"
+ lastName: "Queen"
+ email: "oliver.queen@star-city.com"
+ emailCanonical: "oliver.queen@star-city.com"
+ birthday: "<(new \\DateTime())>"
+
+Sylius\Component\Core\Model\ChannelPricing:
+ sw_mug_web_channel_pricing:
+ channelCode: "WEB"
+ price: 20
+ lotr_mug_web_channel_pricing:
+ channelCode: "WEB"
+ price: 20
+
+Sylius\Component\Core\Model\PaymentMethod:
+ paypal:
+ code: PAYPAL
+ enabled: true
+ gatewayConfig: "@paypal_config"
+ currentLocale: en_US
+ translations:
+ - "@paypal_translation"
+ channels: ["@channel_web"]
+
+Sylius\Bundle\PayumBundle\Model\GatewayConfig:
+ paypal_config:
+ gatewayName: "paypal"
+ factoryName: "sylius.pay_pal"
+ config:
+ client_id: "CLIENT_ID"
+ client_secret: "CLIENT_SECRET"
+ merchant_id: "MERCHANT_ID"
+ sylius_merchant_id: "SYLIUS_MERCHANT_ID"
+ partner_attribution_id: "PARTNER_ATTRIBUTION_ID"
+ use_authorize: true
+
+Sylius\Component\Payment\Model\PaymentMethodTranslation:
+ paypal_translation:
+ name: "PayPal"
+ locale: "en_US"
+ description:
+ translatable: "@paypal"
diff --git a/tests/Functional/CreatePayPalOrderActionTest.php b/tests/Functional/CreatePayPalOrderActionTest.php
new file mode 100644
index 00000000..f05cb13a
--- /dev/null
+++ b/tests/Functional/CreatePayPalOrderActionTest.php
@@ -0,0 +1,24 @@
+loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_order.yaml']);
+
+ $this->client->request('POST', '/en_US/create-pay-pal-order/TOKEN');
+
+ $response = $this->client->getResponse();
+ $content = (array) json_decode($response->getContent(), true);
+
+ $this->assertSame($content['orderID'], 'PAYPAL_ORDER_ID');
+ $this->assertSame($content['status'], 'processing');
+ }
+}
diff --git a/tests/Functional/CreatePayPalOrderFromCartActionTest.php b/tests/Functional/CreatePayPalOrderFromCartActionTest.php
new file mode 100644
index 00000000..e70ed642
--- /dev/null
+++ b/tests/Functional/CreatePayPalOrderFromCartActionTest.php
@@ -0,0 +1,27 @@
+loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_cart.yaml']);
+ /** @var int $orderId */
+ $orderId = $order['new_cart']->getId();
+
+ $this->client->request('POST', '/en_US/create-pay-pal-order-from-cart/' . $orderId);
+
+ $response = $this->client->getResponse();
+ $content = (array) json_decode($response->getContent(), true);
+
+ $this->assertSame($content['id'], $orderId);
+ $this->assertSame($content['orderID'], 'PAYPAL_ORDER_ID');
+ $this->assertSame($content['status'], 'cart');
+ }
+}
diff --git a/tests/Functional/CreatePayPalOrderFromPaymentPageActionTest.php b/tests/Functional/CreatePayPalOrderFromPaymentPageActionTest.php
new file mode 100644
index 00000000..35ec88c2
--- /dev/null
+++ b/tests/Functional/CreatePayPalOrderFromPaymentPageActionTest.php
@@ -0,0 +1,25 @@
+loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_cart.yaml']);
+ /** @var int $orderId */
+ $orderId = $order['new_cart']->getId();
+
+ $this->client->request('POST', '/en_US/pay-pal-order-payment-page/' . $orderId . '/create');
+
+ $response = $this->client->getResponse();
+ $content = (array) json_decode($response->getContent(), true);
+
+ $this->assertSame($content['order_id'], 'PAYPAL_ORDER_ID');
+ }
+}
diff --git a/tests/Behat/Service/DummyAuthorizeClientApi.php b/tests/Service/DummyAuthorizeClientApi.php
similarity index 84%
rename from tests/Behat/Service/DummyAuthorizeClientApi.php
rename to tests/Service/DummyAuthorizeClientApi.php
index f2ed3763..130d7593 100644
--- a/tests/Behat/Service/DummyAuthorizeClientApi.php
+++ b/tests/Service/DummyAuthorizeClientApi.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface;
diff --git a/tests/Behat/Service/DummyOrderDetailsApi.php b/tests/Service/DummyOrderDetailsApi.php
similarity index 87%
rename from tests/Behat/Service/DummyOrderDetailsApi.php
rename to tests/Service/DummyOrderDetailsApi.php
index b3420ddb..47447c67 100644
--- a/tests/Behat/Service/DummyOrderDetailsApi.php
+++ b/tests/Service/DummyOrderDetailsApi.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\PayPalPlugin\Api\OrderDetailsApiInterface;
diff --git a/tests/Behat/Service/DummyPayPalRefundDataProvider.php b/tests/Service/DummyPayPalRefundDataProvider.php
similarity index 85%
rename from tests/Behat/Service/DummyPayPalRefundDataProvider.php
rename to tests/Service/DummyPayPalRefundDataProvider.php
index f1c30e34..1b373b67 100644
--- a/tests/Behat/Service/DummyPayPalRefundDataProvider.php
+++ b/tests/Service/DummyPayPalRefundDataProvider.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\PayPalPlugin\Provider\PayPalRefundDataProviderInterface;
diff --git a/tests/Behat/Service/DummyPayoutsReportDownloader.php b/tests/Service/DummyPayoutsReportDownloader.php
similarity index 90%
rename from tests/Behat/Service/DummyPayoutsReportDownloader.php
rename to tests/Service/DummyPayoutsReportDownloader.php
index bbdbc196..65c47560 100644
--- a/tests/Behat/Service/DummyPayoutsReportDownloader.php
+++ b/tests/Service/DummyPayoutsReportDownloader.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\PayPalPlugin\Downloader\PayoutsReportDownloaderInterface;
diff --git a/tests/Behat/Service/DummyRefundPaymentApi.php b/tests/Service/DummyRefundPaymentApi.php
similarity index 89%
rename from tests/Behat/Service/DummyRefundPaymentApi.php
rename to tests/Service/DummyRefundPaymentApi.php
index c913acde..6a22b9c0 100644
--- a/tests/Behat/Service/DummyRefundPaymentApi.php
+++ b/tests/Service/DummyRefundPaymentApi.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\PayPalPlugin\Api\RefundPaymentApiInterface;
diff --git a/tests/Service/FakeCreateOrderApi.php b/tests/Service/FakeCreateOrderApi.php
new file mode 100644
index 00000000..92251900
--- /dev/null
+++ b/tests/Service/FakeCreateOrderApi.php
@@ -0,0 +1,16 @@
+ 'PAYPAL_ORDER_ID', 'status' => 'CREATED'];
+ }
+}
diff --git a/tests/Behat/Service/VoidPayPalPaymentCompleteProcessor.php b/tests/Service/VoidPayPalPaymentCompleteProcessor.php
similarity index 88%
rename from tests/Behat/Service/VoidPayPalPaymentCompleteProcessor.php
rename to tests/Service/VoidPayPalPaymentCompleteProcessor.php
index 3c60b85a..059849d9 100644
--- a/tests/Behat/Service/VoidPayPalPaymentCompleteProcessor.php
+++ b/tests/Service/VoidPayPalPaymentCompleteProcessor.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\PayPalPlugin\Behat\Service;
+namespace Tests\Sylius\PayPalPlugin\Service;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\PayPalPlugin\Processor\PaymentCompleteProcessorInterface;