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