Passed
Push — master ( 92591d...b586f0 )
by Aimeos
15:24
created

StandardTest::testFromArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 60
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 60
rs 8.9818
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
9
namespace Aimeos\MShop\Supplier\Item\Address;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $values;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->values = array(
21
			'supplier.address.id' => 23,
22
			'supplier.address.siteid' => 12,
23
			'supplier.address.parentid' => 'referenceid',
24
			'supplier.address.company' => 'unitCompany',
25
			'supplier.address.vatid' => 'DE999999999',
26
			'supplier.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
27
			'supplier.address.title' => 'Herr',
28
			'supplier.address.firstname' => 'firstunit',
29
			'supplier.address.lastname' => 'lastunit',
30
			'supplier.address.address1' => 'unit str.',
31
			'supplier.address.address2' => '166',
32
			'supplier.address.address3' => '4.OG',
33
			'supplier.address.postal' => '22769',
34
			'supplier.address.city' => 'Hamburg',
35
			'supplier.address.state' => 'Hamburg',
36
			'supplier.address.countryid' => 'DE',
37
			'supplier.address.languageid' => 'de',
38
			'supplier.address.telephone' => '05554433221',
39
			'supplier.address.telefax' => '05554433222',
40
			'supplier.address.mobile' => '05554433223',
41
			'supplier.address.email' => '[email protected]',
42
			'supplier.address.website' => 'www.example.com',
43
			'supplier.address.longitude' => '10.0',
44
			'supplier.address.latitude' => '50.0',
45
			'supplier.address.position' => 1,
46
			'supplier.address.birthday' => '2001-01-01',
47
			'supplier.address.mtime' => '2011-01-01 00:00:02',
48
			'supplier.address.ctime' => '2011-01-01 00:00:01',
49
			'supplier.address.editor' => 'unitTestUser',
50
		);
51
52
		$this->object = new \Aimeos\MShop\Supplier\Item\Address\Standard( 'supplier.address.', $this->values );
53
	}
54
55
56
	protected function tearDown() : void
57
	{
58
		$this->object = null;
59
	}
60
61
62
	public function testGetId()
63
	{
64
		$this->assertEquals( 23, $this->object->getId() );
65
	}
66
67
68
	public function testSetId()
69
	{
70
		$return = $this->object->setId( null );
71
72
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
73
		$this->assertNull( $this->object->getId() );
74
		$this->assertTrue( $this->object->isModified() );
75
	}
76
77
78
	public function testGetParentId()
79
	{
80
		$this->assertEquals( 'referenceid', $this->object->getParentId() );
81
	}
82
83
84
	public function testSetParentId()
85
	{
86
		$return = $this->object->setParentId( 'unitreference' );
87
88
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
89
		$this->assertEquals( 'unitreference', $this->object->getParentId() );
90
		$this->assertTrue( $this->object->isModified() );
91
	}
92
93
94
	public function testGetCompany()
95
	{
96
		$this->assertEquals( 'unitCompany', $this->object->getCompany() );
97
	}
98
99
100
	public function testSetCompany()
101
	{
102
		$return = $this->object->setCompany( 'company' );
103
104
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
105
		$this->assertEquals( 'company', $this->object->getCompany() );
106
		$this->assertTrue( $this->object->isModified() );
107
	}
108
109
110
	public function testGetVatID()
111
	{
112
		$this->assertEquals( 'DE999999999', $this->object->getVatID() );
113
	}
114
115
116
	public function testSetVatID()
117
	{
118
		$return = $this->object->setVatID( 'vatid' );
119
120
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
121
		$this->assertEquals( 'vatid', $this->object->getVatID() );
122
		$this->assertTrue( $this->object->isModified() );
123
	}
124
125
126
	public function testGetSalutation()
127
	{
128
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, $this->object->getSalutation() );
129
	}
130
131
132
	public function testSetSalutation()
133
	{
134
		$return = $this->object->setSalutation( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY );
135
136
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
137
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY, $this->object->getSalutation() );
138
		$this->assertTrue( $this->object->isModified() );
139
	}
