Passed
Push — master ( 29d5f6...586595 )
by Aimeos
04:48
created

tests/Controller/Common/Order/StandardTest.php (4 issues)

1
<?php
2
3
/**
4
 * @copyright Metaways Infosystems GmbH, 2014
5
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
namespace Aimeos\Controller\Common\Order;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	protected function setUp()
15
	{
16
		\Aimeos\MShop\Factory::setCache( true );
17
	}
18
19
20
	protected function tearDown()
21
	{
22
		\Aimeos\MShop\Factory::clear();
23
		\Aimeos\MShop\Factory::setCache( false );
24
	}
25
26
27
	public function testBlock()
28
	{
29
		$context = \TestHelperCntl::getContext();
30
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
31
32
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
33
			->setConstructorArgs( array( $context ) )
34
			->setMethods( array( 'updateStatus' ) )
35
			->getMock();
36
37
		$object->expects( $this->exactly( 2 ) )->method( 'updateStatus' )
38
			->with( $this->equalTo( $orderItem ), $this->anything(), $this->equalTo( 1 ), $this->equalTo( -1 ) );
39
40
		$object->block( $orderItem );
41
	}
42
43
44
	public function testUnblock()
45
	{
46
		$context = \TestHelperCntl::getContext();
47
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
48
49
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
50
			->setConstructorArgs( array( $context ) )
51
			->setMethods( array( 'updateStatus' ) )
52
			->getMock();
53
54
		$object->expects( $this->exactly( 2 ) )->method( 'updateStatus' )
55
			->with( $this->equalTo( $orderItem ), $this->anything(), $this->equalTo( 0 ), $this->equalTo( +1 ) );
56
57
		$object->unblock( $orderItem );
58
	}
59
60
61
	public function testUpdateBlock()
62
	{
63
		$context = \TestHelperCntl::getContext();
64
65
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
66
		$orderItem->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_PENDING );
0 ignored issues
show
The method setPaymentStatus() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
		$orderItem->/** @scrutinizer ignore-call */ 
67
              setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_PENDING );

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.

Loading history...
67
68
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
69
			->setConstructorArgs( array( $context ) )
70
			->setMethods( array( 'block' ) )
71
			->getMock();
72
73
		$object->expects( $this->once() )->method( 'block' )->with( $this->equalTo( $orderItem ) );
74
75
		$object->update( $orderItem );
76
	}
77
78
79
	public function testUpdateUnblock()
80
	{
81
		$context = \TestHelperCntl::getContext();
82
83
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
84
		$orderItem->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_DELETED );
85
86
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
87
			->setConstructorArgs( array( $context ) )
88
			->setMethods( array( 'unblock' ) )
89
			->getMock();
90
91
		$object->expects( $this->once() )->method( 'unblock' )->with( $this->equalTo( $orderItem ) );
92
93
		$object->update( $orderItem );
94
	}
95
96
97
	public function testAddStatusItem()
98
	{
99
		$context = \TestHelperCntl::getContext();
100
101
		$statusStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Status\Standard' )
102
			->setConstructorArgs( array( $context ) )
103
			->setMethods( array( 'saveItem' ) )
104
			->getMock();
105
106
		$statusStub->expects( $this->once() )->method( 'saveItem' );
107
108
		\Aimeos\MShop\Factory::injectManager( $context, 'order/status', $statusStub );
109
110
111
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
112
		$method = $class->getMethod( 'addStatusItem' );
113
		$method->setAccessible( true );
114
115
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
116
		$method->invokeArgs( $object, array( 1, 2, 3 ) );
117
	}
118
119
120
	public function testGetBundleMap()
121
	{
122
		$context = \TestHelperCntl::getContext();
123
		$prodId = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( 'CNC' )->getId();
1 ignored issue
show
The method findItem() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Index\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
		$prodId = \Aimeos\MShop\Factory::createManager( $context, 'product' )->/** @scrutinizer ignore-call */ findItem( 'CNC' )->getId();
Loading history...
124
125
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
126
		$method = $class->getMethod( 'getBundleMap' );
127
		$method->setAccessible( true );
128
129
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
130
		$result = $method->invokeArgs( $object, array( $prodId ) );
131
132
		$this->assertEquals( 2, count( $result ) );
133
	}
