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