-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCaptureActionTest.php
148 lines (120 loc) · 4 KB
/
CaptureActionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
declare(strict_types=1);
namespace Ekyna\Component\Payum\Payzen\Tests\Action;
use Ekyna\Component\Payum\Payzen\Action\CaptureAction;
use Ekyna\Component\Payum\Payzen\Request\Request;
use Payum\Core\Request\Capture;
use Payum\Core\Request\Sync;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\TokenInterface;
use PHPUnit\Framework\Constraint\IsInstanceOf;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Class CaptureActionTest
* @package Ekyna\Component\Payum\Payzen\Tests\Action
* @author Étienne Dauvergne <contact@ekyna.com>
*/
class CaptureActionTest extends AbstractActionTest
{
protected $requestClass = Capture::class;
protected $actionClass = CaptureAction::class;
/**
* @test
*/
public function should_set_vads_urls_if_request_has_token(): void
{
$assert = function(Request $request) {
$model = $request->getModel();
$fields = [
'vads_url_cancel',
'vads_url_error',
'vads_url_referral',
'vads_url_refused',
'vads_url_success',
'vads_url_return',
];
foreach ($fields as $field) {
$this->assertEquals('https://exmaple.org/return', $model[$field]);
}
};
$gateway = $this->createGatewayMock();
$gateway
->expects(self::at(0))
->method('execute')
->with(new IsInstanceOf(Request::class))
->willReturnCallback($assert);
$action = new CaptureAction();
$action->setGateway($gateway);
$request = new Capture($this->mockToken());
$request->setModel([]);
$action->execute($request);
}
/**
* @test
*/
public function should_set_vad_url_check_if_token_factory_is_available(): void
{
$assert = function(Request $request) {
$model = $request->getModel();
$this->assertEquals('https://exmaple.org/notify', $model['vads_url_check']);
};
$token = $this->createMock(TokenInterface::class);
$token
->expects(self::once())
->method('getTargetUrl')
->willReturn('https://exmaple.org/notify');
$tokenFactory = $this->createMock(GenericTokenFactoryInterface::class);
$tokenFactory
->expects(self::once())
->method('createNotifyToken')
->with('payzen', [])
->willReturn($token);
$gateway = $this->createGatewayMock();
$gateway
->expects(self::at(0))
->method('execute')
->with(new IsInstanceOf(Request::class))
->willReturnCallback($assert);
$action = new CaptureAction();
$action->setGateway($gateway);
$action->setGenericTokenFactory($tokenFactory);
$request = new Capture($this->mockToken());
$request->setModel([]);
$action->execute($request);
}
/**
* @test
*/
public function should_not_execute_api_request_if_trans_id_is_set(): void
{
$gateway = $this->createGatewayMock();
$gateway
->expects(self::at(0))
->method('execute')
->with(new IsInstanceOf(Sync::class));
$action = new CaptureAction();
$action->setGateway($gateway);
$request = new Capture($this->mockToken());
$request->setModel([
'vads_trans_id' => '1',
]);
$action->execute($request);
}
private function mockToken(): MockObject
{
$token = $this->createMock(TokenInterface::class);
$token
->expects(self::once())
->method('getTargetUrl')
->willReturn('https://exmaple.org/return');
$token
->expects(self::any())
->method('getGatewayName')
->willReturn('payzen');
$token
->expects(self::any())
->method('getDetails')
->willReturn([]);
return $token;
}
}