134
135
136
	public function testGetContext()
137
	{
138
		$context = \TestHelperCntl::getContext();
139
140
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
141
		$method = $class->getMethod( 'getContext' );
142
		$method->setAccessible( true );
143
144
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
145
		$result = $method->invokeArgs( $object, [] );
146
147
		$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result );
148
		$this->assertSame( $context, $result );
149
	}
150
151
152
	public function testGetLastStatusItem()
153
	{
154
		$context = \TestHelperCntl::getContext();
155
		$orderItem = $this->getOrderItem( '2008-02-15 12:34:56' );
156
157
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
158
		$method = $class->getMethod( 'getLastStatusItem' );
159
		$method->setAccessible( true );
160
161
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
162
		$result = $method->invokeArgs( $object, array( $orderItem->getId(), 'typestatus', 'shipped' ) );
163
164
		$this->assertNotEquals( false, $result );
165
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Status\Iface', $result );
166
		$this->assertEquals( 'shipped', $result->getValue() );
167
	}
168
169
170
	public function testGetLastStatusItemFalse()
171
	{
172
		$context = \TestHelperCntl::getContext();
173
174
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
175
		$method = $class->getMethod( 'getLastStatusItem' );
176
		$method->setAccessible( true );
177
178
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
179
		$result = $method->invokeArgs( $object, array( -1, 0, 0 ) );
180
181
		$this->assertFalse( $result );
182
	}
183
184
185
	public function testGetStockItems()
186
	{
187
		$context = \TestHelperCntl::getContext();
188
189
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
190
		$method = $class->getMethod( 'getStockItems' );
191
		$method->setAccessible( true );
192
193
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
194
		$result = $method->invokeArgs( $object, array( array( 'CNE' ), 'default' ) );
195
196
		$this->assertEquals( 1, count( $result ) );
197
198
		foreach( $result as $item ) {
199
			$this->assertInstanceOf( '\Aimeos\MShop\Stock\Item\Iface', $item );
200
		}
201
	}
202
203
204
	public function testUpdateCoupons()
205
	{
206
		$context = \TestHelperCntl::getContext();
207
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
208
209
210
		$orderCouponStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Coupon\Standard' )
211
			->setConstructorArgs( array( $context ) )
212
			->setMethods( array( 'searchItems' ) )
213
			->getMock();
214
215
		$orderCouponStub->expects( $this->once() )->method( 'searchItems' )
216
			->will( $this->returnValue( array( $orderCouponStub->createItem() ) ) );
217
218
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/coupon', $orderCouponStub );
219
220
221
		$couponCodeStub = $this->getMockBuilder( '\Aimeos\MShop\Coupon\Manager\Code\Standard' )
222
			->setConstructorArgs( array( $context ) )
223
			->setMethods( array( 'increase' ) )
224
			->getMock();
225
226
		$couponCodeStub->expects( $this->once() )->method( 'increase' );
227
228
		\Aimeos\MShop\Factory::injectManager( $context, 'coupon/code', $couponCodeStub );
229
230
231
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
232
		$method = $class->getMethod( 'updateCoupons' );
233
		$method->setAccessible( true );
234
235
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
236
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
237
	}
238
239
240
	public function testUpdateCouponsException()
241
	{
242
		$context = \TestHelperCntl::getContext();
243
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
244
245
246
		$orderCouponStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Coupon\Standard' )
247
			->setConstructorArgs( array( $context ) )
248
			->setMethods( array( 'searchItems' ) )
249
			->getMock();
250
251
		$orderCouponStub->expects( $this->once() )->method( 'searchItems' )
252
			->will( $this->returnValue( array( $orderCouponStub->createItem() ) ) );
253
254
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/coupon', $orderCouponStub );
255
256
257
		$couponCodeStub = $this->getMockBuilder( '\Aimeos\MShop\Coupon\Manager\Code\Standard' )
258
			->setConstructorArgs( array( $context ) )
259
			->setMethods( array( 'increase' ) )
260
			->getMock();
261
262
		$couponCodeStub->expects( $this->once() )->method( 'increase' )
263
			->will( $this->throwException( new \RuntimeException() ) );
264
265
		\Aimeos\MShop\Factory::injectManager( $context, 'coupon/code', $couponCodeStub );
266
267
268
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
269
		$method = $class->getMethod( 'updateCoupons' );
270
		$method->setAccessible( true );
271
272
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
273
274
		$this->setExpectedException( '\Exception' );
275
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
276
	}
