StandardTest   F
last analyzed

Complexity

Total Complexity 66

Size/Duplication

Total Lines 674
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 66
eloc 288
c 2
b 0
f 0
dl 0
loc 674
rs 3.12

63 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSet() 0 8 1
A setUp() 0 44 1
A testSetScale() 0 7 1
A testSetStatus() 0 7 1
A testGetStockItems() 0 6 1
A testSetCode() 0 9 1
A testAssign() 0 8 1
A testIsAvailable() 0 5 1
A testGetPropertyItems() 0 8 2
A tearDown() 0 3 1
A testDynamicMethods() 0 13 1
A testIsModified() 0 3 1
A testInStock() 0 3 1
A testGetTimeCreated() 0 3 1
A testGetDataset() 0 3 1
A testSetLabel() 0 7 1
A testFromArray() 0 41 1
A testGetId() 0 3 1
A testGetDateStart() 0 3 1
A testGetRating() 0 3 1
A testGetSiteId() 0 3 1
A testGetSitePath() 0 3 1
A testIsAvailableOnStatus() 0 7 1
A testBost() 0 3 1
A testSetDataset() 0 9 1
A testSetTimeCreated() 0 7 1
A testSetId() 0 13 1
A testGetResourceType() 0 3 1
A testGetTarget() 0 3 1
A testMagicMethods() 0 11 1
A testDynamicBaseMethods() 0 13 1
A testSetConfig() 0 9 1
A testGetScale() 0 3 1
A testSetTarget() 0 9 1
A testGetConfigValue() 0 3 1
A testGetSiteItem() 0 6 1
A testSetType() 0 9 1
A testGetRatings() 0 3 1
A testSetDateEnd() 0 7 1
A testGetStockItemsType() 0 9 1
A testGetLabel() 0 3 1
A testGetUrl() 0 3 1
A testGetCode() 0 3 1
A testGetTimeModified() 0 3 1
A testGetType() 0 3 1
A testIsAvailableOnTime() 0 7 1
A testArrayMethods() 0 12 1
A testJsonSerialize() 0 12 1
A testIsModifiedTrue() 0 4 1
A testIsAvailableEvent() 0 8 1
A testGetPropertyItemsAll() 0 8 2
A testGetDateEnd() 0 3 1
A testGetConfig() 0 3 1
A testGetPropertyItemsType() 0 8 2
A testSetBoost() 0 7 1
A testSetUrl() 0 7 1
A testSetDateStart() 0 7 1
A testGetEditor() 0 3 1
A testSetScaleInvalid() 0 7 1
A testToArray() 0 25 1
A testSetInStock() 0 7 1
A testSetConfigValue() 0 13 1
A testGetStatus() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like StandardTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use StandardTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2024
7
 */
8
9
10
namespace Aimeos\MShop\Product\Item;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $values;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->values = array(
22
			'product.id' => 1,
23
			'product.siteid' => '1.33.99.',
24
			'product.type' => 'test',
25
			'product.status' => 1,
26
			'product.code' => 'TEST',
27
			'product.dataset' => 'Shirts',
28
			'product.url' => 'test_product',
29
			'product.label' => 'testproduct',
30
			'product.config' => array( 'css-class' => 'test' ),
31
			'product.datestart' => null,
32
			'product.dateend' => null,
33
			'product.scale' => '',
34
			'product.ctime' => '2011-01-19 17:04:32',
35
			'product.mtime' => '2011-01-19 18:04:32',
36
			'product.editor' => 'unitTestUser',
37
			'product.target' => 'testtarget',
38
			'product.rating' => '4.80',
39
			'product.ratings' => 5,
40
			'product.instock' => 1,
41
			'product.boost' => 1.5,
42
			'additional' => 'value',
43
		);
44
45
		$propItems = array(
46
			2 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array(
47
				'product.property.id' => 2,
48
				'product.property.parentid' => 1,
49
				'product.property.type' => 'proptest',
50
				'product.property.languageid' => 'de',
51
				'.languageid' => 'de',
52
			) ),
53
			3 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array(
54
				'product.property.id' => 3,
55
				'product.property.parentid' => 1,
56
				'product.property.type' => 'proptype',
57
				'product.property.languageid' => 'de',
58
				'.languageid' => 'fr',
59
			) ),
