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 |
||
11 | class TicketCest |
||
12 | { |
||
13 | private IndexPage $index; |
||
|
|||
14 | |||
15 | public function _before(Seller $I): void |
||
16 | { |
||
17 | $this->index = new IndexPage($I); |
||
18 | } |
||
19 | |||
20 | public function ensureIndexPageWorks(Seller $I): void |
||
21 | { |
||
22 | $I->login(); |
||
23 | $I->needPage(Url::to('@ticket/index')); |
||
24 | $I->see('Tickets', 'h1'); |
||
25 | $I->seeLink('Create ticket', Url::to('@ticket/create')); |
||
26 | $this->ensureICanSeeAdvancedSearchBox($I); |
||
27 | $this->ensureICanSeeBulkSearchBox(); |
||
28 | } |
||
29 | |||
30 | private function ensureICanSeeAdvancedSearchBox(Seller $I): void |
||
31 | { |
||
32 | $this->index->containsFilters([ |
||
33 | Input::asAdvancedSearch($I, 'Subject or 1st message'), |
||
34 | Select2::asAdvancedSearch($I, 'Author'), |
||
35 | Select2::asAdvancedSearch($I, 'Recipient'), |
||
36 | Select2::asAdvancedSearch($I, 'Status'), |
||
37 | Select2::asAdvancedSearch($I, 'Assignee'), |
||
38 | Select2::asAdvancedSearch($I, 'Priority'), |
||
39 | Select2::asAdvancedSearch($I, 'Watchers'), |
||
40 | Select2::asAdvancedSearch($I, 'Topics'), |
||
41 | ]); |
||
42 | } |
||
43 | |||
44 | private function ensureICanSeeBulkSearchBox(): void |
||
45 | { |
||
46 | $this->index->containsBulkButtons([ |
||
47 | 'Subscribe', |
||
48 | 'Unsubscribe', |
||
49 | 'Close', |
||
50 | ]); |
||
51 | $this->index->containsColumns([ |
||
52 | 'Subject', |
||
53 | 'Author', |
||
54 | 'Assignee', |
||
55 | 'Recipient', |
||
56 | 'Answers', |
||
57 | ]); |
||
58 | } |
||
59 | } |
||
60 |