277
278
279
	public function testUpdateStatus()
280
	{
281
		$context = \TestHelperCntl::getContext();
282
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
283
		$statusItem = \Aimeos\MShop\Factory::createManager( $context, 'order/status' )->createItem();
284
		$statusItem->setValue( 1 );
0 ignored issues
show
The method setValue() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

284
		$statusItem->/** @scrutinizer ignore-call */ 
285
               setValue( 1 );

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.

Loading history...
285
286
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
287
			->setConstructorArgs( array( $context ) )
288
			->setMethods( array( 'addStatusItem', 'getLastStatusItem' ) )
289
			->getMock();
290
291
		$object->expects( $this->never() )->method( 'addStatusItem' );
292
293
		$object->expects( $this->once() )->method( 'getLastStatusItem' )
294
			->will( $this->returnValue( $statusItem ) );
295
296
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
297
		$method = $class->getMethod( 'updateStatus' );
298
		$method->setAccessible( true );
299
		$method->invokeArgs( $object, array( $orderItem, 'type', 1, 0 ) );
300
	}
301
302
303
	public function testUpdateStatusStock()
304
	{
305
		$context = \TestHelperCntl::getContext();
306
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
307
		$statusItem = \Aimeos\MShop\Factory::createManager( $context, 'order/status' )->createItem();
308
309
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
310
			->setConstructorArgs( array( $context ) )
311
			->setMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateStock' ) )
312
			->getMock();
313
314
		$object->expects( $this->once() )->method( 'getLastStatusItem' )
315
			->will( $this->returnValue( $statusItem ) );
316
317
		$object->expects( $this->once() )->method( 'updateStock' );
318
		$object->expects( $this->once() )->method( 'addStatusItem' );
319
320
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
321
		$method = $class->getMethod( 'updateStatus' );
322
		$method->setAccessible( true );
323
		$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::STOCK_UPDATE, 1, 0 ) );
324
	}
325
326
327
	public function testUpdateStatusCoupons()
328
	{
329
		$context = \TestHelperCntl::getContext();
330
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
331
		$statusItem = \Aimeos\MShop\Factory::createManager( $context, 'order/status' )->createItem();
332
333
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
334
			->setConstructorArgs( array( $context ) )
335
			->setMethods( array( 'addStatusItem', 'getLastStatusItem', 'updateCoupons' ) )
336
			->getMock();
337
338
		$object->expects( $this->once() )->method( 'getLastStatusItem' )
339
			->will( $this->returnValue( $statusItem ) );
340
341
		$object->expects( $this->once() )->method( 'updateCoupons' );
342
		$object->expects( $this->once() )->method( 'addStatusItem' );
343
344
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
345
		$method = $class->getMethod( 'updateStatus' );
346
		$method->setAccessible( true );
347
		$method->invokeArgs( $object, array( $orderItem, \Aimeos\MShop\Order\Item\Status\Base::COUPON_UPDATE, 1, 0 ) );
348
	}
349
350
351
	public function testUpdateStock()
352
	{
353
		$context = \TestHelperCntl::getContext();
354
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
355
356
357
		$orderProductStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Product\Standard' )
358
			->setConstructorArgs( array( $context ) )
359
			->setMethods( array( 'searchItems' ) )
360
			->getMock();
361
362
		$orderProductStub->expects( $this->once() )->method( 'searchItems' )
363
			->will( $this->returnValue( array( $orderProductStub->createItem() ) ) );
364
365
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/product', $orderProductStub );
366
367
368
		$stockStub = $this->getMockBuilder( '\Aimeos\MShop\Stock\Manager\Standard' )
369
			->setConstructorArgs( array( $context ) )
370
			->setMethods( array( 'increase' ) )
371
			->getMock();
372
373
		$stockStub->expects( $this->once() )->method( 'increase' );
374
375
		\Aimeos\MShop\Factory::injectManager( $context, 'stock', $stockStub );
376
377
378
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
379
			->setConstructorArgs( array( $context ) )
380
			->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) )
