Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 22 | class SectionServiceTest extends BaseTest |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Tests that the required <b>ContentService::loadContentInfoByRemoteId()</b> |
||
| 26 | * at least returns an object, because this method is utilized in several |
||
| 27 | * tests,. |
||
| 28 | */ |
||
| 29 | View Code Duplication | protected function setUp() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Test for the newSectionCreateStruct() method. |
||
| 64 | * |
||
| 65 | * @see \eZ\Publish\API\Repository\SectionService::newSectionCreateStruct() |
||
| 66 | */ |
||
| 67 | public function testNewSectionCreateStruct() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Test for the createSection() method. |
||
| 82 | * |
||
| 83 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 84 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testNewSectionCreateStruct |
||
| 85 | */ |
||
| 86 | public function testCreateSection() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Test for the createSection() method. |
||
| 105 | * |
||
| 106 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 107 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 108 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 109 | */ |
||
| 110 | public function testCreateSectionThrowsInvalidArgumentException() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Test for the loadSection() method. |
||
| 134 | * |
||
| 135 | * @see \eZ\Publish\API\Repository\SectionService::loadSection() |
||
| 136 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 137 | */ |
||
| 138 | public function testLoadSection() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Test for the loadSection() method. |
||
| 156 | * |
||
| 157 | * @see \eZ\Publish\API\Repository\SectionService::loadSection() |
||
| 158 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 159 | */ |
||
| 160 | public function testLoadSectionThrowsNotFoundException() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Test for the newSectionUpdateStruct() method. |
||
| 176 | * |
||
| 177 | * @see \eZ\Publish\API\Repository\SectionService::newSectionUpdateStruct() |
||
| 178 | */ |
||
| 179 | public function testNewSectionUpdateStruct() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Test for the updateSection() method. |
||
| 194 | * |
||
| 195 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
||
| 196 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 197 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSection |
||
| 198 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testNewSectionUpdateStruct |
||
| 199 | */ |
||
| 200 | public function testUpdateSection() |
||
| 201 | { |
||
| 202 | $repository = $this->getRepository(); |
||
| 203 | |||
| 204 | $standardSectionId = $this->generateId('section', 1); |
||
| 205 | /* BEGIN: Use Case */ |
||
| 206 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
||
| 207 | // Publish demo installation. |
||
| 208 | |||
| 209 | $sectionService = $repository->getSectionService(); |
||
| 210 | |||
| 211 | $section = $sectionService->loadSection($standardSectionId); |
||
| 212 | |||
| 213 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
||
| 214 | $sectionUpdate->name = 'New section name'; |
||
| 215 | $sectionUpdate->identifier = 'newUniqueKey'; |
||
| 216 | |||
| 217 | $updatedSection = $sectionService->updateSection($section, $sectionUpdate); |
||
| 218 | /* END: Use Case */ |
||
| 219 | |||
| 220 | // Verify that service returns an instance of Section |
||
| 221 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Section', $updatedSection); |
||
| 222 | |||
| 223 | // Verify that the service also persists the changes |
||
| 224 | $updatedSection = $sectionService->loadSection($standardSectionId); |
||
| 225 | |||
| 226 | $this->assertEquals('New section name', $updatedSection->name); |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Test for the updateSection() method. |
||
| 231 | * |
||
| 232 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
||
| 233 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 234 | */ |
||
| 235 | public function testUpdateSectionKeepsSectionIdentifierOnNameUpdate() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Test for the updateSection() method. |
||
| 258 | * |
||
| 259 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
||
| 260 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 261 | */ |
||
| 262 | public function testUpdateSectionWithSectionIdentifierOnNameUpdate() |
||
| 263 | { |
||
| 264 | $repository = $this->getRepository(); |
||
| 265 | |||
| 266 | $standardSectionId = $this->generateId('section', 1); |
||
| 267 | /* BEGIN: Use Case */ |
||
| 268 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
||
| 269 | // Publish demo installation. |
||
| 270 | |||
| 271 | $sectionService = $repository->getSectionService(); |
||
| 272 | |||
| 273 | $section = $sectionService->loadSection($standardSectionId); |
||
| 274 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
||
| 275 | $sectionUpdate->name = 'New section name'; |
||
| 276 | |||
| 277 | // section identifier remains the same |
||
| 278 | $sectionUpdate->identifier = $section->identifier; |
||
| 279 | |||
| 280 | $updatedSection = $sectionService->updateSection($section, $sectionUpdate); |
||
| 281 | /* END: Use Case */ |
||
| 282 | |||
| 283 | $this->assertEquals('standard', $updatedSection->identifier); |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Test for the updateSection() method. |
||
| 288 | * |
||
| 289 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
||
| 290 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 291 | */ |
||
| 292 | public function testUpdateSectionKeepsSectionNameOnIdentifierUpdate() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Test for the updateSection() method. |
||
| 316 | * |
||
| 317 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
||
| 318 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 319 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 320 | */ |
||
| 321 | public function testUpdateSectionThrowsInvalidArgumentException() |
||
| 322 | { |
||
| 323 | $repository = $this->getRepository(); |
||
| 324 | |||
| 325 | $standardSectionId = $this->generateId('section', 1); |
||
| 326 | /* BEGIN: Use Case */ |
||
| 327 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
||
| 328 | // Publish demo installation. |
||
| 329 | |||
| 330 | $sectionService = $repository->getSectionService(); |
||
| 331 | |||
| 332 | // Create section with conflict identifier |
||
| 333 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
||
| 334 | $sectionCreate->name = 'Conflict section'; |
||
| 335 | $sectionCreate->identifier = 'conflictKey'; |
||
| 336 | |||
| 337 | $sectionService->createSection($sectionCreate); |
||
| 338 | |||
| 339 | // Load an existing section and update to an existing identifier |
||
| 340 | $section = $sectionService->loadSection($standardSectionId); |
||
| 341 | |||
| 342 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
||
| 343 | $sectionUpdate->identifier = 'conflictKey'; |
||
| 344 | |||
| 345 | // This call should fail with an InvalidArgumentException |
||
| 346 | $sectionService->updateSection($section, $sectionUpdate); |
||
| 347 | /* END: Use Case */ |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Test for the loadSections() method. |
||
| 352 | * |
||
| 353 | * @see \eZ\Publish\API\Repository\SectionService::loadSections() |
||
| 354 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 355 | */ |
||
| 356 | public function testLoadSections() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Test for the loadSections() method. |
||
| 374 | * |
||
| 375 | * @see \eZ\Publish\API\Repository\SectionService::loadSections() |
||
| 376 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 377 | */ |
||
| 378 | public function testLoadSectionsReturnsDefaultSectionsByDefault() |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Test for the loadSectionByIdentifier() method. |
||
| 435 | * |
||
| 436 | * @see \eZ\Publish\API\Repository\SectionService::loadSectionByIdentifier() |
||
| 437 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 438 | */ |
||
| 439 | View Code Duplication | public function testLoadSectionByIdentifier() |
|
| 440 | { |
||
| 441 | $repository = $this->getRepository(); |
||
| 442 | |||
| 443 | /* BEGIN: Use Case */ |
||
| 444 | $sectionService = $repository->getSectionService(); |
||
| 445 | |||
| 446 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
||
| 447 | $sectionCreate->name = 'Test Section'; |
||
| 448 | $sectionCreate->identifier = 'uniqueKey'; |
||
| 449 | |||
| 450 | $sectionId = $sectionService->createSection($sectionCreate)->id; |
||
| 451 | |||
| 452 | $section = $sectionService->loadSectionByIdentifier('uniqueKey'); |
||
| 453 | /* END: Use Case */ |
||
| 454 | |||
| 455 | $this->assertEquals($sectionId, $section->id); |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Test for the loadSectionByIdentifier() method. |
||
| 460 | * |
||
| 461 | * @see \eZ\Publish\API\Repository\SectionService::loadSectionByIdentifier() |
||
| 462 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 463 | */ |
||
| 464 | public function testLoadSectionByIdentifierThrowsNotFoundException() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Test for the countAssignedContents() method. |
||
| 478 | * |
||
| 479 | * @see \eZ\Publish\API\Repository\SectionService::countAssignedContents() |
||
| 480 | */ |
||
| 481 | View Code Duplication | public function testCountAssignedContents() |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Test for the isSectionUsed() method. |
||
| 507 | * |
||
| 508 | * @see \eZ\Publish\API\Repository\SectionService::isSectionUsed() |
||
| 509 | */ |
||
| 510 | View Code Duplication | public function testIsSectionUsed() |
|
| 533 | |||
| 534 | /** |
||
| 535 | * Test for the assignSection() method. |
||
| 536 | * |
||
| 537 | * @see \eZ\Publish\API\Repository\SectionService::assignSection() |
||
| 538 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCountAssignedContents |
||
| 539 | */ |
||
| 540 | public function testAssignSection() |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Test for the countAssignedContents() method. |
||
| 593 | * |
||
| 594 | * @see \eZ\Publish\API\Repository\SectionService::countAssignedContents() |
||
| 595 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 596 | */ |
||
| 597 | public function testCountAssignedContentsReturnsZeroByDefault() |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Test for the isSectionUsed() method. |
||
| 619 | * |
||
| 620 | * @see \eZ\Publish\API\Repository\SectionService::isSectionUsed() |
||
| 621 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 622 | */ |
||
| 623 | public function testIsSectionUsedReturnsZeroByDefault() |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Test for the deleteSection() method. |
||
| 645 | * |
||
| 646 | * @see \eZ\Publish\API\Repository\SectionService::deleteSection() |
||
| 647 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSections |
||
| 648 | */ |
||
| 649 | public function testDeleteSection() |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Test for the deleteSection() method. |
||
| 671 | * |
||
| 672 | * @see \eZ\Publish\API\Repository\SectionService::deleteSection() |
||
| 673 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 674 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testDeleteSection |
||
| 675 | */ |
||
| 676 | public function testDeleteSectionThrowsNotFoundException() |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Test for the deleteSection() method. |
||
| 699 | * |
||
| 700 | * @see \eZ\Publish\API\Repository\SectionService::deleteSection() |
||
| 701 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 702 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testAssignSection |
||
| 703 | */ |
||
| 704 | public function testDeleteSectionThrowsBadStateException() |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Test for the createSection() method. |
||
| 735 | * |
||
| 736 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 737 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 738 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
||
| 739 | */ |
||
| 740 | View Code Duplication | public function testCreateSectionInTransactionWithRollback() |
|
| 777 | |||
| 778 | /** |
||
| 779 | * Test for the createSection() method. |
||
| 780 | * |
||
| 781 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 782 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
||
| 783 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
||
| 784 | */ |
||
| 785 | public function testCreateSectionInTransactionWithCommit() |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Test for the createSection() method. |
||
| 821 | * |
||
| 822 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 823 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 824 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
||
| 825 | */ |
||
| 826 | View Code Duplication | public function testUpdateSectionInTransactionWithRollback() |
|
| 861 | |||
| 862 | /** |
||
| 863 | * Test for the createSection() method. |
||
| 864 | * |
||
| 865 | * @see \eZ\Publish\API\Repository\SectionService::createSection() |
||
| 866 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
||
| 867 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
||
| 868 | */ |
||
| 869 | View Code Duplication | public function testUpdateSectionInTransactionWithCommit() |
|
| 904 | } |
||
| 905 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.