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 |
||
37 | abstract class ViewTestCase extends FragmentTestCase |
||
38 | { |
||
39 | /** |
||
40 | * @var string the (short) name of the view |
||
41 | */ |
||
42 | protected $viewName; |
||
43 | |||
44 | /** |
||
45 | * @var mixed the result of the view execution |
||
46 | */ |
||
47 | protected $viewResult; |
||
48 | |||
49 | /** |
||
50 | * creates the view instance for this testcase |
||
51 | * |
||
52 | * @return View |
||
53 | * |
||
54 | * @author Felix Gilcher <[email protected]> |
||
55 | * @since 1.0.0 |
||
56 | */ |
||
57 | protected function createViewInstance() |
||
65 | |||
66 | /** |
||
67 | * runs the view instance for this testcase |
||
68 | * |
||
69 | * @param string $otName the name of the output type to run the view for |
||
70 | * null for the default output type |
||
71 | * |
||
72 | * @author Felix Gilcher <[email protected]> |
||
73 | * @since 1.0.0 |
||
74 | */ |
||
75 | protected function runView($otName = null) |
||
83 | |||
84 | /** |
||
85 | * assert that the view handles the given output type |
||
86 | * |
||
87 | * @param string $method the output type name |
||
88 | * @param boolean $acceptGeneric true if the generic 'execute' method should be accepted as handled |
||
89 | * @param string $message an optional message to display if the test fails |
||
90 | * |
||
91 | * @author Felix Gilcher <[email protected]> |
||
92 | * @since 1.0.0 |
||
93 | */ |
||
94 | View Code Duplication | protected function assertHandlesOutputType($method, $acceptGeneric = false, $message = '') |
|
101 | |||
102 | /** |
||
103 | * assert that the view does not handle the given output type |
||
104 | * |
||
105 | * @param string $method the output type name |
||
106 | * @param boolean $acceptGeneric true if the generic 'execute' method should be accepted as handled |
||
107 | * @param string $message an optional message to display if the test fails |
||
108 | * |
||
109 | * @author Felix Gilcher <[email protected]> |
||
110 | * @since 1.0.0 |
||
111 | */ |
||
112 | View Code Duplication | protected function assertNotHandlesOutputType($method, $acceptGeneric = false, $message = '') |
|
119 | |||
120 | /** |
||
121 | * assert that the response contains a redirect |
||
122 | * |
||
123 | * @param string $message the message to emit on failure |
||
124 | * |
||
125 | * @author Felix Gilcher <[email protected]> |
||
126 | * @since 1.0.0 |
||
127 | */ |
||
128 | View Code Duplication | protected function assertViewRedirects($message = 'Failed asserting that the view redirects') |
|
137 | |||
138 | /** |
||
139 | * assert that the response contains no redirect |
||
140 | * |
||
141 | * @param string $message the message to emit on failure |
||
142 | * |
||
143 | * @author Felix Gilcher <[email protected]> |
||
144 | * @since 1.0.0 |
||
145 | */ |
||
146 | View Code Duplication | protected function assertViewRedirectsNot($message = 'Failed asserting that the view does not redirect') |
|
155 | |||
156 | /** |
||
157 | * assert that the response contains the expected redirect |
||
158 | * |
||
159 | * @param mixed $expected the expected redirect |
||
160 | * @param string $message the message to emit on failure |
||
161 | * |
||
162 | * @author Felix Gilcher <[email protected]> |
||
163 | * @since 1.0.0 |
||
164 | */ |
||
165 | protected function assertViewRedirectsTo($expected, $message = 'Failed asserting that the view redirects to the given target.') |
||
174 | |||
175 | /** |
||
176 | * Assert that the view sets the given content type. |
||
177 | * |
||
178 | * this assertion only works on WebResponse or subclasses |
||
179 | * |
||
180 | * @param string $expected the expected content type |
||
181 | * @param string $message the message to emit on failure |
||
182 | * |
||
183 | * @author Felix Gilcher <[email protected]> |
||
184 | * @since 1.0.0 |
||
185 | */ |
||
186 | View Code Duplication | protected function assertViewSetsContentType($expected, $message = 'Failed asserting that the view sets the content type "%1$s".') |
|
195 | |||
196 | /** |
||
197 | * Assert that the view sets the given header with the given value. |
||
198 | * |
||
199 | * this response only works on WebResponse and subclasses |
||
200 | * |
||
201 | * @param string $expected the name of the expected header |
||
202 | * @param string $expectedValue the value of the expected header |
||
203 | * @param string $message the message to emit on failure |
||
204 | * |
||
205 | * @author Felix Gilcher <[email protected]> |
||
206 | * @since 1.0.0 |
||
207 | */ |
||
208 | View Code Duplication | protected function assertViewSetsHeader($expected, $expectedValue = null, $message = 'Failed asserting that the view sets a header named <%1$s> with the value <%2$s>') |
|
217 | |||
218 | /** |
||
219 | * Assert that the view sets the given cookie with the given value.<y></y> |
||
220 | * |
||
221 | * this response only works on WebResponse and subclasses |
||
222 | * |
||
223 | * @param string $expected the name of the expected cookie |
||
224 | * @param string $expectedValue the value of the expected header |
||
225 | * @param string $message the message to emit on failure |
||
226 | * |
||
227 | * @author Felix Gilcher <[email protected]> |
||
228 | * @since 1.0.0 |
||
229 | */ |
||
230 | protected function assertViewSetsCookie($expected, $expectedValue = null, $message = 'Failed asserting that the view sets a cookie named <%1$s> with a value of <%2$s>') |
||
239 | |||
240 | /** |
||
241 | * assert that the response has the given http status |
||
242 | * |
||
243 | * this assertion only works on WebResponse or subclasses |
||
244 | * |
||
245 | * @param string $expected the expected http status |
||
246 | * @param string $message the message to emit on failure |
||
247 | * |
||
248 | * @author Felix Gilcher <[email protected]> |
||
249 | * @since 1.0.0 |
||
250 | */ |
||
251 | View Code Duplication | protected function assertViewResponseHasHTTPStatus($expected, $message = 'Failed asserting that the response status is %1$s.') |
|
260 | |||
261 | /** |
||
262 | * assert that the response has the given content |
||
263 | * |
||
264 | * @param mixed $expected the expected content |
||
265 | * @param string $message the message to emit on failure |
||
266 | * |
||
267 | * @author Felix Gilcher <[email protected]> |
||
268 | * @since 1.0.0 |
||
269 | */ |
||
270 | protected function assertViewResponseHasContent($expected, $message = 'Failed asserting that the response has content <%1$s>.') |
||
275 | |||
276 | /** |
||
277 | * assert that the view result has the given content |
||
278 | * |
||
279 | * @param mixed $expected the expected content |
||
280 | * @param string $message the message to emit on failure |
||
281 | * |
||
282 | * @author Felix Gilcher <[email protected]> |
||
283 | * @since 1.0.0 |
||
284 | */ |
||
285 | protected function assertViewResultEquals($expected, $message = 'Failed asserting the expected view result.') |
||
289 | |||
290 | /** |
||
291 | * assert that the view forwards to the given module/controller |
||
292 | * |
||
293 | * @param string $expectedModule the expected module name |
||
294 | * @param string $expectedController the expected controller name |
||
295 | * @param string $message the message to emit on failure |
||
296 | * |
||
297 | * @author Felix Gilcher <[email protected]> |
||
298 | * @since 1.0.0 |
||
299 | */ |
||
300 | protected function assertViewForwards($expectedModule, $expectedController, $message = 'Failed asserting that the view forwards to "%1$s" "%2$s".') |
||
308 | |||
309 | /** |
||
310 | * assert that the view has the given layer |
||
311 | * |
||
312 | * @param string $expectedLayer the expected layer name |
||
313 | * @param string $message the message to emit on failure |
||
314 | * |
||
315 | * @author Felix Gilcher <[email protected]> |
||
316 | * @since 1.0.0 |
||
317 | */ |
||
318 | View Code Duplication | protected function assertHasLayer($expectedLayer, $message = 'Failed asserting that the view contains the layer "%1$s".') |
|
327 | |||
328 | /** |
||
329 | * assert that the view has the given layer |
||
330 | * |
||
331 | * @param string $expectedLayer the expected layer name |
||
332 | * @param string $message the message to emit on failure |
||
333 | * |
||
334 | * @author David Zülke <[email protected]> |
||
335 | * @since 1.0.6 |
||
336 | */ |
||
337 | View Code Duplication | protected function assertNotHasLayer($expectedLayer, $message = '') |
|
346 | } |
||
347 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.