381
			->getMock();
382
383
		$object->expects( $this->never() )->method( 'updateStockBundle' );
384
		$object->expects( $this->never() )->method( 'updateStockSelection' );
385
386
387
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
388
		$method = $class->getMethod( 'updateStock' );
389
		$method->setAccessible( true );
390
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
391
	}
392
393
394
	public function testUpdateStockArticle()
395
	{
396
		$context = \TestHelperCntl::getContext();
397
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
398
399
400
		$orderProductStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Product\Standard' )
401
			->setConstructorArgs( array( $context ) )
402
			->setMethods( array( 'searchItems' ) )
403
			->getMock();
404
405
		$orderProductItem = $orderProductStub->createItem();
406
		$orderProductItem->setType( 'default' );
407
408
		$orderProductStub->expects( $this->once() )->method( 'searchItems' )
409
			->will( $this->returnValue( array( $orderProductItem ) ) );
410
411
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/product', $orderProductStub );
412
413
414
		$stockStub = $this->getMockBuilder( '\Aimeos\MShop\Stock\Manager\Standard' )
415
			->setConstructorArgs( array( $context ) )
416
			->setMethods( array( 'increase' ) )
417
			->getMock();
418
419
		$stockStub->expects( $this->once() )->method( 'increase' );
420
421
		\Aimeos\MShop\Factory::injectManager( $context, 'stock', $stockStub );
422
423
424
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
425
			->setConstructorArgs( array( $context ) )
426
			->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) )
427
			->getMock();
428
429
		$object->expects( $this->once() )->method( 'updateStockBundle' );
430
		$object->expects( $this->never() )->method( 'updateStockSelection' );
431
432
433
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
434
		$method = $class->getMethod( 'updateStock' );
435
		$method->setAccessible( true );
436
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
437
	}
438
439
440
	public function testUpdateStockSelect()
441
	{
442
		$context = \TestHelperCntl::getContext();
443
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
444
445
446
		$orderProductStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Product\Standard' )
447
			->setConstructorArgs( array( $context ) )
448
			->setMethods( array( 'searchItems' ) )
449
			->getMock();
450
451
		$orderProductItem = $orderProductStub->createItem();
452
		$orderProductItem->setType( 'select' );
453
454
		$orderProductStub->expects( $this->once() )->method( 'searchItems' )
455
			->will( $this->returnValue( array( $orderProductItem ) ) );
456
457
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/product', $orderProductStub );
458
459
460
		$stockStub = $this->getMockBuilder( '\Aimeos\MShop\Stock\Manager\Standard' )
461
			->setConstructorArgs( array( $context ) )
462
			->setMethods( array( 'increase' ) )
463
			->getMock();
464
465
		$stockStub->expects( $this->once() )->method( 'increase' );
466
467
		\Aimeos\MShop\Factory::injectManager( $context, 'stock', $stockStub );
468
469
470
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
471
			->setConstructorArgs( array( $context ) )
472
			->setMethods( array( 'updateStockBundle', 'updateStockSelection' ) )
473
			->getMock();
474
475
		$object->expects( $this->never() )->method( 'updateStockBundle' );
476
		$object->expects( $this->once() )->method( 'updateStockSelection' );
477
478
479
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
480
		$method = $class->getMethod( 'updateStock' );
481
		$method->setAccessible( true );
482
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
483
	}
484
485
486
	public function testUpdateStockException()
487
	{
488
		$context = \TestHelperCntl::getContext();
489
		$orderItem = \Aimeos\MShop\Factory::createManager( $context, 'order' )->createItem();
490
491
492
		$orderProductStub = $this->getMockBuilder( '\Aimeos\MShop\Order\Manager\Base\Product\Standard' )
493
			->setConstructorArgs( array( $context ) )
494
			->setMethods( array( 'searchItems' ) )
495
			->getMock();
496
497
		$orderProductStub->expects( $this->once() )->method( 'searchItems' )
498
			->will( $this->throwException( new \RuntimeException() ) );
499
500
		\Aimeos\MShop\Factory::injectManager( $context, 'order/base/product', $orderProductStub );
501
502
503
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
504
		$method = $class->getMethod( 'updateStock' );
505
		$method->setAccessible( true );
506
507
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
508
509
		$this->setExpectedException( '\Exception' );
510
		$method->invokeArgs( $object, array( $orderItem, 1 ) );
511
	}
