| Total Complexity | 61 |
| Total Lines | 602 |
| 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.company' => 'unitCompany', |
||
| 25 | 'customer.address.vatid' => 'DE999999999', |
||
| 26 | 'customer.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
||
| 27 | 'customer.address.title' => 'Herr', |
||
| 28 | 'customer.address.firstname' => 'firstunit', |
||
| 29 | 'customer.address.lastname' => 'lastunit', |
||
| 30 | 'customer.address.address1' => 'unit str.', |
||
| 31 | 'customer.address.address2' => '166', |
||
| 32 | 'customer.address.address3' => '4.OG', |
||
| 33 | 'customer.address.postal' => '22769', |
||
| 34 | 'customer.address.city' => 'Hamburg', |
||
| 35 | 'customer.address.state' => 'Hamburg', |
||
| 36 | 'customer.address.countryid' => 'DE', |
||
| 37 | 'customer.address.languageid' => 'de', |
||
| 38 | 'customer.address.telephone' => '05554433221', |
||
| 39 | 'customer.address.telefax' => '05554433222', |
||
| 40 | 'customer.address.mobile' => '05554433223', |
||
| 41 | 'customer.address.email' => '[email protected]', |
||
| 42 | 'customer.address.website' => 'www.example.com', |
||
| 43 | 'customer.address.longitude' => '10.0', |
||
| 44 | 'customer.address.latitude' => '50.0', |
||
| 45 | 'customer.address.position' => 1, |
||
| 46 | 'customer.address.birthday' => '2000-01-01', |
||
| 47 | 'customer.address.mtime' => '2011-01-01 00:00:02', |
||
| 48 | 'customer.address.ctime' => '2011-01-01 00:00:01', |
||
| 49 | 'customer.address.editor' => 'unitTestUser', |
||
| 50 | ); |
||
| 51 | |||
| 52 | $this->object = new \Aimeos\MShop\Customer\Item\Address\Standard( 'customer.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\Customer\Item\Address\Iface::class, $return ); |
||
| 73 | $this->assertTrue( $this->object->isModified() ); |
||
| 74 | $this->assertNull( $this->object->getId() ); |
||
| 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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\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\Customer\Item\Address\Iface::class, $return ); |
||
| 458 | $this->assertEquals( 555, $this->object->getPosition() ); |
||
| 459 | $this->assertTrue( $this->object->isModified() ); |
||
| 460 | } |
||
| 461 | |||
| 462 | |||
| 463 | public function testGetBirthday() |
||
| 464 | { |
||
| 465 | $this->assertEquals( '2000-01-01', $this->object->getBirthday() ); |
||
| 466 | } |
||
| 467 | |||
| 468 | |||
| 469 | public function testSetBirthday() |
||
| 470 | { |
||
| 471 | $return = $this->object->setBirthday( '1990-01-01' ); |
||
| 472 | |||
| 473 | $this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return ); |
||
| 474 | $this->assertEquals( '1990-01-01', $this->object->getBirthday() ); |
||
| 475 | $this->assertTrue( $this->object->isModified() ); |
||
| 476 | } |
||
| 477 | |||
| 478 | |||
| 479 | public function testGetTimeModified() |
||
| 480 | { |
||
| 481 | $this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
||
| 482 | } |
||
| 483 | |||
| 484 | |||
| 485 | public function testGetTimeCreated() |
||
| 486 | { |
||
| 487 | $this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
||
| 488 | } |
||
| 489 | |||
| 490 | |||
| 491 | public function testGetEditor() |
||
| 492 | { |
||
| 493 | $this->assertEquals( 'unitTestUser', $this->object->editor() ); |
||
| 494 | } |
||
| 495 | |||
| 496 | |||
| 497 | public function testGetResourceType() |
||
| 498 | { |
||
| 499 | $this->assertEquals( 'customer/address', $this->object->getResourceType() ); |
||
| 500 | } |
||
| 501 | |||
| 502 | |||
| 503 | public function testCopyFrom() |
||
| 509 | } |
||
| 510 | |||
| 511 | |||
| 512 | public function testFromArray() |
||
| 572 | } |
||
| 573 | |||
| 574 | public function testToArray() |
||
| 609 | } |
||
| 610 | |||
| 611 | public function testIsModified() |
||
| 612 | { |
||
| 613 | $this->assertFalse( $this->object->isModified() ); |
||
| 614 | } |
||
| 615 | } |
||
| 616 |