| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 164 | public function testDetermineServices() |
||
| 165 | { |
||
| 166 | $services = [ |
||
| 167 | [ |
||
| 168 | '$ref' => 'http://localhost/core/product/', |
||
| 169 | 'profile' => 'http://localhost/schema/core/product/collection' |
||
| 170 | ], |
||
| 171 | [ |
||
| 172 | '$ref' => 'http://localhost/core/app/', |
||
| 173 | 'profile' => 'http://localhost/schema/core/app/collection' |
||
| 174 | ], |
||
| 175 | ]; |
||
| 176 | |||
| 177 | $routerDouble = $this->getMockBuilder('\Symfony\Component\Routing\Router') |
||
| 178 | ->disableOriginalConstructor() |
||
| 179 | ->setMethods(array('generate')) |
||
| 180 | ->getMock(); |
||
| 181 | $routerDouble |
||
| 182 | ->expects($this->exactly(4)) |
||
| 183 | ->method('generate') |
||
| 184 | ->with( |
||
| 185 | $this->isType('string'), |
||
| 186 | $this->isType('array'), |
||
| 187 | $this->isType('boolean') |
||
| 188 | ) |
||
| 189 | ->will( |
||
| 190 | $this->onConsecutiveCalls( |
||
| 191 | $this->returnValue($services[0]['$ref']), |
||
| 192 | $this->returnValue($services[0]['profile']), |
||
| 193 | $this->returnValue($services[1]['$ref']), |
||
| 194 | $this->returnValue($services[1]['profile']) |
||
| 195 | ) |
||
| 196 | ); |
||
| 197 | |||
| 198 | $responseDouble = $this->getMock('Symfony\Component\HttpFoundation\Response'); |
||
| 199 | $restUtilsDouble = $this->getMock('Graviton\RestBundle\Service\RestUtilsInterface'); |
||
| 200 | $templateDouble = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface'); |
||
| 201 | $apiLoaderDouble = $this->getMock('Graviton\ProxyBundle\Service\ApiDefinitionLoader'); |
||
| 202 | $configuration = [ |
||
| 203 | 'petstore' => [ |
||
| 204 | 'prefix' => 'petstore', |
||
| 205 | 'uri' => 'http://petstore.swagger.io/v2/swagger.json' |
||
| 206 | ] |
||
| 207 | ]; |
||
| 208 | |||
| 209 | $optionRoutes = [ |
||
| 210 | "graviton.core.rest.app.options" => $routerDouble, |
||
| 211 | "graviton.core.rest.product.options" => $routerDouble, |
||
| 212 | ]; |
||
| 213 | |||
| 214 | $controller = $this->getProxyBuilder('\Graviton\CoreBundle\Controller\MainController') |
||
| 215 | ->setConstructorArgs( |
||
| 216 | [ |
||
| 217 | $routerDouble, |
||
| 218 | $responseDouble, |
||
| 219 | $restUtilsDouble, |
||
| 220 | $templateDouble, |
||
| 221 | $apiLoaderDouble, |
||
| 222 | [], |
||
| 223 | [], |
||
| 224 | $configuration, |
||
| 225 | ] |
||
| 226 | ) |
||
| 227 | ->setMethods(array('determineServices')) |
||
| 228 | ->getProxy(); |
||
| 229 | |||
| 230 | $this->assertEquals( |
||
| 231 | [ |
||
| 232 | [ |
||
| 233 | '$ref' => 'http://localhost/core/app/', |
||
| 234 | 'profile' => 'http://localhost/schema/core/app/collection' |
||
| 235 | ], |
||
| 236 | [ |
||
| 237 | '$ref' => 'http://localhost/core/product/', |
||
| 238 | 'profile' => 'http://localhost/schema/core/product/collection' |
||
| 239 | ], |
||
| 240 | ], |
||
| 241 | $controller->determineServices($optionRoutes) |
||
| 242 | ); |
||
| 243 | } |
||
| 244 | |||
| 261 |