512
513
514
	public function testUpdateStockBundle()
515
	{
516
		$context = \TestHelperCntl::getContext();
517
518
519
		$stockStub = $this->getMockBuilder( '\Aimeos\MShop\Stock\Manager\Standard' )
520
			->setConstructorArgs( array( $context ) )
521
			->setMethods( array( 'saveItem' ) )
522
			->getMock();
523
524
		$stockStub->expects( $this->once() )->method( 'saveItem' )->with( $this->callback( function( $item ) {
525
			return $item->getStocklevel() === 10;
526
		} ) );
527
528
		\Aimeos\MShop\Factory::injectManager( $context, 'stock', $stockStub );
529
530
531
		$stockItem = $stockStub->createItem();
532
533
		$stockItem1 = clone $stockItem;
534
		$stockItem1->setProductCode( 'X2' );
535
		$stockItem1->setStocklevel( 10 );
536
537
		$stockItem2 = clone $stockItem;
538
		$stockItem2->setProductCode( 'X3' );
539
		$stockItem2->setStocklevel( 20 );
540
541
		$stockItem3 = clone $stockItem;
542
		$stockItem3->setProductCode( 'X1' );
543
		$stockItem3->setStocklevel( 30 );
544
545
546
		$object = $this->getMockBuilder( '\Aimeos\Controller\Common\Order\Standard' )
547
			->setConstructorArgs( array( $context ) )
548
			->setMethods( array( 'getBundleMap', 'getStockItems' ) )
549
			->getMock();
550
551
		$object->expects( $this->once() )->method( 'getBundleMap' )
552
			->will( $this->returnValue( array( 'X2' => array( 'X1' ), 'X3' => array( 'X1' ) ) ) );
553
554
		$object->expects( $this->exactly( 2 ) )->method( 'getStockItems' )
555
			->will( $this->onConsecutiveCalls( array( $stockItem2, $stockItem1 ), array( $stockItem3 ) ) );
556
557
558
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
559
		$method = $class->getMethod( 'updateStockBundle' );
560
		$method->setAccessible( true );
561
		$method->invokeArgs( $object, array( 1, 'default' ) );
562
	}
563
564
565
	public function testUpdateStockSelection()
566
	{
567
		$context = \TestHelperCntl::getContext();
568
		$stockItem = \Aimeos\MShop\Factory::createManager( $context, 'stock' )->createItem();
0 ignored issues
show
The assignment to $stockItem is dead and can be removed.
Loading history...
569
		$prodId = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( 'U:TEST' )->getId();
570
571
572
		$stockStub = $this->getMockBuilder( '\Aimeos\MShop\Stock\Manager\Standard' )
573
			->setConstructorArgs( array( $context ) )
574
			->setMethods( array( 'saveItem' ) )
575
			->getMock();
576
577
		$stockStub->expects( $this->once() )->method( 'saveItem' )->with( $this->callback( function( $item ) {
578
			return $item->getStocklevel() === 300;
579
		} ) );
580
581
		\Aimeos\MShop\Factory::injectManager( $context, 'stock', $stockStub );
582
583
584
		$class = new \ReflectionClass( '\\Aimeos\\Controller\\Common\\Order\\Standard' );
585
		$method = $class->getMethod( 'updateStockSelection' );
586
		$method->setAccessible( true );
587
588
		$object = new \Aimeos\Controller\Common\Order\Standard( $context );
589
		$method->invokeArgs( $object, array( $prodId, 'default' ) );
590
	}
591
592
593
	protected function getOrderItem( $datepayment )
594
	{
595
		$manager = \Aimeos\MShop\Factory::createManager( \TestHelperCntl::getContext(), 'order' );
596
597
		$search = $manager->createSearch();
598
		$search->setConditions( $search->compare( '==', 'order.datepayment', $datepayment ) );
599
600
		$result = $manager->searchItems( $search );
601
602
		if( ( $item = reset( $result ) ) === false ) {
603
			throw new \RuntimeException( sprintf( 'No order item for payment date "%1$s" found', $datepayment ) );
604
		}
605
606
		return $item;
607
	}
608
}
609