|
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\CaptureAction; |
|
16
|
|
|
use BitBag\SyliusMolliePlugin\Client\MollieApiClient; |
|
17
|
|
|
use Mollie\Api\Endpoints\PaymentEndpoint; |
|
18
|
|
|
use Payum\Core\Action\ActionInterface; |
|
19
|
|
|
use Payum\Core\ApiAwareInterface; |
|
20
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
|
21
|
|
|
use Payum\Core\GatewayAwareInterface; |
|
22
|
|
|
use Payum\Core\GatewayInterface; |
|
23
|
|
|
use Payum\Core\Payum; |
|
24
|
|
|
use Payum\Core\Reply\HttpRedirect; |
|
25
|
|
|
use Payum\Core\Request\Capture; |
|
26
|
|
|
use Payum\Core\Security\GenericTokenFactory; |
|
27
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareInterface; |
|
28
|
|
|
use Payum\Core\Security\TokenInterface; |
|
29
|
|
|
use PhpSpec\ObjectBehavior; |
|
30
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
31
|
|
|
|
|
32
|
|
|
final class CaptureActionSpec extends ObjectBehavior |
|
33
|
|
|
{ |
|
34
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldHaveType(CaptureAction::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_action_interface(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldHaveType(ActionInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_implements_generic_token_factory_aware(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->shouldHaveType(GenericTokenFactoryAwareInterface::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_implements_api_aware_interface(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->shouldHaveType(ApiAwareInterface::class); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_implements_gateway_aware_interface(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->shouldHaveType(GatewayAwareInterface::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function it_executes( |
|
60
|
|
|
Capture $request, |
|
61
|
|
|
ArrayObject $arrayObject, |
|
62
|
|
|
PaymentInterface $payment, |
|
63
|
|
|
TokenInterface $token, |
|
64
|
|
|
TokenInterface $notifyToken, |
|
65
|
|
|
Payum $payum, |
|
66
|
|
|
GenericTokenFactory $genericTokenFactory, |
|
67
|
|
|
GatewayInterface $gateway, |
|
68
|
|
|
MollieApiClient $mollieApiClient, |
|
69
|
|
|
PaymentEndpoint $paymentEndpoint |
|
70
|
|
|
): void { |
|
71
|
|
|
$this->setGateway($gateway); |
|
|
|
|
|
|
72
|
|
|
$mollieApiClient->isRecurringSubscription()->willReturn(false); |
|
73
|
|
|
$this->setApi($mollieApiClient); |
|
|
|
|
|
|
74
|
|
|
$notifyToken->getTargetUrl()->willReturn('url'); |
|
75
|
|
|
$notifyToken->getHash()->willReturn('test'); |
|
76
|
|
|
$token->getTargetUrl()->willReturn('url'); |
|
77
|
|
|
$token->getAfterUrl()->willReturn('url'); |
|
78
|
|
|
$token->getGatewayName()->willReturn('test'); |
|
79
|
|
|
$token->getDetails()->willReturn([]); |
|
80
|
|
|
$token->getHash()->willReturn('test'); |
|
81
|
|
|
$genericTokenFactory->createNotifyToken('test', [])->willReturn($notifyToken); |
|
|
|
|
|
|
82
|
|
|
$genericTokenFactory->createRefundToken('test', [])->willReturn($notifyToken); |
|
83
|
|
|
$this->setGenericTokenFactory($genericTokenFactory); |
|
|
|
|
|
|
84
|
|
|
$payum->getTokenFactory()->willReturn($genericTokenFactory); |
|
|
|
|
|
|
85
|
|
|
$arrayObject->toUnsafeArray()->willReturn([]); |
|
86
|
|
|
$request->getModel()->willReturn($arrayObject); |
|
87
|
|
|
$request->getFirstModel()->willReturn($payment); |
|
88
|
|
|
$request->getToken()->willReturn($token); |
|
89
|
|
|
$payment = \Mockery::mock('payment'); |
|
90
|
|
|
$payment->id = 1; |
|
|
|
|
|
|
91
|
|
|
$payment->shouldReceive('getCheckoutUrl')->andReturn('https://thisisnotanemptyurl.com'); |
|
92
|
|
|
$paymentEndpoint->create([ |
|
93
|
|
|
'amount' => null, |
|
94
|
|
|
'description' => null, |
|
95
|
|
|
'redirectUrl' => 'url', |
|
96
|
|
|
'webhookUrl' => null, |
|
97
|
|
|
'metadata' => null, |
|
98
|
|
|
])->willReturn($payment); |
|
|
|
|
|
|
99
|
|
|
$mollieApiClient->payments = $paymentEndpoint; |
|
100
|
|
|
|
|
101
|
|
|
$arrayObject->offsetGet('description')->shouldBeCalled(); |
|
102
|
|
|
$arrayObject->offsetGet('webhookUrl')->shouldBeCalled(); |
|
103
|
|
|
$arrayObject->offsetGet('amount')->shouldBeCalled(); |
|
104
|
|
|
$arrayObject->offsetExists('subscription_mollie_id')->shouldBeCalled(); |
|
105
|
|
|
$arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled(); |
|
106
|
|
|
$arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled(); |
|
107
|
|
|
$arrayObject->offsetGet('metadata')->shouldBeCalled(); |
|
108
|
|
|
$arrayObject->offsetSet('metadata', ['refund_token' => 'test'])->shouldBeCalled(); |
|
|
|
|
|
|
109
|
|
|
$arrayObject->offsetSet('payment_mollie_id', 1)->shouldBeCalled(); |
|
|
|
|
|
|
110
|
|
|
$arrayObject->offsetSet('webhookUrl', 'url')->shouldBeCalled(); |
|
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
$this |
|
113
|
|
|
->shouldThrow(HttpRedirect::class) |
|
114
|
|
|
->during('execute', [$request]) |
|
115
|
|
|
; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
function it_supports_only_capture_request_and_array_access( |
|
119
|
|
|
Capture $request, |
|
120
|
|
|
\ArrayAccess $arrayAccess |
|
121
|
|
|
): void { |
|
122
|
|
|
$request->getModel()->willReturn($arrayAccess); |
|
123
|
|
|
|
|
124
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
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.