60
		);
61
62
		$this->object = new \Aimeos\MShop\Product\Item\Standard( $this->values, [], [], $propItems );
63
	}
64
65
66
	protected function tearDown() : void
67
	{
68
		unset( $this->object, $this->values );
69
	}
70
71
72
	public function testDynamicMethods()
73
	{
74
		\Aimeos\MShop\Product\Item\Standard::macro( 'test', function( $name ) {
75
			return $this->bdata[$name];
0 ignored issues
show
Bug introduced by
The property bdata does not exist on Aimeos\MShop\Product\Item\StandardTest. Did you mean data?
Loading history...
76
		} );
77
78
		$this->assertInstanceOf( '\Closure', \Aimeos\MShop\Product\Item\Standard::macro( 'test' ) );
79
80
		$object = new \Aimeos\MShop\Product\Item\Standard( $this->values );
81
		$this->assertEquals( 'TEST', $object->test( 'product.code' ) );
82
83
		$this->expectException( \BadMethodCallException::class );
84
		$object->invalid();
85
	}
86
87
88
	public function testDynamicBaseMethods()
89
	{
90
		\Aimeos\MShop\Common\Item\Base::macro( 'tests', function( $name ) {
91
			return $this->bdata[$name];
0 ignored issues
show
Bug introduced by
The property bdata does not exist on Aimeos\MShop\Product\Item\StandardTest. Did you mean data?
Loading history...
92
		} );
93
94
		$this->assertInstanceOf( '\Closure', \Aimeos\MShop\Product\Item\Standard::macro( 'tests' ) );
95
96
		$object = new \Aimeos\MShop\Product\Item\Standard( $this->values );
97
		$this->assertEquals( 'TEST', $object->tests( 'product.code' ) );
98
99
		$this->expectException( \BadMethodCallException::class );
100
		$object->invalid();
101
	}
102
103
104
	public function testArrayMethods()
105
	{
106
		$this->assertFalse( isset( $this->object['test'] ) );
107
		$this->assertEquals( null, $this->object['test'] );
108
109
		$this->object['test'] = 'value';
110
111
		$this->assertTrue( isset( $this->object['test'] ) );
112
		$this->assertEquals( 'value', $this->object['test'] );
113
114
		$this->expectException( \LogicException::class );
115
		unset( $this->object['test'] );
116
	}
117
118
119
	public function testMagicMethods()
120
	{
121
		$this->assertFalse( isset( $this->object->test ) );
122
		$this->assertEquals( null, $this->object->test );
123
124
		$this->object->test = 'value';
125
126
		$this->assertTrue( isset( $this->object->test ) );
127
		$this->assertEquals( 'value', $this->object->test );
128
129
		$this->assertEquals( '1', (string) $this->object );
130
	}
131
132
133
	public function testGetSet()
134
	{
135
		$this->assertEquals( false, $this->object->get( 'test', false ) );
136
137
		$return = $this->object->set( 'test', 'value' );
138
139
		$this->assertEquals( 'value', $this->object->get( 'test', false ) );
140
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
141
	}
142
143
144
	public function testJsonSerialize()
145
	{
146
		$result = json_decode( json_encode( $this->object ), true );
147
148
		$this->assertEquals( 1, $result['product.id'] );
149
		$this->assertEquals( '1.33.99.', $result['product.siteid'] );
150
151
152
		$result = json_decode( json_encode( [1 => $this->object] ), true );
153
154
		$this->assertEquals( 1, $result[1]['product.id'] );
155
		$this->assertEquals( '1.33.99.', $result[1]['product.siteid'] );
156
	}
157
158
159
	public function testAssign()
160
	{
161
		$this->assertEquals( false, $this->object->get( 'test', false ) );
162
163
		$return = $this->object->assign( ['test' => 'value'] );
164
165
		$this->assertEquals( 'value', $this->object->get( 'test', false ) );
166
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
167
	}
168
169
170
	public function testGetId()
171
	{
172
		$this->assertEquals( '1', $this->object->getId() );
173
	}
174
175
176
	public function testSetId()
