|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Service\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class Example extends Base |
|
13
|
|
|
{ |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
private $context; |
|
20
|
|
|
private $object; |
|
21
|
|
|
private $stub; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() : void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->context = \TestHelper::context(); |
|
27
|
|
|
|
|
28
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class ) |
|
29
|
|
|
->disableOriginalConstructor() |
|
30
|
|
|
->getMock(); |
|
31
|
|
|
|
|
32
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Service\Decorator\Example( $this->stub, $this->context ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
protected function tearDown() : void |
|
37
|
|
|
{ |
|
38
|
|
|
unset( $this->context, $this->object, $this->stub ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function testCall() |
|
43
|
|
|
{ |
|
44
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class ) |
|
45
|
|
|
->disableOriginalConstructor() |
|
46
|
|
|
->onlyMethods( ['__call'] ) |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
|
|
49
|
|
|
$object = new \Aimeos\Controller\Frontend\Service\Decorator\Example( $stub, $this->context ); |
|
50
|
|
|
|
|
51
|
|
|
$stub->expects( $this->once() )->method( '__call' )->willReturn( true ); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertTrue( $object->invalid() ); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function testCompare() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertSame( $this->object, $this->object->compare( '==', 'service.type', 'delivery' ) ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function testConfig() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertSame( $this->object, $this->object->config( ['key' => 'value'] ) ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testFind() |
|
70
|
|
|
{ |
|
71
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->create(); |
|
72
|
|
|
|
|
73
|
|
|
$this->stub->expects( $this->once() )->method( 'find' ) |
|
74
|
|
|
->willReturn( $item ); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertSame( $item, $this->object->find( 'test' ) ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function testFunction() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->stub->expects( $this->once() )->method( 'function' ) |
|
83
|
|
|
->willReturn( 'service:has("domain","type","refid")' ); |
|
84
|
|
|
|
|
85
|
|
|
$str = $this->object->function( 'service:has', ['domain', 'type', 'refid'] ); |
|
86
|
|
|
$this->assertEquals( 'service:has("domain","type","refid")', $str ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testGet() |
|
91
|
|
|
{ |
|
92
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->create(); |
|
93
|
|
|
|
|
94
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
|
95
|
|
|
->willReturn( $item ); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertSame( $item, $this->object->get( -1 ) ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
public function testGetProvider() |
|
102
|
|
|
{ |
|
103
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'service' ); |
|
104
|
|
|
$provider = $manager->getProvider( $manager->find( 'unitdeliverycode', [], 'service', 'delivery' ), 'delivery' ); |
|
105
|
|
|
|
|
106
|
|
|
$this->stub->expects( $this->once() )->method( 'getProvider' ) |
|
107
|
|
|
->willReturn( $provider ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertSame( $provider, $this->object->getProvider( -1 ) ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function testGetProviders() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->stub->expects( $this->once() )->method( 'getProviders' ) |
|
116
|
|
|
->willReturn( map() ); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals( [], $this->object->getProviders( 'payment' )->toArray() ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
public function testParse() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->assertSame( $this->object, $this->object->parse( [] ) ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
public function testProcess() |
|
129
|
|
|
{ |
|
130
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
131
|
|
|
|
|
132
|
|
|
$this->stub->expects( $this->once() )->method( 'process' ) |
|
133
|
|
|
->willReturn( new \Aimeos\MShop\Common\Helper\Form\Standard() ); |
|
134
|
|
|
|
|
135
|
|
|
$this->assertInstanceOf( 'Aimeos\MShop\Common\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function testSearch() |
|
140
|
|
|
{ |
|
141
|
|
|
$total = 0; |
|
142
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->create(); |
|
143
|
|
|
|
|
144
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
|
145
|
|
|
->willReturn( map( [$item] ) ); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertEquals( [$item], $this->object->search( $total )->toArray() ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testSlice() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
public function testSort() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->assertSame( $this->object, $this->object->sort( 'type' ) ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
public function testUpdatePush() |
|
164
|
|
|
{ |
|
165
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
166
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
|
167
|
|
|
|
|
168
|
|
|
$this->stub->expects( $this->once() )->method( 'updatePush' ) |
|
169
|
|
|
->willReturn( $response ); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'test' ) ); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
public function testUpdateSync() |
|
176
|
|
|
{ |
|
177
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
|
178
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
179
|
|
|
|
|
180
|
|
|
$this->stub->expects( $this->once() )->method( 'updateSync' ) |
|
181
|
|
|
->willReturn( $item ); |
|
182
|
|
|
|
|
183
|
|
|
$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, 'test', -1 ) ); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
public function testUses() |
|
188
|
|
|
{ |
|
189
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
public function testGetController() |
|
194
|
|
|
{ |
|
195
|
|
|
$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) ); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
protected function access( $name ) |
|
200
|
|
|
{ |
|
201
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Service\Decorator\Base::class ); |
|
202
|
|
|
$method = $class->getMethod( $name ); |
|
203
|
|
|
$method->setAccessible( true ); |
|
204
|
|
|
|
|
205
|
|
|
return $method; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|