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 |
||
13 | class ContentTypeTest extends RESTFunctionalTestCase |
||
14 | { |
||
15 | /** |
||
16 | * Covers POST /content/typegroups. |
||
17 | */ |
||
18 | View Code Duplication | public function testCreateContentTypeGroup() |
|
43 | |||
44 | /** |
||
45 | * @depends testCreateContentTypeGroup |
||
46 | * Covers PATCH /content/typegroups/<contentTypeGroupId> |
||
47 | * |
||
48 | * @return string the updated content type href |
||
49 | */ |
||
50 | View Code Duplication | public function testUpdateContentTypeGroup($contentTypeGroupHref) |
|
72 | |||
73 | /** |
||
74 | * @depends testCreateContentTypeGroup |
||
75 | * @returns string The created content type href |
||
76 | * Covers POST /content/typegroups/<contentTypeGroupId>/types?publish=true |
||
77 | * |
||
78 | * @todo write test with full workflow (draft, edit, publish) |
||
79 | */ |
||
80 | public function testCreateContentType($contentTypeGroupHref) |
||
135 | |||
136 | /** |
||
137 | * @depends testCreateContentTypeGroup |
||
138 | * Covers GET /content/typegroups/<contentTypeGroupId> |
||
139 | * |
||
140 | * @param string $contentTypeGroupHref |
||
141 | */ |
||
142 | public function testListContentTypesForGroup($contentTypeGroupHref) |
||
150 | |||
151 | /** |
||
152 | * Covers GET /content/typegroups. |
||
153 | */ |
||
154 | public function testLoadContentTypeGroupList() |
||
163 | |||
164 | /** |
||
165 | * @depends testUpdateContentTypeGroup |
||
166 | * Covers GET /content/typegroups?identifier=<contentTypeGroupIdentifier> |
||
167 | */ |
||
168 | public function testLoadContentTypeGroupListWithIdentifier() |
||
176 | |||
177 | /** |
||
178 | * @depends testUpdateContentTypeGroup |
||
179 | * Covers GET /content/typegroups/<contentTypeGroupId> |
||
180 | * |
||
181 | * @param string $contentTypeGroupHref |
||
182 | */ |
||
183 | public function testLoadContentTypeGroup($contentTypeGroupHref) |
||
191 | |||
192 | /** |
||
193 | * @depends testUpdateContentTypeGroup |
||
194 | * Covers GET /content/typegroups/<contentTypeGroupId> |
||
195 | * |
||
196 | * @param string $contentTypeGroupHref |
||
197 | */ |
||
198 | public function testLoadContentTypeGroupNotFound($contentTypeGroupHref) |
||
206 | |||
207 | /** |
||
208 | * @depends testCreateContentType |
||
209 | * Covers GET /content/types/<contentTypeId> |
||
210 | */ |
||
211 | public function testLoadContentType($contentTypeHref) |
||
219 | |||
220 | /** |
||
221 | * @depends testCreateContentType |
||
222 | * Covers GET /content/types/<contentTypeId> |
||
223 | */ |
||
224 | public function testLoadContentTypeNotFound($contentTypeHref) |
||
232 | |||
233 | /** |
||
234 | * @depends testCreateContentType |
||
235 | * Covers GET /content/types |
||
236 | */ |
||
237 | public function testListContentTypes() |
||
245 | |||
246 | /** |
||
247 | * @depends testCreateContentType |
||
248 | * Covers GET /content/types?identifier=<contentTypeIdentifier> |
||
249 | */ |
||
250 | public function testListContentTypesByIdentifier() |
||
259 | |||
260 | /** |
||
261 | * @depends testCreateContentType |
||
262 | * Covers GET /content/types?remoteid=<contentTypeRemoteId> |
||
263 | */ |
||
264 | public function testListContentTypesByRemoteId() |
||
273 | |||
274 | /** |
||
275 | * @depends testCreateContentType |
||
276 | * Covers COPY /content/types/<contentTypeId> |
||
277 | * |
||
278 | * @return string The copied content type href |
||
279 | */ |
||
280 | public function testCopyContentType($sourceContentTypeHref) |
||
296 | |||
297 | /** |
||
298 | * Covers POST /content/type/<contentTypeId>. |
||
299 | * @depends testCopyContentType |
||
300 | * |
||
301 | * @return string the created content type draft href |
||
302 | */ |
||
303 | View Code Duplication | public function testCreateContentTypeDraft($contentTypeHref) |
|
331 | |||
332 | /** |
||
333 | * @depends testCreateContentTypeDraft |
||
334 | * Covers GET /content/types/<contentTypeId>/draft |
||
335 | */ |
||
336 | public function testLoadContentTypeDraft($contentTypeDraftHref) |
||
344 | |||
345 | /** |
||
346 | * @depends testCreateContentTypeDraft |
||
347 | * Covers PATCH /content/types/<contentTypeId>/draft |
||
348 | */ |
||
349 | View Code Duplication | public function testUpdateContentTypeDraft($contentTypeDraftHref) |
|
371 | |||
372 | /** |
||
373 | * Covers POST /content/types/<contentTypeId>/draft/fielddefinitions. |
||
374 | * @depends testCreateContentTypeDraft |
||
375 | * |
||
376 | * @return string The content type draft field definition href |
||
377 | */ |
||
378 | View Code Duplication | public function testAddContentTypeDraftFieldDefinition($contentTypeDraftHref) |
|
412 | |||
413 | /** |
||
414 | * @depends testCreateContentType |
||
415 | * Covers GET /content/types/<contentTypeId>/fieldDefinitions |
||
416 | * |
||
417 | * @return string the href of the first field definition in the list |
||
418 | */ |
||
419 | public function testContentTypeLoadFieldDefinitionList($contentTypeHref) |
||
431 | |||
432 | /** |
||
433 | * @depends testAddContentTypeDraftFieldDefinition |
||
434 | * Covers GET /content/types/<contentTypeId>/fieldDefinitions/<fieldDefinitionId> |
||
435 | * |
||
436 | * @param string $fieldDefinitionHref |
||
437 | * |
||
438 | * @throws \Psr\Http\Client\ClientException |
||
439 | */ |
||
440 | public function testLoadContentTypeFieldDefinition(string $fieldDefinitionHref) |
||
448 | |||
449 | /** |
||
450 | * @depends testAddContentTypeDraftFieldDefinition |
||
451 | * Covers PATCH /content/types/<contentTypeId>/fieldDefinitions/<fieldDefinitionId> |
||
452 | * |
||
453 | * @todo the spec says PUT... |
||
454 | */ |
||
455 | View Code Duplication | public function testUpdateContentTypeDraftFieldDefinition($fieldDefinitionHref) |
|
479 | |||
480 | /** |
||
481 | * Covers DELETE /content/types/<contentTypeId>/draft/fieldDefinitions/<fieldDefinitionId>. |
||
482 | * @depends testAddContentTypeDraftFieldDefinition |
||
483 | * |
||
484 | * @param string $fieldDefinitionHref |
||
485 | */ |
||
486 | public function deleteContentTypeDraftFieldDefinition(string $fieldDefinitionHref) |
||
494 | |||
495 | /** |
||
496 | * Covers DELETE /content/types/<contentTypeId>/draft. |
||
497 | * @depends testCreateContentTypeDraft |
||
498 | */ |
||
499 | public function testDeleteContentTypeDraft($contentTypeDraftHref) |
||
507 | |||
508 | /** |
||
509 | * @depends testCreateContentType |
||
510 | * Covers PUBLISH /content/types/<contentTypeId>/draft |
||
511 | */ |
||
512 | public function testPublishContentTypeDraft($contentTypeHref) |
||
523 | |||
524 | /** |
||
525 | * @depends testCreateContentType |
||
526 | * Covers GET /content/types/<contentTypeId>/groups |
||
527 | */ |
||
528 | public function testLoadGroupsOfContentType($contentTypeHref) |
||
536 | |||
537 | /** |
||
538 | * @depends testCreateContentType |
||
539 | * Covers POST /content/types/<contentTypeId>/groups |
||
540 | * |
||
541 | * @return string the content type href |
||
542 | */ |
||
543 | public function testLinkContentTypeToGroup($contentTypeHref) |
||
552 | |||
553 | /** |
||
554 | * @depends testLinkContentTypeToGroup |
||
555 | * Covers DELETE /content/types/{contentTypeId}/groups/{contentTypeGroupId} |
||
556 | */ |
||
557 | public function testUnlinkContentTypeFromGroup($contentTypeHref) |
||
565 | |||
566 | /** |
||
567 | * @depends testCreateContentType |
||
568 | */ |
||
569 | public function testDeleteContentType($contentTypeHref) |
||
577 | |||
578 | /** |
||
579 | * @depends testCreateContentTypeGroup |
||
580 | * Covers DELETE /content/typegroups/<contentTypeGroupId> |
||
581 | */ |
||
582 | public function testDeleteContentTypeGroupNotEmpty($contentTypeGroupHref) |
||
590 | } |
||
591 |