140
141
142
	public function testGetTitle()
143
	{
144
		$this->assertEquals( 'Herr', $this->object->getTitle() );
145
	}
146
147
148
	public function testSetTitle()
149
	{
150
		$return = $this->object->setTitle( 'Dr.' );
151
152
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
153
		$this->assertEquals( 'Dr.', $this->object->getTitle() );
154
		$this->assertTrue( $this->object->isModified() );
155
	}
156
157
158
	public function testGetFirstname()
159
	{
160
		$this->assertEquals( 'firstunit', $this->object->getFirstname() );
161
	}
162
163
164
	public function testSetFirstname()
165
	{
166
		$return = $this->object->setFirstname( 'hans' );
167
168
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
169
		$this->assertEquals( 'hans', $this->object->getFirstname() );
170
		$this->assertTrue( $this->object->isModified() );
171
	}
172
173
174
	public function testGetLastname()
175
	{
176
		$this->assertEquals( 'lastunit', $this->object->getLastname() );
177
	}
178
179
180
	public function testSetLastname()
181
	{
182
		$return = $this->object->setLastname( 'im Glueck' );
183
184
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
185
		$this->assertEquals( 'im Glueck', $this->object->getLastname() );
186
		$this->assertTrue( $this->object->isModified() );
187
	}
188
189
190
	public function testGetAddress1()
191
	{
192
		$this->assertEquals( 'unit str.', $this->object->getAddress1() );
193
	}
194
195
196
	public function testSetAddress1()
197
	{
198
		$return = $this->object->setAddress1( 'unitallee' );
199
200
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
201
		$this->assertEquals( 'unitallee', $this->object->getAddress1() );
202
		$this->assertTrue( $this->object->isModified() );
203
	}
204
205
206
	public function testGetAddress2()
207
	{
208
		$this->assertEquals( '166', $this->object->getAddress2() );
209
	}
210
211
212
	public function testSetAddress2()
213
	{
214
		$return = $this->object->setAddress2( '12' );
215
216
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
217
		$this->assertEquals( '12', $this->object->getAddress2() );
218
		$this->assertTrue( $this->object->isModified() );
219
	}
220
221
222
	public function testGetAddress3()
223
	{
224
		$this->assertEquals( '4.OG', $this->object->getAddress3() );
225
	}
226
227
228
	public function testSetAddress3()
229
	{
230
		$return = $this->object->setAddress3( 'EG' );
231
232
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
233
		$this->assertEquals( 'EG', $this->object->getAddress3() );
234
		$this->assertTrue( $this->object->isModified() );
235
	}
236
237
238
	public function testGetPostal()
239
	{
240
		$this->assertEquals( '22769', $this->object->getPostal() );
241
	}
242
243
244
	public function testSetPostal()
245
	{
246
		$return = $this->object->setPostal( '11111' );
247
248
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
249
		$this->assertEquals( '11111', $this->object->getPostal() );
250
		$this->assertTrue( $this->object->isModified() );
251
	}
252
253
254
	public function testGetCity()
255
	{
256
		$this->assertEquals( 'Hamburg', $this->object->getCity() );
257
	}
258
259
260
	public function testSetCity()
261
	{
262
		$return = $this->object->setCity( 'unitCity' );
263
264
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
265
		$this->assertEquals( 'unitCity', $this->object->getCity() );
266
		$this->assertTrue( $this->object->isModified() );
267
	}
268
269
270
	public function testGetState()
271
	{
272
		$this->assertEquals( 'Hamburg', $this->object->getState() );
273
	}
274
275
276
	public function testSetState()
277
	{
278
		$return = $this->object->setState( 'unitState' );
279
280
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
281
		$this->assertEquals( 'unitState', $this->object->getState() );
282
		$this->assertTrue( $this->object->isModified() );
283
	}
284
285
286
	public function testGetCountryId()
287
	{
288
		$this->assertEquals( 'DE', $this->object->getCountryId() );
289
	}
290
291
292
	public function testSetCountryId()
