1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\FluxSE\PayumStripe\Action\StripeCheckoutSession; |
4
|
|
|
|
5
|
|
|
use FluxSE\PayumStripe\Action\StripeCheckoutSession\CancelAction; |
6
|
|
|
use FluxSE\PayumStripe\Request\Api\Resource\AllSession; |
7
|
|
|
use FluxSE\PayumStripe\Request\Api\Resource\ExpireSession; |
8
|
|
|
use Payum\Core\Action\ActionInterface; |
9
|
|
|
use Payum\Core\Request\Authorize; |
10
|
|
|
use Payum\Core\Request\Cancel; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Stripe\Checkout\Session; |
13
|
|
|
use Stripe\Collection; |
14
|
|
|
use Tests\FluxSE\PayumStripe\Action\GatewayAwareTestTrait; |
15
|
|
|
|
16
|
|
|
final class CancelActionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
use GatewayAwareTestTrait; |
19
|
|
|
|
20
|
|
|
public function testShouldImplements(): void |
21
|
|
|
{ |
22
|
|
|
$action = new CancelAction(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf(ActionInterface::class, $action); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testShouldSupportOnlyCaptureAndArrayAccessModelWithCaptureMethodAutomatic(): void |
28
|
|
|
{ |
29
|
|
|
$action = new CancelAction(); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($action->supports(new Cancel(['capture_method' => 'automatic']))); |
32
|
|
|
$this->assertFalse($action->supports(new Cancel(['capture_method' => 'manual']))); |
33
|
|
|
$this->assertFalse($action->supports(new Cancel([]))); |
34
|
|
|
$this->assertFalse($action->supports(new Cancel(null))); |
35
|
|
|
$this->assertFalse($action->supports(new Authorize(['capture_method' => 'manual']))); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDoesNothingForNotACheckoutSession(): void |
39
|
|
|
{ |
40
|
|
|
$request = new Cancel(['capture_method' => 'automatic', 'id' => 'pi_abc123']); |
41
|
|
|
$action = new CancelAction(); |
42
|
|
|
|
43
|
|
|
$allSessionRequest = new AllSession(['payment_intent' => 'pi_abc123']); |
44
|
|
|
$gatewayMock = $this->createGatewayMock(); |
45
|
|
|
$gatewayMock |
46
|
|
|
->expects($this->once()) |
|
|
|
|
47
|
|
|
->method('execute') |
48
|
|
|
->with($allSessionRequest) |
49
|
|
|
->willReturn( |
50
|
|
|
$this->returnCallback( |
51
|
|
|
function (AllSession $request) { |
52
|
|
|
$sessions = Collection::emptyCollection(); |
53
|
|
|
$request->setApiResources($sessions); |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$action->setGateway($gatewayMock); |
60
|
|
|
$action->execute($request); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testDoesNothingForNotAnOpenedCheckoutSession(): void |
64
|
|
|
{ |
65
|
|
|
$request = new Cancel(['capture_method' => 'automatic', 'id' => 'pi_abc123']); |
66
|
|
|
$action = new CancelAction(); |
67
|
|
|
|
68
|
|
|
$allSessionRequest = new AllSession(['payment_intent' => 'pi_abc123']); |
69
|
|
|
$gatewayMock = $this->createGatewayMock(); |
70
|
|
|
$gatewayMock |
71
|
|
|
->expects($this->once()) |
72
|
|
|
->method('execute') |
73
|
|
|
->with($allSessionRequest) |
74
|
|
|
->willReturn( |
75
|
|
|
$this->returnCallback( |
76
|
|
|
function (AllSession $request) { |
77
|
|
|
$sessions = Collection::constructFrom( |
78
|
|
|
[ |
79
|
|
|
'data' => [ |
80
|
|
|
[ |
81
|
|
|
'id' => 'cs_1', |
82
|
|
|
'object' => Session::OBJECT_NAME, |
83
|
|
|
'status' => Session::STATUS_COMPLETE, |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
] |
87
|
|
|
); |
88
|
|
|
$request->setApiResources($sessions); |
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$action->setGateway($gatewayMock); |
95
|
|
|
$action->execute($request); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testExpiresAnOpenedCheckoutSession(): void |
99
|
|
|
{ |
100
|
|
|
$request = new Cancel(['capture_method' => 'automatic', 'id' => 'pi_abc123']); |
101
|
|
|
$action = new CancelAction(); |
102
|
|
|
|
103
|
|
|
$gatewayMock = $this->createGatewayMock(); |
104
|
|
|
$gatewayMock |
105
|
|
|
->expects($this->exactly(2)) |
106
|
|
|
->method('execute') |
107
|
|
|
->withConsecutive( |
108
|
|
|
[ |
109
|
|
|
$this->callback( |
110
|
|
|
function (AllSession $request): bool { |
111
|
|
|
$this->assertSame(['payment_intent' => 'pi_abc123'], $request->getParameters()); |
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
), |
115
|
|
|
], |
116
|
|
|
[new ExpireSession('cs_1')] |
117
|
|
|
) |
118
|
|
|
->willReturnOnConsecutiveCalls( |
119
|
|
|
$this->returnCallback( |
120
|
|
|
function (AllSession $request) { |
121
|
|
|
$sessions = Collection::constructFrom( |
122
|
|
|
[ |
123
|
|
|
'data' => [ |
124
|
|
|
[ |
125
|
|
|
'id' => 'cs_1', |
126
|
|
|
'object' => Session::OBJECT_NAME, |
127
|
|
|
'status' => Session::STATUS_OPEN, |
128
|
|
|
], |
129
|
|
|
], |
130
|
|
|
] |
131
|
|
|
); |
132
|
|
|
$request->setApiResources($sessions); |
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
), |
136
|
|
|
$this->anything() |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$action->setGateway($gatewayMock); |
140
|
|
|
$action->execute($request); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.