| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| 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 |
||
| 71 | public function testWillParseQuery($query) |
||
| 72 | { |
||
| 73 | $lexerDouble = $this->getMockBuilder('Graviton\RqlParser\Lexer') |
||
| 74 | ->disableOriginalConstructor() |
||
| 75 | ->getMock(); |
||
| 76 | $lexerDouble->expects($this->any()) |
||
| 77 | ->method('tokenize') |
||
| 78 | ->willReturn( |
||
| 79 | $this->getMockBuilder('Graviton\RqlParser\TokenStream') |
||
| 80 | ->disableOriginalConstructor() |
||
| 81 | ->getMock() |
||
| 82 | ); |
||
| 83 | |||
| 84 | $parserDouble = $this->getMockBuilder('Graviton\RqlParser\Parser') |
||
| 85 | ->disableOriginalConstructor() |
||
| 86 | ->getMock(); |
||
| 87 | $parserDouble->expects($this->once()) |
||
| 88 | ->method('parse') |
||
| 89 | ->willReturn($this->getMockBuilder('Graviton\RqlParser\Query')->getMock()); |
||
| 90 | |||
| 91 | $eventDouble = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') |
||
| 92 | ->disableOriginalConstructor() |
||
| 93 | ->getMock(); |
||
| 94 | |||
| 95 | $requestDouble = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); |
||
| 96 | |||
| 97 | $serverDouble = $this->getMockBuilder('Symfony\Component\HttpFoundation\ServerBag')->getMock(); |
||
| 98 | $serverDouble->expects($this->once()) |
||
| 99 | ->method('get') |
||
| 100 | ->with('QUERY_STRING') |
||
| 101 | ->willReturn($query); |
||
| 102 | $requestDouble->server = $serverDouble; |
||
| 103 | |||
| 104 | $attributesDouble = $this->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag')->getMock(); |
||
| 105 | $attributesDouble->expects($this->at(0)) |
||
| 106 | ->method('set') |
||
| 107 | ->with('hasRql', true); |
||
| 108 | $attributesDouble->expects($this->at(1)) |
||
| 109 | ->method('set') |
||
| 110 | ->with('rawRql', $query); |
||
| 111 | $attributesDouble->expects($this->at(2)) |
||
| 112 | ->method('set') |
||
| 113 | ->with('rqlQuery', $this->isInstanceOf('Graviton\RqlParser\Query')); |
||
| 114 | $requestDouble->attributes = $attributesDouble; |
||
| 115 | |||
| 116 | $eventDouble->expects($this->once()) |
||
| 117 | ->method('getRequest') |
||
| 118 | ->willReturn($requestDouble); |
||
| 119 | |||
| 120 | $sut = new RequestListener( |
||
| 121 | $lexerDouble, |
||
| 122 | $parserDouble |
||
| 123 | ); |
||
| 124 | |||
| 125 | $sut->onKernelRequest($eventDouble); |
||
| 126 | } |
||
| 127 | |||
| 146 |