1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace spec\BitBag\SyliusMolliePlugin\Action; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Action\ConvertPaymentAction; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Client\MollieApiClient; |
17
|
|
|
use Payum\Core\Action\ActionInterface; |
18
|
|
|
use Payum\Core\GatewayInterface; |
19
|
|
|
use Payum\Core\Request\Convert; |
20
|
|
|
use PhpSpec\ObjectBehavior; |
21
|
|
|
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface; |
22
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
23
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
24
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
25
|
|
|
|
26
|
|
|
final class ConvertPaymentActionSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(PaymentDescriptionProviderInterface $paymentDescriptionProvider): void |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($paymentDescriptionProvider); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable(): void |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType(ConvertPaymentAction::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_action_interface(): void |
39
|
|
|
{ |
40
|
|
|
$this->shouldHaveType(ActionInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_executes( |
44
|
|
|
Convert $request, |
45
|
|
|
PaymentInterface $payment, |
46
|
|
|
OrderInterface $order, |
47
|
|
|
CustomerInterface $customer, |
48
|
|
|
GatewayInterface $gateway, |
49
|
|
|
MollieApiClient $mollieApiClient, |
50
|
|
|
PaymentDescriptionProviderInterface $paymentDescriptionProvider |
51
|
|
|
): void { |
52
|
|
|
$mollieApiClient->isRecurringSubscription()->willReturn(false); |
53
|
|
|
$this->setApi($mollieApiClient); |
|
|
|
|
54
|
|
|
$this->setGateway($gateway); |
|
|
|
|
55
|
|
|
$customer->getFullName()->willReturn('Jan Kowalski'); |
56
|
|
|
$customer->getEmail()->willReturn('[email protected]'); |
57
|
|
|
$customer->getId()->willReturn(1); |
58
|
|
|
$order->getId()->willReturn(1); |
59
|
|
|
$order->getLocaleCode()->willReturn('pl_PL'); |
60
|
|
|
$order->getCustomer()->willReturn($customer); |
|
|
|
|
61
|
|
|
$payment->getOrder()->willReturn($order); |
|
|
|
|
62
|
|
|
$payment->getAmount()->willReturn(445535); |
63
|
|
|
$payment->getCurrencyCode()->willReturn('EUR'); |
64
|
|
|
$paymentDescriptionProvider->getPaymentDescription($payment)->willReturn('description'); |
65
|
|
|
$request->getSource()->willReturn($payment); |
66
|
|
|
$request->getTo()->willReturn('array'); |
67
|
|
|
|
68
|
|
|
$request->setResult([ |
|
|
|
|
69
|
|
|
'amount' => [ |
70
|
|
|
'value' => '445535', |
71
|
|
|
'currency' => 'EUR', |
72
|
|
|
], |
73
|
|
|
'description' => 'description', |
74
|
|
|
'locale' => 'en_US', |
75
|
|
|
'metadata' => [ |
76
|
|
|
'order_id' => 1, |
77
|
|
|
'customer_id' => 1, |
78
|
|
|
], |
79
|
|
|
'full_name' => 'Jan Kowalski', |
80
|
|
|
'email' => '[email protected]', |
81
|
|
|
])->shouldBeCalled(); |
82
|
|
|
|
83
|
|
|
$this->execute($request); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function it_supports_only_convert_request_payment_source_and_array_to( |
87
|
|
|
Convert $request, |
88
|
|
|
PaymentInterface $payment |
89
|
|
|
): void { |
90
|
|
|
$request->getSource()->willReturn($payment); |
91
|
|
|
$request->getTo()->willReturn('array'); |
92
|
|
|
|
93
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.