| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace Tests; |
||
| 150 | public function testParameters() { |
||
| 151 | // Instantiate command |
||
| 152 | $command = new Command(); |
||
| 153 | $command->output = new BufferedOutput(); |
||
| 154 | $command->output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
||
| 155 | |||
| 156 | // Instiantiate file system |
||
| 157 | $root = vfsStream::setup('test')->url(); |
||
| 158 | $destination = $root.'/destination'; |
||
| 159 | mkdir($destination); |
||
| 160 | $history = $root.'/history'; |
||
| 161 | |||
| 162 | // Assert attribute assignation (default values) |
||
| 163 | $options = [ |
||
| 164 | 'destination' => getcwd(), |
||
| 165 | 'quantity' => '10', |
||
| 166 | 'history' => null, |
||
| 167 | 'featured' => false, |
||
| 168 | 'category' => '123', |
||
| 169 | ]; |
||
| 170 | |||
| 171 | // Instantiate task (default values) |
||
| 172 | $task = $this->getMock( |
||
| 173 | 'Simondubois\UnsplashDownloader\Task', |
||
| 174 | ['setDestination', 'setQuantity', 'setHistory', 'setFeatured', 'setCategory'] |
||
| 175 | ); |
||
| 176 | $task->expects($this->once())->method('setDestination')->with($this->identicalTo($options['destination'])); |
||
| 177 | $task->expects($this->once())->method('setQuantity')->with($this->identicalTo(intval($options['quantity']))); |
||
| 178 | $task->expects($this->once())->method('setHistory')->with($this->identicalTo($options['history'])); |
||
| 179 | $task->expects($this->once())->method('setFeatured')->with($this->identicalTo($options['featured'])); |
||
| 180 | $task->expects($this->once())->method('setCategory')->with($this->identicalTo(intval($options['category']))); |
||
| 181 | $command->parameters($this->mockValidate($options), $task, $options); |
||
| 182 | |||
| 183 | // Assert output content (default values) |
||
| 184 | $output = $command->output->fetch(); |
||
| 185 | $this->assertContains(getcwd(), $output); |
||
| 186 | $this->assertContains($options['quantity'], $output); |
||
| 187 | $this->assertContains('Do not use history.', $output); |
||
| 188 | $this->assertContains('featured and not featured', $output); |
||
| 189 | |||
| 190 | // Assert attribute assignation (custom values) |
||
| 191 | $options = [ |
||
| 192 | 'destination' => $destination, |
||
| 193 | 'quantity' => '100', |
||
| 194 | 'history' => $history, |
||
| 195 | 'featured' => true, |
||
| 196 | 'category' => null, |
||
| 197 | ]; |
||
| 198 | |||
| 199 | // Instantiate task (custom values) |
||
| 200 | $task = $this->getMock( |
||
| 201 | 'Simondubois\UnsplashDownloader\Task', |
||
| 202 | ['setDestination', 'setQuantity', 'setHistory', 'setFeatured', 'setCategory'] |
||
| 203 | ); |
||
| 204 | $task->expects($this->once())->method('setDestination')->with($this->identicalTo($options['destination'])); |
||
| 205 | $task->expects($this->once())->method('setQuantity')->with($this->identicalTo(intval($options['quantity']))); |
||
| 206 | $task->expects($this->once())->method('setHistory')->with($this->identicalTo($options['history'])); |
||
| 207 | $task->expects($this->once())->method('setFeatured')->with($this->identicalTo($options['featured'])); |
||
| 208 | $task->expects($this->once())->method('setCategory')->with($this->identicalTo($options['category'])); |
||
| 209 | $command->parameters($this->mockValidate($options), $task, $options); |
||
| 210 | |||
| 211 | // Assert output content (custom values) |
||
| 212 | $output = $command->output->fetch(); |
||
| 213 | $this->assertContains($options['destination'], $output); |
||
| 214 | $this->assertContains($options['quantity'], $output); |
||
| 215 | $this->assertContains($options['history'], $output); |
||
| 216 | $this->assertContains('only featured', $output); |
||
| 217 | } |
||
| 218 | |||
| 220 |