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 |
||
15 | class FileSenderTest extends \PHPUnit_Framework_TestCase |
||
16 | { |
||
17 | /** |
||
18 | * checks if FileSender does nothing if nothing is needed |
||
19 | * |
||
20 | * @dataProvider requestTypeProvider |
||
21 | * @covers Graviton\ImportExport\Service\FileSender |
||
22 | * |
||
23 | * @param string $type type of request to test |
||
24 | * @return void |
||
25 | */ |
||
26 | View Code Duplication | public function testSenderDoesPlainRequestWithoutUploadField($type) |
|
46 | |||
47 | /** |
||
48 | * checks if FileSender does nothing if it gets a falsy file path |
||
49 | * |
||
50 | * This test was added post-implementation, be sure to check if it is really what |
||
51 | * you need if you read this. |
||
52 | * |
||
53 | * @dataProvider requestTypeProvider |
||
54 | * @covers Graviton\ImportExport\Service\FileSender |
||
55 | * |
||
56 | * @param string $type type of request to test |
||
57 | * @return void |
||
58 | */ |
||
59 | View Code Duplication | public function testSenderDoesPlainRequestWithFalsyUploadField($type) |
|
82 | |||
83 | /** |
||
84 | * test if FileSender excepts to being called without json in upload cases |
||
85 | * |
||
86 | * @dataProvider requestTypeProvider |
||
87 | * @covers Graviton\ImportExport\Service\FileSender |
||
88 | * |
||
89 | * @param string $type type of request to test |
||
90 | * @return void |
||
91 | */ |
||
92 | public function testExceptsToBeingCalledWithoutJsonDataInUploadCase($type) |
||
111 | |||
112 | |||
113 | /** |
||
114 | * checks if FileSender mangles the options before passing them to the client |
||
115 | * |
||
116 | * @dataProvider requestTypeProvider |
||
117 | * @covers Graviton\ImportExport\Service\FileSender |
||
118 | * |
||
119 | * @param string $type type of request to test |
||
120 | * @return void |
||
121 | */ |
||
122 | public function testSenderManglesOptionsIfUploadHasBeenPassed($type) |
||
162 | |||
163 | /** |
||
164 | * @return array |
||
165 | */ |
||
166 | public function requestTypeProvider() |
||
173 | } |
||
174 |