Skip to content

Commit c5401dc

Browse files
committed
init behat tests for checkout
1 parent d934821 commit c5401dc

15 files changed

+274
-285
lines changed

behat.yml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default:
77
FriendsOfBehat\ContextServiceExtension:
88
imports:
99
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
10-
- tests/Behat/Resources/services.xml
10+
- tests/Behat/Resources/services.yml
1111

1212
FriendsOfBehat\SymfonyExtension:
1313
kernel:

features/dynamically_greeting_a_customer.feature

-17
This file was deleted.

features/running_a_sylius_feature.feature

-54
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@paying_with_ht_payway_offsite_for_order
2+
Feature: Paying with Mollie during checkout
3+
In order to buy products
4+
As a Customer
5+
I want to be able to pay with Mollie
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And there is a user "john@locastic.com" identified by "password123"
10+
And the store has a payment method "HT PayWay Offsite" with a code "ht_payway_offsite" and HT PayWay Offsite payment gateway
11+
And the store has a product "PHP T-Shirt" priced at "€19.99"
12+
And the store ships everywhere for free
13+
And I am logged in as "john@locastic.com"
14+
15+
@ui @javascript
16+
Scenario: Successful payment
17+
Given I added product "PHP T-Shirt" to the cart
18+
And I have proceeded selecting "HT PayWay Offsite" payment method
19+
When I confirm my order with HT PayWay Offsite payment
20+
# And I sign in to HT PayWay Offsite and pay successfully
21+
# Then I should be notified that my payment has been completed

