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:
Complex classes like RepositoryTest 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 RepositoryTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class RepositoryTest extends BaseTest |
||
23 | { |
||
24 | /** |
||
25 | * Test for the getContentService() method. |
||
26 | * |
||
27 | * @group content |
||
28 | * @group user |
||
29 | * |
||
30 | * @see \eZ\Publish\API\Repository\Repository::getContentService() |
||
31 | */ |
||
32 | public function testGetContentService() |
||
40 | |||
41 | /** |
||
42 | * Test for the getContentLanguageService() method. |
||
43 | * |
||
44 | * @group language |
||
45 | * |
||
46 | * @see \eZ\Publish\API\Repository\Repository::getContentLanguageService() |
||
47 | */ |
||
48 | public function testGetContentLanguageService() |
||
56 | |||
57 | /** |
||
58 | * Test for the getContentTypeService() method. |
||
59 | * |
||
60 | * @group content-type |
||
61 | * @group field-type |
||
62 | * @group user |
||
63 | * |
||
64 | * @see \eZ\Publish\API\Repository\Repository::getContentTypeService() |
||
65 | */ |
||
66 | public function testGetContentTypeService() |
||
74 | |||
75 | /** |
||
76 | * Test for the getLocationService() method. |
||
77 | * |
||
78 | * @group location |
||
79 | * |
||
80 | * @see \eZ\Publish\API\Repository\Repository::getLocationService() |
||
81 | */ |
||
82 | public function testGetLocationService() |
||
90 | |||
91 | /** |
||
92 | * Test for the getSectionService() method. |
||
93 | * |
||
94 | * @group section |
||
95 | * |
||
96 | * @see \eZ\Publish\API\Repository\Repository::getSectionService() |
||
97 | */ |
||
98 | public function testGetSectionService() |
||
106 | |||
107 | /** |
||
108 | * Test for the getUserService() method. |
||
109 | * |
||
110 | * @group user |
||
111 | * |
||
112 | * @see \eZ\Publish\API\Repository\Repository::getUserService() |
||
113 | */ |
||
114 | public function testGetUserService() |
||
122 | |||
123 | /** |
||
124 | * Test for the getTrashService() method. |
||
125 | * |
||
126 | * @group trash |
||
127 | * |
||
128 | * @see \eZ\Publish\API\Repository\Repository::getTrashService() |
||
129 | */ |
||
130 | public function testGetTrashService() |
||
138 | |||
139 | /** |
||
140 | * Test for the getRoleService() method. |
||
141 | * |
||
142 | * @group role |
||
143 | * |
||
144 | * @see \eZ\Publish\API\Repository\Repository::getRoleService() |
||
145 | */ |
||
146 | public function testGetRoleService() |
||
154 | |||
155 | /** |
||
156 | * Test for the getURLAliasService() method. |
||
157 | * |
||
158 | * @group url-alias |
||
159 | * |
||
160 | * @see \eZ\Publish\API\Repository\Repository::getURLAliasService() |
||
161 | */ |
||
162 | public function testGetURLAliasService() |
||
170 | |||
171 | /** |
||
172 | * Test for the getUrlWildcardService() method. |
||
173 | * |
||
174 | * @group url-wildcard |
||
175 | * |
||
176 | * @see \eZ\Publish\API\Repository\Repository::getUrlWildcardService() |
||
177 | */ |
||
178 | public function testGetURLWildcardService() |
||
186 | |||
187 | /** |
||
188 | * Test for the getObjectStateService(). |
||
189 | * |
||
190 | * @group object-state |
||
191 | * |
||
192 | * @see \eZ\Publish\API\Repository\Repository::getObjectStateService() |
||
193 | */ |
||
194 | public function testGetObjectStateService() |
||
202 | |||
203 | /** |
||
204 | * Test for the getFieldTypeService(). |
||
205 | * |
||
206 | * @group object-state |
||
207 | * |
||
208 | * @see \eZ\Publish\API\Repository\Repository::getFieldTypeService() |
||
209 | */ |
||
210 | public function testGetFieldTypeService() |
||
218 | |||
219 | /** |
||
220 | * Test for the getSearchService() method. |
||
221 | * |
||
222 | * @group search |
||
223 | * |
||
224 | * @see \eZ\Publish\API\Repository\Repository::getSearchService() |
||
225 | */ |
||
226 | public function testGetSearchService() |
||
235 | |||
236 | /** |
||
237 | * Test for the getSearchService() method. |
||
238 | * |
||
239 | * @group permission |
||
240 | * |
||
241 | * @see \eZ\Publish\API\Repository\Repository::getPermissionResolver() |
||
242 | */ |
||
243 | public function testGetPermissionResolver() |
||
244 | { |
||
245 | $repository = $this->getRepository(); |
||
246 | |||
247 | $this->assertInstanceOf( |
||
248 | '\\eZ\\Publish\\API\\Repository\\PermissionResolver', |
||
249 | $repository->getPermissionResolver() |
||
250 | ); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Test for the commit() method. |
||
255 | * |
||
256 | * @see \eZ\Publish\API\Repository\Repository::commit() |
||
257 | */ |
||
258 | public function testCommit() |
||
271 | |||
272 | /** |
||
273 | * Test for the commit() method. |
||
274 | * |
||
275 | * @see \eZ\Publish\API\Repository\Repository::commit() |
||
276 | * @expectedException \RuntimeException |
||
277 | */ |
||
278 | public function testCommitThrowsRuntimeException() |
||
283 | |||
284 | /** |
||
285 | * Test for the rollback() method. |
||
286 | * |
||
287 | * @see \eZ\Publish\API\Repository\Repository::rollback() |
||
288 | */ |
||
289 | public function testRollback() |
||
295 | |||
296 | /** |
||
297 | * Test for the rollback() method. |
||
298 | * |
||
299 | * @see \eZ\Publish\API\Repository\Repository::rollback() |
||
300 | * @expectedException \RuntimeException |
||
301 | */ |
||
302 | public function testRollbackThrowsRuntimeException() |
||
307 | |||
308 | /** |
||
309 | * Test for the getCurrentUser() method. |
||
310 | * |
||
311 | * @group content |
||
312 | * @group user |
||
313 | * |
||
314 | * @see \eZ\Publish\API\Repository\Repository::getCurrentUser() |
||
315 | */ |
||
316 | public function testGetCurrentUserReturnsAnonymousUser() |
||
338 | |||
339 | /** |
||
340 | * Test for the setCurrentUser() method. |
||
341 | * |
||
342 | * @group content |
||
343 | * @group user |
||
344 | * |
||
345 | * @see \eZ\Publish\API\Repository\Repository::setCurrentUser() |
||
346 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
347 | */ |
||
348 | View Code Duplication | public function testSetCurrentUser() |
|
382 | |||
383 | /** |
||
384 | * Test for the hasAccess() method. |
||
385 | * |
||
386 | * @see \eZ\Publish\API\Repository\Repository::hasAccess() |
||
387 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
388 | */ |
||
389 | public function testHasAccessWithAnonymousUserNo() |
||
409 | |||
410 | /** |
||
411 | * Test for the hasAccess() method. |
||
412 | * |
||
413 | * @see \eZ\Publish\API\Repository\Repository::hasAccess() |
||
414 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
415 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessWithAnonymousUserNo |
||
416 | */ |
||
417 | public function testHasAccessForCurrentUserNo() |
||
440 | |||
441 | /** |
||
442 | * Test for the hasAccess() method. |
||
443 | * |
||
444 | * @see \eZ\Publish\API\Repository\Repository::hasAccess() |
||
445 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
446 | */ |
||
447 | public function testHasAccessWithAdministratorUser() |
||
467 | |||
468 | /** |
||
469 | * Test for the hasAccess() method. |
||
470 | * |
||
471 | * @see \eZ\Publish\API\Repository\Repository::hasAccess() |
||
472 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
473 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
||
474 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessWithAdministratorUser |
||
475 | */ |
||
476 | public function testHasAccessForCurrentUserYes() |
||
499 | |||
500 | /** |
||
501 | * Test for the hasAccess() method. |
||
502 | * |
||
503 | * @see \eZ\Publish\API\Repository\Repository::hasAccess() |
||
504 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
505 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
||
506 | */ |
||
507 | View Code Duplication | public function testHasAccessLimited() |
|
528 | |||
529 | /** |
||
530 | * Test for the canUser() method. |
||
531 | * |
||
532 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
533 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
534 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
535 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessForCurrentUserNo |
||
536 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
537 | */ |
||
538 | public function testCanUserForAnonymousUserNo() |
||
572 | |||
573 | /** |
||
574 | * Test for the canUser() method. |
||
575 | * |
||
576 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
577 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
578 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
579 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessForCurrentUserYes |
||
580 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
581 | */ |
||
582 | View Code Duplication | public function testCanUserForAdministratorUser() |
|
615 | |||
616 | /** |
||
617 | * Test for the canUser() method. |
||
618 | * |
||
619 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
620 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
621 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
622 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
623 | */ |
||
624 | public function testCanUserWithLimitationYes() |
||
649 | |||
650 | /** |
||
651 | * Test for the canUser() method. |
||
652 | * |
||
653 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
654 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
655 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
656 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
657 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
658 | */ |
||
659 | public function testCanUserWithLimitationNo() |
||
690 | |||
691 | /** |
||
692 | * Test for the canUser() method. |
||
693 | * |
||
694 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
695 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
696 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
697 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
||
698 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
699 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
700 | */ |
||
701 | public function testCanUserThrowsInvalidArgumentException() |
||
726 | |||
727 | /** |
||
728 | * Test for the canUser() method. |
||
729 | * |
||
730 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
731 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
732 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
733 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
734 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
735 | */ |
||
736 | View Code Duplication | public function testCanUserWithTargetYes() |
|
785 | |||
786 | /** |
||
787 | * Test for the canUser() method. |
||
788 | * |
||
789 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
790 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
791 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
792 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
793 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
794 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
795 | */ |
||
796 | View Code Duplication | public function testCanUserWithTargetNo() |
|
842 | |||
843 | /** |
||
844 | * Test for the canUser() method. |
||
845 | * |
||
846 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
847 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
848 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
849 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
850 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
851 | */ |
||
852 | View Code Duplication | public function testCanUserWithMultipleTargetsYes() |
|
902 | |||
903 | /** |
||
904 | * Test for the canUser() method. |
||
905 | * |
||
906 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
907 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
908 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
909 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
910 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
911 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
912 | */ |
||
913 | View Code Duplication | public function testCanUserWithMultipleTargetsNo() |
|
960 | |||
961 | /** |
||
962 | * Test for the canUser() method. |
||
963 | * |
||
964 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
965 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
966 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
967 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
||
968 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
969 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
970 | */ |
||
971 | public function testCanUserWithTargetThrowsInvalidArgumentException() |
||
1000 | |||
1001 | /** |
||
1002 | * Test for the canUser() method. |
||
1003 | * |
||
1004 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
1005 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
1006 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
1007 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
1008 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetURLAliasService |
||
1009 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
||
1010 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
||
1011 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1012 | */ |
||
1013 | View Code Duplication | public function testCanUserWithTargetThrowsInvalidArgumentExceptionVariant() |
|
1046 | |||
1047 | /** |
||
1048 | * Test for the canUser() method. |
||
1049 | * |
||
1050 | * @see \eZ\Publish\API\Repository\Repository::canUser() |
||
1051 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1052 | */ |
||
1053 | public function testCanUserThrowsBadStateException() |
||
1059 | } |
||
1060 |
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.