Conditions | 1 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 48 |
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 |
||
42 | public function testDeserialize() |
||
43 | { |
||
44 | $jwt = 'a.b.c'; |
||
45 | |||
46 | // Configure encoding |
||
47 | |||
48 | $this->encoding->expects($this->at(0)) |
||
49 | ->method('decode') |
||
50 | ->with('a') |
||
51 | ->will($this->returnValue('{"a":"1"}')); |
||
52 | |||
53 | $this->encoding->expects($this->at(1)) |
||
54 | ->method('decode') |
||
55 | ->with('b') |
||
56 | ->will($this->returnValue('{"b":"2"}')); |
||
57 | |||
58 | $this->encoding->expects($this->at(2)) |
||
59 | ->method('decode') |
||
60 | ->with('c') |
||
61 | ->will($this->returnValue('c')); |
||
62 | |||
63 | // Configure headers |
||
64 | |||
65 | $headerParameter = $this->getMockBuilder('Emarref\Jwt\HeaderParameter\Custom') |
||
66 | ->getMock(); |
||
67 | |||
68 | $headerParameter->expects($this->once()) |
||
69 | ->method('setValue') |
||
70 | ->with('1'); |
||
71 | |||
72 | $headerParameter->expects($this->once()) |
||
73 | ->method('getValue') |
||
74 | ->will($this->returnValue('1')); |
||
75 | |||
76 | $headerParameter->expects($this->exactly(2)) |
||
77 | ->method('getName') |
||
78 | ->will($this->returnValue('a')); |
||
79 | |||
80 | $this->headerParameterFactory->expects($this->once()) |
||
81 | ->method('get') |
||
82 | ->with('a') |
||
83 | ->will($this->returnValue($headerParameter)); |
||
84 | |||
85 | // Configure claims |
||
86 | |||
87 | $claim = $this->getMockBuilder('Emarref\Jwt\Claim\PrivateClaim') |
||
88 | ->getMock(); |
||
89 | |||
90 | $claim->expects($this->once()) |
||
91 | ->method('setValue') |
||
92 | ->with('2'); |
||
93 | |||
94 | $claim->expects($this->once()) |
||
95 | ->method('getValue') |
||
96 | ->will($this->returnValue('2')); |
||
97 | |||
98 | $claim->expects($this->exactly(2)) |
||
99 | ->method('getName') |
||
100 | ->will($this->returnValue('b')); |
||
101 | |||
102 | $this->claimFactory->expects($this->once()) |
||
103 | ->method('get') |
||
104 | ->with('b') |
||
105 | ->will($this->returnValue($claim)); |
||
106 | |||
107 | // Assert |
||
108 | |||
109 | $token = $this->serializer->deserialize($jwt); |
||
110 | |||
111 | $this->assertSame('{"a":"1"}', $token->getHeader()->jsonSerialize()); |
||
112 | $this->assertSame('{"b":"2"}', $token->getPayload()->jsonSerialize()); |
||
113 | $this->assertSame('c', $token->getSignature()); |
||
114 | } |
||
115 | |||
177 |