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 |
||
20 | class SmokeTestRunCommandTest extends KernelTestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var Application |
||
24 | */ |
||
25 | private $application; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $commandConfiguration = []; |
||
31 | |||
32 | /** |
||
33 | * @var Command |
||
34 | */ |
||
35 | private $command; |
||
36 | |||
37 | /** |
||
38 | * @var CommandTester |
||
39 | */ |
||
40 | private $commandTester; |
||
41 | |||
42 | public function setUp() |
||
53 | |||
54 | public function tearDown() |
||
61 | |||
62 | View Code Duplication | public function testSmokeTestCommandNoLabels() |
|
82 | |||
83 | View Code Duplication | public function testSmokeTestCommandWipLabel() |
|
84 | { |
||
85 | $smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
||
86 | $smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
||
87 | $smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
||
88 | |||
89 | $smokeTest1 = $this->createMock(SmokeTestInterface::class); |
||
90 | $smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
||
91 | $smokeTest1->expects($this->once())->method('getDescription'); |
||
92 | |||
93 | $smokeTest2 = $this->createMock(SmokeTestInterface::class); |
||
94 | $smokeTest2->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput)); |
||
95 | $smokeTest2->expects($this->never())->method('getDescription'); |
||
96 | |||
97 | $smokeTestRunCommand = new SmokeTestRunCommand(); |
||
98 | $smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
||
99 | $smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
||
100 | |||
101 | $smokeTestRunCommand->run(new ArrayInput(['--label' => ['wip']]), new NullOutput()); |
||
102 | } |
||
103 | |||
104 | View Code Duplication | public function testSmokeTestCommandAllTests() |
|
105 | { |
||
106 | $smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
||
107 | $smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
||
108 | $smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
||
109 | |||
110 | $smokeTest1 = $this->createMock(SmokeTestInterface::class); |
||
111 | $smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
||
112 | $smokeTest1->expects($this->once())->method('getDescription'); |
||
113 | |||
114 | $smokeTest2 = $this->createMock(SmokeTestInterface::class); |
||
115 | $smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
||
116 | $smokeTest2->expects($this->once())->method('getDescription'); |
||
117 | |||
118 | $smokeTestRunCommand = new SmokeTestRunCommand(); |
||
119 | $smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
||
120 | $smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
||
121 | |||
122 | $smokeTestRunCommand->run(new ArrayInput(['--all' => true]), new NullOutput()); |
||
123 | } |
||
124 | |||
125 | public function testExecute() |
||
133 | |||
134 | public function testExecuteWithLabels() |
||
135 | { |
||
136 | $label = ['-l' => 'important']; |
||
137 | |||
138 | $this->setCommandConfiguration($label); |
||
139 | $output = $this->execute(); |
||
140 | |||
141 | $this->assertInternalType('string', $output); |
||
142 | $this->assertContains('Smoke Tests', $output); |
||
143 | $this->assertNotContains('Error', $output); |
||
144 | } |
||
145 | |||
146 | private function execute() |
||
156 | |||
157 | private function setCommandConfiguration($options = []) |
||
161 | } |
||
162 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..