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