177
	{
178
		$return = $this->object->setId( null );
179
180
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
181
		$this->assertNull( $this->object->getId() );
182
		$this->assertTrue( $this->object->isModified() );
183
184
		$return = $this->object->setId( 1 );
185
186
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
187
		$this->assertEquals( '1', $this->object->getId() );
188
		$this->assertFalse( $this->object->isModified() );
189
	}
190
191
192
	public function testGetSiteId()
193
	{
194
		$this->assertEquals( '1.33.99.', $this->object->getSiteId() );
195
	}
196
197
198
	public function testGetSitePath()
199
	{
200
		$this->assertEquals( ['1.', '1.33.', '1.33.99.'], $this->object->getSitePath() );
201
	}
202
203
204
	public function testGetType()
205
	{
206
		$this->assertEquals( 'test', $this->object->getType() );
207
	}
208
209
210
	public function testSetType()
211
	{
212
		$this->assertFalse( $this->object->isModified() );
213
214
		$return = $this->object->setType( 'default' );
215
216
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
217
		$this->assertEquals( 'default', $this->object->getType() );
218
		$this->assertTrue( $this->object->isModified() );
219
	}
220
221
222
	public function testGetCode()
223
	{
224
		$this->assertEquals( 'TEST', $this->object->getCode() );
225
	}
226
227
228
	public function testSetCode()
229
	{
230
		$this->assertFalse( $this->object->isModified() );
231
232
		$return = $this->object->setCode( 'NEU' );
233
234
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
235
		$this->assertEquals( 'NEU', $this->object->getCode() );
236
		$this->assertTrue( $this->object->isModified() );
237
	}
238
239
240
	public function testGetDataset()
241
	{
242
		$this->assertEquals( 'Shirts', $this->object->getDataset() );
243
	}
244
245
246
	public function testSetDataset()
247
	{
248
		$this->assertFalse( $this->object->isModified() );
249
250
		$return = $this->object->setDataset( 'Skirts' );
251
252
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
253
		$this->assertEquals( 'Skirts', $this->object->getDataset() );
254
		$this->assertTrue( $this->object->isModified() );
255
	}
256
257
258
	public function testGetScale()
259
	{
260
		$this->assertEquals( 1, $this->object->getScale() );
261
	}
262
263
264
	public function testSetScale()
265
	{
266
		$return = $this->object->setScale( 0.25 );
267
268
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
269
		$this->assertEquals( 0.25, $this->object->getScale() );
270
		$this->assertTrue( $this->object->isModified() );
271
	}
272
273
274
	public function testSetScaleInvalid()
275
	{
276
		$return = $this->object->setScale( -1 );
277
278
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
279
		$this->assertEquals( 1, $this->object->getScale() );
280
		$this->assertTrue( $this->object->isModified() );
281
	}
282
283
284
	public function testGetEditor()
285
	{
286
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
287
	}
288
289
290
	public function testGetStatus()
291
	{
292
		$this->assertEquals( 1, $this->object->getStatus() );
293
	}
294
295
296
	public function testSetStatus()
297
	{
298
		$return = $this->object->setStatus( 8 );
299
300
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
301
		$this->assertEquals( 8, $this->object->getStatus() );
302
		$this->assertTrue( $this->object->isModified() );
303
	}
304
305
306
	public function testGetLabel()
307
	{
308
		$this->assertEquals( 'testproduct', $this->object->getLabel() );
309
	}
310
311
312
	public function testSetLabel()
313
	{
314
		$return = $this->object->setLabel( 'editproduct' );
315
316
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
317
		$this->assertEquals( 'editproduct', $this->object->getLabel() );
318
		$this->assertTrue( $this->object->isModified() );
319
	}
320
321
322
	public function testGetUrl()
323
	{
324
		$this->assertEquals( 'test_product', $this->object->getUrl() );
325
	}
326
327
328
	public function testSetUrl()
329
	{
330
		$return = $this->object->setUrl( 'edit_product' );
331
332
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
333
		$this->assertEquals( 'edit_product', $this->object->getUrl() );
334
		$this->assertTrue( $this->object->isModified() );
335
	}
336
337
338
	public function testGetConfig()
