GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JwsTest::testSign()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 66
rs 9.3191
cc 1
eloc 40
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace Emarref\Jwt\Signature;
4
5
use Emarref\Jwt\HeaderParameter\Algorithm;
6
7
class JwsTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject
11
     */
12
    private $algorithm;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject
16
     */
17
    private $encryption;
18
19
    /**
20
     * @var \PHPUnit_Framework_MockObject_MockObject
21
     */
22
    private $encoder;
23
24
    /**
25
     * @var Jws
26
     */
27
    private $signer;
28
29
    public function setUp()
30
    {
31
        $this->algorithm = $this->getMockBuilder('Emarref\Jwt\Algorithm\None')->getMock();
32
33
        $this->encryption = $this->getMockBuilder('Emarref\Jwt\Encryption\Symmetric')
34
            ->setConstructorArgs([$this->algorithm])
35
            ->getMock();
36
37
        $this->encoder = $this->getMockBuilder('Emarref\Jwt\Encoding\Base64')->getMock();
38
39
        $this->signer = new Jws($this->encryption, $this->encoder);
40
    }
41
42
    public function testSign()
43
    {
44
        $expectedSignature = 'foobar';
45
46
        // Configure payload
47
48
        $headerParameters = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock();
49
50
        $headerParameters->expects($this->once())
51
            ->method('jsonSerialize');
52
53
        $this->encoder->expects($this->at(0))
54
            ->method('encode');
55
56
        $header = $this->getMockBuilder('Emarref\Jwt\Token\Header')->getMock();
57
58
        $header->expects($this->once())
59
            ->method('getParameters')
60
            ->will($this->returnValue($headerParameters));
61
62
        // Configure payload
63
64
        $claims = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock();
65
66
        $claims->expects($this->once())
67
            ->method('jsonSerialize');
68
69
        $payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock();
70
71
        $payload->expects($this->once())
72
            ->method('getClaims')
73
            ->will($this->returnValue($claims));
74
75
        $this->encoder->expects($this->at(1))
76
            ->method('encode');
77
78
        // Configure token
79
80
        $token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock();
81
82
        $token->expects($this->once())
83
              ->method('getHeader')
84
              ->will($this->returnValue($header));
85
86
        $token->expects($this->once())
87
              ->method('getPayload')
88
              ->will($this->returnValue($payload));
89
90
        $this->encryption->expects($this->once())
91
            ->method('getAlgorithmName')
92
            ->will($this->returnValue('alg'));
93
94
        $this->encryption->expects($this->once())
95
            ->method('encrypt')
96
            ->will($this->returnValue($expectedSignature));
97
98
        $token->expects($this->once())
99
            ->method('addHeader')
100
            ->with(new Algorithm('alg'));
101
102
        $token->expects($this->once())
103
            ->method('setSignature')
104
            ->with($expectedSignature);
105
106
        $this->signer->sign($token);
107
    }
108
}
109