293
	{
294
		$return = $this->object->setCountryId( 'uk' );
295
296
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
297
		$this->assertEquals( 'UK', $this->object->getCountryId() );
298
		$this->assertTrue( $this->object->isModified() );
299
	}
300
301
302
	public function testGetLanguageId()
303
	{
304
		$this->assertEquals( 'de', $this->object->getLanguageId() );
305
	}
306
307
308
	public function testSetLanguageId()
309
	{
310
		$return = $this->object->setLanguageId( 'en' );
311
312
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
313
		$this->assertEquals( 'en', $this->object->getLanguageId() );
314
		$this->assertTrue( $this->object->isModified() );
315
	}
316
317
318
	public function testGetTelephone()
319
	{
320
		$this->assertEquals( '05554433221', $this->object->getTelephone() );
321
	}
322
323
324
	public function testSetTelephone()
325
	{
326
		$return = $this->object->setTelephone( '55512345' );
327
328
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
329
		$this->assertEquals( '55512345', $this->object->getTelephone() );
330
		$this->assertTrue( $this->object->isModified() );
331
	}
332
333
334
	public function testGetTelefax()
335
	{
336
		$this->assertEquals( '05554433222', $this->object->getTelefax() );
337
	}
338
339
340
	public function testSetTelefax()
341
	{
342
		$return = $this->object->setTelefax( '55512345' );
343
344
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
345
		$this->assertEquals( '55512345', $this->object->getTelefax() );
346
		$this->assertTrue( $this->object->isModified() );
347
	}
348
349
350
	public function testGetMobile()
351
	{
352
		$this->assertEquals( '05554433223', $this->object->getMobile() );
353
	}
354
355
356
	public function testSetMobile()
357
	{
358
		$return = $this->object->setMobile( '555123456' );
359
360
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
361
		$this->assertEquals( '555123456', $this->object->getMobile() );
362
		$this->assertTrue( $this->object->isModified() );
363
	}
364
365
366
	public function testGetEmail()
367
	{
368
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
369
	}
370
371
372
	public function testSetEmail()
373
	{
374
		$return = $this->object->setEmail( '[email protected]' );
375
376
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
377
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
378
		$this->assertTrue( $this->object->isModified() );
379
380
		$this->expectException( \Aimeos\MShop\Exception::class );
381
		$this->object->setEmail( 'unittest.de' );
382
	}
383
384
385
	public function testGetWebsite()
386
	{
387
		$this->assertEquals( 'www.example.com', $this->object->getWebsite() );
388
	}
389
390
391
	public function testSetWebsite()
392
	{
393
		$return = $this->object->setWebsite( 'www.test.de' );
394
395
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
396
		$this->assertEquals( 'www.test.de', $this->object->getWebsite() );
397
		$this->assertTrue( $this->object->isModified() );
398
399
		$this->object->setWebsite( 'http://xn--ses-5ka8l.de' );
400
		$this->object->setWebsite( 'http://www.test.de:443' );
401
		$this->object->setWebsite( 'https://www.test.de:8080/abc?123' );
402
403
		$this->expectException( \Aimeos\MShop\Exception::class );
404
		$this->object->setWebsite( '_test:de' );
405
	}
406
407
408
	public function testSetWebsiteHostException()
409
	{
410
		$this->expectException( \Aimeos\MShop\Exception::class );
411
		$this->object->setWebsite( 'localhost' );
412
	}
413
414
415
	public function testGetLongitude()
416
	{
417
		$this->assertEquals( '10.0', $this->object->getLongitude() );
418
	}
419
420
421
	public function testSetLongitude()
422
	{
423
		$return = $this->object->setLongitude( '10.5' );
424
425
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
426
		$this->assertEquals( '10.5', $this->object->getLongitude() );
427
		$this->assertTrue( $this->object->isModified() );
428
	}
429
430
431
	public function testGetLatitude()
432
	{
433
		$this->assertEquals( '50.0', $this->object->getLatitude() );
434
	}
435
436
437
	public function testSetLatitude()
438
	{
439
		$return = $this->object->setLatitude( '53.5' );
440
441
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
442
		$this->assertEquals( '53.5', $this->object->getLatitude() );
443
		$this->assertTrue( $this->object->isModified() );
444
	}