339
	{
340
		$this->assertEquals( array( 'css-class' => 'test' ), $this->object->getConfig() );
341
	}
342
343
344
	public function testGetConfigValue()
345
	{
346
		$this->assertEquals( 'test', $this->object->getConfigValue( 'css-class' ) );
347
	}
348
349
350
	public function testSetConfig()
351
	{
352
		$this->assertFalse( $this->object->isModified() );
353
354
		$return = $this->object->setConfig( array( 'key' => 'value' ) );
355
356
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
357
		$this->assertEquals( array( 'key' => 'value' ), $this->object->getConfig() );
358
		$this->assertTrue( $this->object->isModified() );
359
	}
360
361
362
	public function testSetConfigValue()
363
	{
364
		$result = $this->object->setConfigValue( 'path/to/value', 'test' );
365
		$expected = ['path' => ['to' => ['value' => 'test']], 'css-class' => 'test'];
366
367
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result );
368
		$this->assertEquals( $expected, $this->object->getConfig() );
369
370
		$result = $this->object->setConfigValue( 'path/to/value2', 'test2' );
371
		$expected = ['path' => ['to' => ['value' => 'test', 'value2' => 'test2']], 'css-class' => 'test'];
372
373
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result );
374
		$this->assertEquals( $expected, $this->object->getConfig() );
375
	}
376
377
378
	public function testGetTarget()
379
	{
380
		$this->assertEquals( 'testtarget', $this->object->getTarget() );
381
	}
382
383
384
	public function testSetTarget()
385
	{
386
		$this->assertFalse( $this->object->isModified() );
387
388
		$return = $this->object->setTarget( 'ttarget' );
389
390
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
391
		$this->assertEquals( 'ttarget', $this->object->getTarget() );
392
		$this->assertTrue( $this->object->isModified() );
393
	}
394
395
396
	public function testGetDateStart()
397
	{
398
		$this->assertEquals( null, $this->object->getDateStart() );
399
	}
400
401
402
	public function testSetDateStart()
403
	{
404
		$return = $this->object->setDateStart( '2010-04-22 06:22:22' );
405
406
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
407
		$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() );
408
		$this->assertTrue( $this->object->isModified() );
409
	}
410
411
412
	public function testGetDateEnd()
413
	{
414
		$this->assertEquals( null, $this->object->getDateEnd() );
415
	}
416
417
418
	public function testSetDateEnd()
419
	{
420
		$return = $this->object->setDateEnd( '2010-05-22 06:22' );
421
422
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
423
		$this->assertEquals( '2010-05-22 06:22:00', $this->object->getDateEnd() );
424
		$this->assertTrue( $this->object->isModified() );
425
	}
426
427
428
	public function testGetTimeModified()
429
	{
430
		$this->assertEquals( '2011-01-19 18:04:32', $this->object->getTimeModified() );
431
	}
432
433
434
	public function testGetTimeCreated()
435
	{
436
		$this->assertEquals( '2011-01-19 17:04:32', $this->object->getTimeCreated() );
437
	}
438
439
440
	public function testSetTimeCreated()
441
	{
442
		$return = $this->object->setTimeCreated( '2010-05-22 06:22:22' );
443
444
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
445
		$this->assertEquals( '2010-05-22 06:22:22', $this->object->getTimeCreated() );
446
		$this->assertTrue( $this->object->isModified() );
447
	}
448
449
450
	public function testGetRating()
451
	{
452
		$this->assertEquals( '4.80', $this->object->getRating() );
453
	}
454
455
456
	public function testGetRatings()
457
	{
458
		$this->assertEquals( 5, $this->object->getRatings() );
459
	}
460
461
462
	public function testInStock()
463
	{
464
		$this->assertEquals( 1, $this->object->inStock() );
465
	}
466
467
468
	public function testSetInStock()
469
	{
470
		$return = $this->object->setInStock( 0 );
471
472
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
473
		$this->assertEquals( 0, $this->object->inStock() );
474
		$this->assertTrue( $this->object->isModified() );
475
	}
476
477
478
	public function testBost()
479
	{
480
		$this->assertEquals( 1.5, $this->object->boost() );
481
	}
482
483
484
	public function testSetBoost()
