| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 116 | public function testSerialize() |
||
| 117 | { |
||
| 118 | // Configure payload |
||
| 119 | |||
| 120 | $headerParameters = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock(); |
||
| 121 | |||
| 122 | $headerParameters->expects($this->once()) |
||
| 123 | ->method('jsonSerialize') |
||
| 124 | ->will($this->returnValue('{"a":"1"}')); |
||
| 125 | |||
| 126 | $header = $this->getMockBuilder('Emarref\Jwt\Token\Header')->getMock(); |
||
| 127 | |||
| 128 | $header->expects($this->once()) |
||
| 129 | ->method('getParameters') |
||
| 130 | ->will($this->returnValue($headerParameters)); |
||
| 131 | |||
| 132 | // Configure payload |
||
| 133 | |||
| 134 | $claims = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock(); |
||
| 135 | |||
| 136 | $claims->expects($this->once()) |
||
| 137 | ->method('jsonSerialize') |
||
| 138 | ->will($this->returnValue('{"b":"2"}')); |
||
| 139 | |||
| 140 | $payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock(); |
||
| 141 | |||
| 142 | $payload->expects($this->once()) |
||
| 143 | ->method('getClaims') |
||
| 144 | ->will($this->returnValue($claims)); |
||
| 145 | |||
| 146 | // Configure token |
||
| 147 | |||
| 148 | $token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock(); |
||
| 149 | |||
| 150 | $token->expects($this->once()) |
||
| 151 | ->method('getHeader') |
||
| 152 | ->will($this->returnValue($header)); |
||
| 153 | |||
| 154 | $token->expects($this->once()) |
||
| 155 | ->method('getPayload') |
||
| 156 | ->will($this->returnValue($payload)); |
||
| 157 | |||
| 158 | $token->expects($this->once()) |
||
| 159 | ->method('getSignature') |
||
| 160 | ->will($this->returnValue('c')); |
||
| 161 | |||
| 162 | // Configure encoding |
||
| 163 | |||
| 164 | $this->encoding->expects($this->exactly(3)) |
||
| 165 | ->method('encode') |
||
| 166 | ->will($this->returnValueMap([ |
||
| 167 | ['{"a":"1"}', 'a'], |
||
| 168 | ['{"b":"2"}', 'b'], |
||
| 169 | ['c', 'c'], |
||
| 170 | ])); |
||
| 171 | |||
| 172 | $jwt = $this->serializer->serialize($token); |
||
| 173 | |||
| 174 | $this->assertSame('a.b.c', $jwt); |
||
| 175 | } |
||
| 176 | } |
||
| 177 |