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 |
||
23 | class SettingsManagerControllerTest extends AbstractElasticsearchTestCase |
||
24 | { |
||
25 | /** |
||
26 | * @var Client. |
||
27 | */ |
||
28 | private $client; |
||
29 | |||
30 | /** |
||
31 | * @var LoginTestHelper. |
||
32 | */ |
||
33 | private $loginHelper; |
||
34 | |||
35 | /** |
||
36 | * @var Container |
||
37 | */ |
||
38 | private $container; |
||
|
|||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | View Code Duplication | public function setUp() |
|
52 | |||
53 | /** |
||
54 | * Data provider for testCopyAction. |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | public function copyActionData() |
||
74 | |||
75 | /** |
||
76 | * Create setting. |
||
77 | */ |
||
78 | public function createSetting() |
||
83 | |||
84 | /** |
||
85 | * Data provider for testCreateAction(). |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | public function createActionData() |
||
102 | |||
103 | /** |
||
104 | * Test for createAction(). |
||
105 | * |
||
106 | * @param string $requestContent |
||
107 | * @param int $statusCode |
||
108 | * |
||
109 | * @dataProvider createActionData() |
||
110 | */ |
||
111 | public function testCreateAction($requestContent, $statusCode) |
||
116 | |||
117 | /** |
||
118 | * Test for copyAction. |
||
119 | * |
||
120 | * @param int $status |
||
121 | * @param string $url |
||
122 | * |
||
123 | * @dataProvider copyActionData() |
||
124 | */ |
||
125 | public function testCopyActionLogedIn($status, $url) |
||
131 | |||
132 | /** |
||
133 | * Test for copyAction after logged Out. |
||
134 | * |
||
135 | * @param int $status |
||
136 | * @param string $url |
||
137 | * |
||
138 | * @dataProvider copyActionData() |
||
139 | */ |
||
140 | public function testCopyActionLogedOut($status, $url) |
||
147 | |||
148 | /** |
||
149 | * Test for editAction(). |
||
150 | */ |
||
151 | public function testEditAction() |
||
157 | |||
158 | /** |
||
159 | * Data provider for testRemoveAction(). |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | public function removeActionData() |
||
176 | |||
177 | /** |
||
178 | * Test for removeAction(). |
||
179 | * |
||
180 | * @param string $url |
||
181 | * @param string $expectedStatusCode |
||
182 | * |
||
183 | * @dataProvider removeActionData() |
||
184 | */ |
||
185 | public function testRemoveAction($url, $expectedStatusCode) |
||
191 | |||
192 | /** |
||
193 | * Test ngEditAction and ensure cached value is cleared. |
||
194 | */ |
||
195 | public function testCacheClearAfterModify() |
||
219 | |||
220 | /** |
||
221 | * Assert value has been set. |
||
222 | * |
||
223 | * @param Client $client |
||
224 | * @param string $expectedValue |
||
225 | */ |
||
226 | protected function assertSettingValue(Client $client, $expectedValue) |
||
232 | |||
233 | /** |
||
234 | * Add domain_foo so that the setting can be read. |
||
235 | * |
||
236 | * @param Client $client |
||
237 | */ |
||
238 | protected function enableDomain(Client $client) |
||
249 | } |
||
250 |