445
446
447
	public function testGetPosition()
448
	{
449
		$this->assertEquals( 1, $this->object->getPosition() );
450
	}
451
452
453
	public function testSetPosition()
454
	{
455
		$return = $this->object->setPosition( 555 );
456
457
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
458
		$this->assertEquals( 555, $this->object->getPosition() );
459
		$this->assertTrue( $this->object->isModified() );
460
	}
461
462
463
	public function testGetTimeModified()
464
	{
465
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
466
	}
467
468
469
	public function testGetTimeCreated()
470
	{
471
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
472
	}
473
474
475
	public function testGetEditor()
476
	{
477
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
478
	}
479
480
481
	public function testGetResourceType()
482
	{
483
		$this->assertEquals( 'supplier/address', $this->object->getResourceType() );
484
	}
485
486
487
	public function testCopyFrom()
488
	{
489
		$address = new \Aimeos\MShop\Order\Item\Address\Standard();
490
		$return = $this->object->copyFrom( $address );
491
492
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $return );
493
	}
494
495
	public function testFromArray()
496
	{
497
		$list = $entries = array(
498
			'supplier.address.id' => 1,
499
			'supplier.address.parentid' => 2,
500
			'supplier.address.salutation' => 'mr',
501
			'supplier.address.company' => 'mw',
502
			'supplier.address.vatid' => 'vatnumber',
503
			'supplier.address.title' => 'dr',
504
			'supplier.address.firstname' => 'first',
505
			'supplier.address.lastname' => 'last',
506
			'supplier.address.address1' => 'street',
507
			'supplier.address.address2' => 'no',
508
			'supplier.address.address3' => 'flat',
509
			'supplier.address.postal' => '12345',
510
			'supplier.address.city' => 'city',
511
			'supplier.address.state' => 'state',
512
			'supplier.address.countryid' => 'DE',
513
			'supplier.address.languageid' => 'de',
514
			'supplier.address.telephone' => '01234',
515
			'supplier.address.telefax' => '02345',
516
			'supplier.address.mobile' => '03456',
517
			'supplier.address.email' => '[email protected]',
518
			'supplier.address.website' => 'example.com',
519
			'supplier.address.longitude' => '10.0',
520
			'supplier.address.latitude' => '53.5',
521
			'supplier.address.birthday' => '2000-01-01',
522
			'supplier.address.position' => 4,
523
		);
524
525
		$object = new \Aimeos\MShop\Common\Item\Address\Standard( 'supplier.address.' );
526
		$object = $object->fromArray( $entries, true );
527
528
		$this->assertEquals( [], $entries );
529
		$this->assertEquals( '', $object->getSiteId() );
530
		$this->assertEquals( $list['supplier.address.id'], $object->getId() );
531
		$this->assertEquals( $list['supplier.address.parentid'], $object->getParentId() );
532
		$this->assertEquals( $list['supplier.address.salutation'], $object->getSalutation() );
533
		$this->assertEquals( $list['supplier.address.company'], $object->getCompany() );
534
		$this->assertEquals( $list['supplier.address.vatid'], $object->getVatID() );
535
		$this->assertEquals( $list['supplier.address.title'], $object->getTitle() );
536
		$this->assertEquals( $list['supplier.address.firstname'], $object->getFirstname() );
537
		$this->assertEquals( $list['supplier.address.lastname'], $object->getLastname() );
538
		$this->assertEquals( $list['supplier.address.address1'], $object->getAddress1() );
539
		$this->assertEquals( $list['supplier.address.address2'], $object->getAddress2() );
540
		$this->assertEquals( $list['supplier.address.address3'], $object->getAddress3() );
541
		$this->assertEquals( $list['supplier.address.postal'], $object->getPostal() );
542
		$this->assertEquals( $list['supplier.address.city'], $object->getCity() );
543
		$this->assertEquals( $list['supplier.address.state'], $object->getState() );
544
		$this->assertEquals( $list['supplier.address.countryid'], $object->getCountryId() );
545
		$this->assertEquals( $list['supplier.address.languageid'], $object->getLanguageId() );
546
		$this->assertEquals( $list['supplier.address.telephone'], $object->getTelephone() );
547
		$this->assertEquals( $list['supplier.address.telefax'], $object->getTelefax() );
548
		$this->assertEquals( $list['supplier.address.mobile'], $object->getMobile() );
549
		$this->assertEquals( $list['supplier.address.email'], $object->getEmail() );
550
		$this->assertEquals( $list['supplier.address.website'], $object->getWebsite() );
551
		$this->assertEquals( $list['supplier.address.longitude'], $object->getLongitude() );
552
		$this->assertEquals( $list['supplier.address.latitude'], $object->getLatitude() );
553
		$this->assertEquals( $list['supplier.address.position'], $object->getPosition() );
554
		$this->assertEquals( $list['supplier.address.birthday'], $object->getBirthday() );
555
	}