485
	{
486
		$return = $this->object->setBoost( 1.25 );
487
488
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return );
489
		$this->assertEquals( 1.25, $this->object->boost() );
490
		$this->assertTrue( $this->object->isModified() );
491
	}
492
493
494
	public function testIsAvailable()
495
	{
496
		$this->assertTrue( $this->object->isAvailable() );
497
		$this->object->setAvailable( false );
498
		$this->assertFalse( $this->object->isAvailable() );
499
	}
500
501
502
	public function testIsAvailableOnStatus()
503
	{
504
		$this->assertTrue( $this->object->isAvailable() );
505
		$this->object->setStatus( 0 );
506
		$this->assertFalse( $this->object->isAvailable() );
507
		$this->object->setStatus( -1 );
508
		$this->assertFalse( $this->object->isAvailable() );
509
	}
510
511
512
	public function testIsAvailableOnTime()
513
	{
514
		$this->assertTrue( $this->object->isAvailable() );
515
		$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) );
516
		$this->assertFalse( $this->object->isAvailable() );
517
		$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) );
518
		$this->assertFalse( $this->object->isAvailable() );
519
	}
520
521
522
	public function testIsAvailableEvent()
523
	{
524
		$this->object->setType( 'event' );
525
		$this->assertTrue( $this->object->isAvailable() );
526
		$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) );
527
		$this->assertTrue( $this->object->isAvailable() );
528
		$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) );
529
		$this->assertFalse( $this->object->isAvailable() );
530
	}
531
532
533
	public function testIsModified()
534
	{
535
		$this->assertFalse( $this->object->isModified() );
536
	}
537
538
539
	public function testIsModifiedTrue()
540
	{
541
		$this->object->setLabel( 'reeditProduct' );
542
		$this->assertTrue( $this->object->isModified() );
543
	}
544
545
546
	public function testGetResourceType()
547
	{
548
		$this->assertEquals( 'product', $this->object->getResourceType() );
549
	}
550
551
552
	public function testGetPropertyItems()
553
	{
554
		$propItems = $this->object->getPropertyItems();
555
556
		$this->assertEquals( 1, count( $propItems ) );
557
558
		foreach( $propItems as $propItem ) {
559
			$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem );
560
		}
561
	}
562
563
564
	public function testGetSiteItem()
565
	{
566
		$siteItem = \TestHelper::context()->locale()->getSiteItem();
567
		$object = new \Aimeos\MShop\Product\Item\Standard( ['.locale/site' => $siteItem] );
568
569
		$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $object->getSiteItem() );
570
	}
571
572
573
	public function testGetStockItems()
574
	{
575
		$object = new \Aimeos\MShop\Product\Item\Standard( ['.stock' => []] );
576
577
		$this->assertInstanceOf( \Aimeos\Map::class, $object->getStockItems() );
578
		$this->assertEquals( [], $object->getStockItems()->toArray() );
579
	}
580
581
582
	public function testGetStockItemsType()
583
	{
584
		$stock = new \Aimeos\MShop\Stock\Item\Standard();
585
		$stocks = [123 => ( clone $stock )->setType( 'something' ), 456 => ( clone $stock )->setType( 'default' )];
586
		$object = new \Aimeos\MShop\Product\Item\Standard( ['.stock' => $stocks] );
587
588
		$this->assertInstanceOf( \Aimeos\Map::class, $object->getStockItems( 'default' ) );
589
		$this->assertEquals( 'default', $object->getStockItems( 'default' )->getType()->first() );
590
		$this->assertCount( 1, $object->getStockItems( 'default' ) );
591
	}
592
593
594
	public function testGetPropertyItemsAll()
595
	{
596
		$propItems = $this->object->getPropertyItems( null, false );
597
598
		$this->assertEquals( 2, count( $propItems ) );
599
600
		foreach( $propItems as $propItem ) {
601
			$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem );
602
		}
603
	}
604
605
606
	public function testGetPropertyItemsType()
607
	{
608
		$propItems = $this->object->getPropertyItems( 'proptest' );
609
610
		$this->assertEquals( 1, count( $propItems ) );
611
612
		foreach( $propItems as $propItem ) {
613
			$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem );
614
		}
615
	}
