| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| Code Lines | 58 |
| 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 |
||
| 22 | public function testProcess() |
||
| 23 | { |
||
| 24 | $message = 'The service (strategy.doesnotExists) is not registered in the application kernel.'; |
||
| 25 | |||
| 26 | $loggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface') |
||
| 27 | ->setMethods(array('warning')) |
||
| 28 | ->getMockForAbstractClass(); |
||
| 29 | $loggerMock |
||
| 30 | ->expects($this->once()) |
||
| 31 | ->method('warning') |
||
| 32 | ->with($this->equalTo($message)); |
||
| 33 | |||
| 34 | $definitionMock = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Definition') |
||
| 35 | ->disableOriginalConstructor() |
||
| 36 | ->getMock(); |
||
| 37 | |||
| 38 | $container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder') |
||
| 39 | ->setMethods( |
||
| 40 | [ |
||
| 41 | 'findTaggedServiceIds', |
||
| 42 | 'getDefinition', |
||
| 43 | 'getParameter', |
||
| 44 | 'hasParameter', |
||
| 45 | 'findDefinition', |
||
| 46 | 'hasDefinition' |
||
| 47 | ] |
||
| 48 | ) |
||
| 49 | ->getMock(); |
||
| 50 | $container |
||
| 51 | ->expects($this->exactly(1)) |
||
| 52 | ->method('findDefinition') |
||
| 53 | ->will($this->returnValue($definitionMock)); |
||
| 54 | $container |
||
| 55 | ->expects($this->exactly(1)) |
||
| 56 | ->method('hasParameter') |
||
| 57 | ->will($this->returnValue(true)); |
||
| 58 | $container |
||
| 59 | ->expects($this->exactly(2)) |
||
| 60 | ->method('getParameter') |
||
| 61 | ->will( |
||
| 62 | $this->onConsecutiveCalls( |
||
| 63 | $this->returnValue('graviton.security.authentication.strategy.multi'), |
||
| 64 | $this->returnValue( |
||
| 65 | [ |
||
| 66 | 'graviton.security.authentication.strategy.subnet', |
||
| 67 | 'graviton.security.authentication.strategy.header', |
||
| 68 | 'graviton.security.authentication.strategy.cookie', |
||
| 69 | 'strategy.doesnotExists' |
||
| 70 | ] |
||
| 71 | ) |
||
| 72 | ) |
||
| 73 | ); |
||
| 74 | $container |
||
| 75 | ->expects($this->exactly(1)) |
||
| 76 | ->method('getDefinition') |
||
| 77 | ->will( |
||
| 78 | $this->onConsecutiveCalls( |
||
| 79 | $this->returnValue($loggerMock) |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | $container |
||
| 83 | ->expects($this->exactly(5)) |
||
| 84 | ->method('hasDefinition') |
||
| 85 | ->will( |
||
| 86 | $this->onConsecutiveCalls( |
||
| 87 | $this->returnValue(true), // service id |
||
| 88 | $this->returnValue(true), // service id |
||
| 89 | $this->returnValue(true), // service id |
||
| 90 | $this->returnValue(false), // not exists service id |
||
| 91 | $this->returnValue(true) // logger service id |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | |||
| 95 | $compilerPass = new AuthenticationKeyFinderPass(); |
||
| 96 | $compilerPass->process($container); |
||
| 97 | } |
||
| 98 | } |
||
| 99 |