556
557
	public function testToArray()
558
	{
559
		$arrayObject = $this->object->toArray( true );
560
561
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
562
563
		$this->assertEquals( $this->object->getId(), $arrayObject['supplier.address.id'] );
564
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['supplier.address.siteid'] );
565
		$this->assertEquals( $this->object->getParentId(), $arrayObject['supplier.address.parentid'] );
566
		$this->assertEquals( $this->object->getPosition(), $arrayObject['supplier.address.position'] );
567
		$this->assertEquals( $this->object->getCompany(), $arrayObject['supplier.address.company'] );
568
		$this->assertEquals( $this->object->getVatID(), $arrayObject['supplier.address.vatid'] );
569
		$this->assertEquals( $this->object->getSalutation(), $arrayObject['supplier.address.salutation'] );
570
		$this->assertEquals( $this->object->getTitle(), $arrayObject['supplier.address.title'] );
571
		$this->assertEquals( $this->object->getFirstname(), $arrayObject['supplier.address.firstname'] );
572
		$this->assertEquals( $this->object->getLastname(), $arrayObject['supplier.address.lastname'] );
573
		$this->assertEquals( $this->object->getAddress1(), $arrayObject['supplier.address.address1'] );
574
		$this->assertEquals( $this->object->getAddress2(), $arrayObject['supplier.address.address2'] );
575
		$this->assertEquals( $this->object->getAddress3(), $arrayObject['supplier.address.address3'] );
576
		$this->assertEquals( $this->object->getPostal(), $arrayObject['supplier.address.postal'] );
577
		$this->assertEquals( $this->object->getCity(), $arrayObject['supplier.address.city'] );
578
		$this->assertEquals( $this->object->getState(), $arrayObject['supplier.address.state'] );
579
		$this->assertEquals( $this->object->getCountryId(), $arrayObject['supplier.address.countryid'] );
580
		$this->assertEquals( $this->object->getLanguageId(), $arrayObject['supplier.address.languageid'] );
581
		$this->assertEquals( $this->object->getTelephone(), $arrayObject['supplier.address.telephone'] );
582
		$this->assertEquals( $this->object->getTelefax(), $arrayObject['supplier.address.telefax'] );
583
		$this->assertEquals( $this->object->getMobile(), $arrayObject['supplier.address.mobile'] );
584
		$this->assertEquals( $this->object->getEmail(), $arrayObject['supplier.address.email'] );
585
		$this->assertEquals( $this->object->getWebsite(), $arrayObject['supplier.address.website'] );
586
		$this->assertEquals( $this->object->getLongitude(), $arrayObject['supplier.address.longitude'] );
587
		$this->assertEquals( $this->object->getLatitude(), $arrayObject['supplier.address.latitude'] );
588
		$this->assertEquals( $this->object->getBirthday(), $arrayObject['supplier.address.birthday'] );
589
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['supplier.address.ctime'] );
590
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['supplier.address.mtime'] );
591
		$this->assertEquals( $this->object->editor(), $arrayObject['supplier.address.editor'] );
592
	}
593
594
	public function testIsModified()
595
	{
596
		$this->assertFalse( $this->object->isModified() );
597
	}
598
}
599