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