features/statically_greeting_a_customer.feature

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Tests\Locastic\SyliusHTPayWayPlugin\Behat\Context\Setup;
4+
5+
use Behat\Behat\Context\Context;
6+
use Locastic\SyliusHTPayWayPlugin\HTPayWayOffsiteGatewayFactory;
7+
use Sylius\Component\Core\Model\PaymentMethodInterface;
8+
use Doctrine\Common\Persistence\ObjectManager;
9+
use Sylius\Behat\Service\SharedStorageInterface;
10+
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
11+
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
12+
use Sylius\Component\Resource\Factory\FactoryInterface;
13+
14+
final class HTPayWayOffsiteContext implements Context
15+
{
16+
private $sharedStorage;
17+
18+
private $paymentMethodRepository;
19+
20+
private $paymentMethodExampleFactory;
21+
22+
private $paymentMethodTranslationFactory;
23+
24+
private $paymentMethodManager;
25+
26+
public function __construct(
27+
SharedStorageInterface $sharedStorage,
28+
PaymentMethodRepositoryInterface $paymentMethodRepository,
29+
ExampleFactoryInterface $paymentMethodExampleFactory,
30+
FactoryInterface $paymentMethodTranslationFactory,
31+
ObjectManager $paymentMethodManager
32+
) {
33+
$this->sharedStorage = $sharedStorage;
34+
$this->paymentMethodRepository = $paymentMethodRepository;
35+
$this->paymentMethodExampleFactory = $paymentMethodExampleFactory;
36+
$this->paymentMethodTranslationFactory = $paymentMethodTranslationFactory;
37+
$this->paymentMethodManager = $paymentMethodManager;
38+
}
39+
40+
/**
41+
* @Given the store has a payment method :paymentMethodName with a code :paymentMethodCode and HT PayWay Offsite payment gateway
42+
*/
43+
public function theStoreHasAPaymentMethodWithACodeAndHtPaywayOffsitePaymentGateway(
44+
string $paymentMethodName,
45+
string $paymentMethodCode
46+
): void {
47+
$paymentMethod = $this->createPaymentMethodHTPayWayOffsite(
48+
$paymentMethodName,
49+
$paymentMethodCode,
50+
HTPayWayOffsiteGatewayFactory::FACTORY_NAME,
51+
'HT PayWay Offiste'
52+
);
53+
54+
$paymentMethod->getGatewayConfig()->setConfig(
55+
[
56+
'shop_id' => 'test_shop_id',
57+
'secret_key' => 'test_key',
58+
]
59+
);
60+
61+
$this->paymentMethodManager->flush();
62+
}
63+
64+
private function createPaymentMethodHTPayWayOffsite(
65+
string $name,
66+
string $code,
67+
string $factoryName,
68+
string $description = '',
69+
bool $addForCurrentChannel = true,
70+
int $position = null
71+
): PaymentMethodInterface {
72+
73+
/** @var PaymentMethodInterface $paymentMethod */
74+
$paymentMethod = $this->paymentMethodExampleFactory->create(
75+
[
76+
'name' => ucfirst($name),
77+
'code' => $code,
78+
'description' => $description,
79+
'gatewayName' => $factoryName,
80+
'gatewayFactory' => $factoryName,
81+
'enabled' => true,
82+
'channels' => ($addForCurrentChannel && $this->sharedStorage->has(
83+
'channel'
84+
)) ? [$this->sharedStorage->get('channel')] : [],
85+
]
86+
);
87+
if (null !== $position) {
88+
$paymentMethod->setPosition($position);
89+
}
90+
91+
$this->sharedStorage->set('payment_method', $paymentMethod);
92+
$this->paymentMethodRepository->add($paymentMethod);
93+
94+
return $paymentMethod;
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Tests\Locastic\SyliusHTPayWayPlugin\Behat\Context\Ui\Shop;
4+
5+
6+
use Behat\Behat\Context\Context;
7+
use Tests\Locastic\SyliusHTPayWayPlugin\Behat\Mocker\HTPayWayOffsiteMocker;
8+
use Sylius\Behat\Page\Shop\Checkout\CompletePage;
9+
10+
final class CheckoutContext implements Context
11+
{
12+
private $HTPayWayOffsiteMocker;
13+
14+
private $completePage;
15+
16+
/**
17+
* CheckoutContext constructor.
18+
* @param HTPayWayOffsiteMocker $HTPayWayOffsiteMocker
19+
*/
20+
public function __construct(HTPayWayOffsiteMocker $HTPayWayOffsiteMocker, CompletePage $completePage)
21+
{
22+
$this->HTPayWayOffsiteMocker = $HTPayWayOffsiteMocker;
23+
$this->completePage = $completePage;
24+
}
25+
26+
/**
27+
* @When I confirm my order with HT PayWay Offsite payment
28+
*/
29+
public function iConfirmMyOrderWithHtPaywayOffsitePayment()
30+
{
31+
$this->HTPayWayOffsiteMocker->mockApiCreatePayment(
32+
function () {
33+
$this->completePage->confirmOrder();
34+
}
35+
);
36+
}
37+
}

tests/Behat/Context/Ui/Shop/WelcomeContext.php

-80
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Tests\Locastic\SyliusHTPayWayPlugin\Behat\Mocker;
4+
5+
use Locastic\TcomPayWay\AuthorizeForm\Model\Payment;
6+
7+
use Sylius\Behat\Service\Mocker\MockerInterface;
8+
9+
final class HTPayWayOffsiteMocker
10+
{
11+
12+
private $mocker;
13+
14+
public function __construct(MockerInterface $mocker)
15+
{
16+
$this->mocker = $mocker;
17+
}
18+
19+
public function mockApiCreatePayment(callable $action): void
20+
{
21+
$payment = \Mockery::mock('payment');
22+
23+
$payment->id = 1;
24+
25+
$payment
26+
->shouldReceive('getPaymentUrl')
27+
->andReturn('');
28+
29+
$payments = \Mockery::mock('payments');
30+
31+
$payments
32+
->shouldReceive('create')
33+
->andReturn($payment);
34+
35+
// $mock = $this->mocker->mockCollaborator(Payment::class);
36+
37+
// $mock
38+
// ->shouldReceive('setApiKey');
39+
//
40+
// $mock
41+
// ->shouldReceive('isRecurringSubscription')
42+
// ->andReturn(false);
43+
//
44+
// $mock->payments = $payments;
45+
46+
$action();
47+
48+
$this->mocker->unmockAll();
49+
}
50+
51+
}

0 commit comments

Comments
 (0)