1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\MShop\Service\Provider\Decorator; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
8
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
9
|
|
|
*/ |
10
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
11
|
|
|
{ |
12
|
|
|
private $mock; |
13
|
|
|
private $object; |
14
|
|
|
private $context; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->context = \TestHelperMShop::getContext(); |
20
|
|
|
|
21
|
|
|
$servManager = \Aimeos\MShop\Service\Manager\Factory::createManager( $this->context ); |
22
|
|
|
$search = $servManager->createSearch(); |
23
|
|
|
$search->setConditions($search->compare('==', 'service.provider', 'Standard')); |
24
|
|
|
$result = $servManager->searchItems($search, array('price')); |
25
|
|
|
|
26
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
27
|
|
|
throw new \RuntimeException( 'No order base item found' ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$this->mock = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Payment\\PrePay' ) |
31
|
|
|
->setConstructorArgs( array( $this->context, $item ) ) |
32
|
|
|
->setMethods( array( 'calcPrice', 'checkConfigBE', 'checkConfigFE', 'getConfigBE', |
33
|
|
|
'getConfigFE', 'injectGlobalConfigBE', 'isAvailable', 'isImplemented', 'query', |
34
|
|
|
'cancel', 'capture', 'process', 'refund', 'setCommunication', 'setConfigFE', |
35
|
|
|
'updateAsync', 'updatePush', 'updateSync' ) ) |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$this->object = new TestBase( $this->mock, $this->context, $item ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tears down the fixture, for example, closes a network connection. |
44
|
|
|
* This method is called after a test is executed. |
45
|
|
|
* |
46
|
|
|
* @access protected |
47
|
|
|
*/ |
48
|
|
|
protected function tearDown() |
49
|
|
|
{ |
50
|
|
|
unset( $this->object ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testCalcPrice() |
55
|
|
|
{ |
56
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->getSubManager( 'base' )->createItem(); |
57
|
|
|
|
58
|
|
|
$this->mock->expects( $this->once() )->method( 'calcPrice' )->will( $this->returnValue( $item->getPrice() ) ); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Price\\Item\\Iface', $this->object->calcPrice( $item ) ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testCheckConfigBE() |
65
|
|
|
{ |
66
|
|
|
$this->mock->expects( $this->once() )->method( 'checkConfigBE' )->will( $this->returnValue( [] ) ); |
67
|
|
|
|
68
|
|
|
$this->assertEquals( [], $this->object->checkConfigBE( [] ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testCheckConfigFE() |
73
|
|
|
{ |
74
|
|
|
$this->mock->expects( $this->once() )->method( 'checkConfigFE' )->will( $this->returnValue( [] ) ); |
75
|
|
|
|
76
|
|
|
$this->assertEquals( [], $this->object->checkConfigFE( [] ) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testGetConfigBE() |
81
|
|
|
{ |
82
|
|
|
$this->mock->expects( $this->once() )->method( 'getConfigBE' )->will( $this->returnValue( [] ) ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( [], $this->object->getConfigBE() ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testGetConfigFE() |
89
|
|
|
{ |
90
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->getSubManager( 'base' )->createItem(); |
91
|
|
|
|
92
|
|
|
$this->mock->expects( $this->once() )->method( 'getConfigFE' )->will( $this->returnValue( [] ) ); |
93
|
|
|
|
94
|
|
|
$this->assertEquals( [], $this->object->getConfigFE( $item ) ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testInjectGlobalConfigBE() |
99
|
|
|
{ |
100
|
|
|
$this->mock->expects( $this->once() )->method( 'injectGlobalConfigBE' ); |
101
|
|
|
|
102
|
|
|
$this->object->injectGlobalConfigBE( [] ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testIsAvailable() |
107
|
|
|
{ |
108
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->getSubManager( 'base' )->createItem(); |
109
|
|
|
|
110
|
|
|
$this->mock->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) ); |
111
|
|
|
|
112
|
|
|
$this->assertEquals( true, $this->object->isAvailable( $item ) ); |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testIsImplemented() |
117
|
|
|
{ |
118
|
|
|
$this->mock->expects( $this->once() )->method( 'isImplemented' )->will( $this->returnValue( true ) ); |
119
|
|
|
|
120
|
|
|
$this->assertTrue( $this->object->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_QUERY ) ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testCancel() |
125
|
|
|
{ |
126
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
127
|
|
|
|
128
|
|
|
$this->mock->expects( $this->once() )->method( 'cancel' ); |
129
|
|
|
|
130
|
|
|
$this->object->cancel( $item ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testCapture() |
135
|
|
|
{ |
136
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
137
|
|
|
|
138
|
|
|
$this->mock->expects( $this->once() )->method( 'capture' ); |
139
|
|
|
|
140
|
|
|
$this->object->capture( $item ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testProcess() |
145
|
|
|
{ |
146
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
147
|
|
|
|
148
|
|
|
$this->mock->expects( $this->once() )->method( 'process' ); |
149
|
|
|
|
150
|
|
|
$this->object->process( $item, array( 'params' ) ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
public function testQuery() |
155
|
|
|
{ |
156
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
157
|
|
|
|
158
|
|
|
$this->mock->expects( $this->once() )->method( 'query' ); |
159
|
|
|
|
160
|
|
|
$this->object->query( $item ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testRefund() |
165
|
|
|
{ |
166
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
167
|
|
|
|
168
|
|
|
$this->mock->expects( $this->once() )->method( 'refund' ); |
169
|
|
|
|
170
|
|
|
$this->object->refund( $item ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testSetCommunication() |
175
|
|
|
{ |
176
|
|
|
$this->mock->expects( $this->once() )->method( 'setCommunication' ); |
177
|
|
|
|
178
|
|
|
$this->object->setCommunication( new \Aimeos\MW\Communication\Curl() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testSetConfigFE() |
183
|
|
|
{ |
184
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context ) |
185
|
|
|
->getSubManager( 'base' )->getSubManager( 'service' )->createItem(); |
186
|
|
|
|
187
|
|
|
$this->mock->expects( $this->once() )->method( 'setConfigFE' ); |
188
|
|
|
|
189
|
|
|
$this->object->setConfigFE( $item, [] ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
public function testUpdateAsync() |
194
|
|
|
{ |
195
|
|
|
$this->mock->expects( $this->once() )->method( 'updateAsync' ); |
196
|
|
|
|
197
|
|
|
$this->object->updateAsync(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testUpdatePush() |
202
|
|
|
{ |
203
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
204
|
|
|
$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock(); |
205
|
|
|
|
206
|
|
|
$this->mock->expects( $this->once() )->method( 'updatePush' )->will( $this->returnValue( $response ) ); |
207
|
|
|
|
208
|
|
|
$result = $this->object->updatePush( $request, $response ); |
209
|
|
|
|
210
|
|
|
$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $result ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testUpdateSync() |
215
|
|
|
{ |
216
|
|
|
$this->mock->expects( $this->once() )->method( 'updateSync' ); |
217
|
|
|
|
218
|
|
|
$response = null; $header = []; |
219
|
|
|
$this->object->updateSync( [], 'body', $response, $header ); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
class TestBase extends \Aimeos\MShop\Service\Provider\Decorator\Base |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.