616
617
618
	public function testFromArray()
619
	{
620
		$item = new \Aimeos\MShop\Product\Item\Standard();
621
622
		$list = $entries = array(
623
			'product.id' => 1,
624
			'product.type' => 'test',
625
			'product.label' => 'test item',
626
			'product.url' => 'test_item',
627
			'product.code' => 'test',
628
			'product.dataset' => 'Shirts',
629
			'product.datestart' => '2000-01-01 00:00:00',
630
			'product.dateend' => '2001-01-01 00:00:00',
631
			'product.config' => array( 'key' => 'value' ),
632
			'product.status' => 0,
633
			'product.scale' => '0.5',
634
			'product.target' => 'ttarget',
635
			'product.instock' => 1,
636
			'product.boost' => 2.5,
637
			'additional' => 'value',
638
		);
639
640
		$item = $item->fromArray( $entries, true );
641
642
		$this->assertEquals( ['additional' => 'value'], $entries );
643
		$this->assertEquals( $list['product.id'], $item->getId() );
644
		$this->assertEquals( $list['product.url'], $item->getUrl() );
645
		$this->assertEquals( $list['product.type'], $item->getType() );
646
		$this->assertEquals( $list['product.code'], $item->getCode() );
647
		$this->assertEquals( $list['product.label'], $item->getLabel() );
648
		$this->assertEquals( $list['product.dataset'], $item->getDataset() );
649
		$this->assertEquals( $list['product.datestart'], $item->getDateStart() );
650
		$this->assertEquals( $list['product.dateend'], $item->getDateEnd() );
651
		$this->assertEquals( $list['product.config'], $item->getConfig() );
652
		$this->assertEquals( $list['product.status'], $item->getStatus() );
653
		$this->assertEquals( $list['product.target'], $item->getTarget() );
654
		$this->assertEquals( $list['product.scale'], $item->getScale() );
655
		$this->assertEquals( $list['product.instock'], $item->inStock() );
656
		$this->assertEquals( $list['product.boost'], $item->boost() );
657
		$this->assertEquals( $list['additional'], $item->additional );
0 ignored issues
show
Bug Best Practice introduced by
The property additional does not exist on Aimeos\MShop\Product\Item\Standard. Since you implemented __get, consider adding a @property annotation.
Loading history...
658
		$this->assertEquals( '', $item->getSiteId() );
659
	}
660
661
662
	public function testToArray()
663
	{
664
		$arrayObject = $this->object->toArray( true );
665
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
666
667
		$this->assertEquals( $this->object->getId(), $arrayObject['product.id'] );
668
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['product.siteid'] );
669
		$this->assertEquals( $this->object->getCode(), $arrayObject['product.code'] );
670
		$this->assertEquals( $this->object->getType(), $arrayObject['product.type'] );
671
		$this->assertEquals( $this->object->getDataset(), $arrayObject['product.dataset'] );
672
		$this->assertEquals( $this->object->getLabel(), $arrayObject['product.label'] );
673
		$this->assertEquals( $this->object->getUrl(), $arrayObject['product.url'] );
674
		$this->assertEquals( $this->object->getStatus(), $arrayObject['product.status'] );
675
		$this->assertEquals( $this->object->getDateStart(), $arrayObject['product.datestart'] );
676
		$this->assertEquals( $this->object->getDateEnd(), $arrayObject['product.dateend'] );
677
		$this->assertEquals( $this->object->getConfig(), $arrayObject['product.config'] );
678
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['product.ctime'] );
679
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['product.mtime'] );
680
		$this->assertEquals( $this->object->editor(), $arrayObject['product.editor'] );
681
		$this->assertEquals( $this->object->boost(), $arrayObject['product.boost'] );
682
		$this->assertEquals( $this->object->getTarget(), $arrayObject['product.target'] );
683
		$this->assertEquals( $this->object->getScale(), $arrayObject['product.scale'] );
684
		$this->assertEquals( $this->object->getRating(), $arrayObject['product.rating'] );
685
		$this->assertEquals( $this->object->getRatings(), $arrayObject['product.ratings'] );
686
		$this->assertEquals( $this->object->inStock(), $arrayObject['product.instock'] );
687
	}
688
}
689