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.
Completed
Push — master ( a17582...d97b9d )
by Malcolm
07:04 queued 04:10
created

SubjectVerifierTest::testSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 21
loc 21
rs 9.3142
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\Claim;
6
7 View Code Duplication
class SubjectVerifierTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject
11
     */
12
    private $payload;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject
16
     */
17
    private $token;
18
19
    public function setUp()
20
    {
21
        $this->payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock();
22
23
        $this->token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock();
24
    }
25
26
    /**
27
     * @expectedException \InvalidArgumentException
28
     * @expectedExceptionMessage Cannot verify invalid subject value.
29
     */
30
    public function testInvalidSubject()
31
    {
32
        new SubjectVerifier(new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
    }
34
35
    public function testNoSubject()
36
    {
37
        $this->token->expects($this->once())
38
            ->method('getPayload')
39
            ->will($this->returnValue($this->payload));
40
41
        $this->payload->expects($this->once())
42
            ->method('findClaimByName')
43
            ->with(Claim\Subject::NAME)
44
            ->will($this->returnValue(null));
45
46
        $verifier = new SubjectVerifier();
47
        $verifier->verify($this->token);
48
    }
49
50
    /**
51
     * @expectedException Emarref\Jwt\Exception\VerificationException
52
     * @expectedExceptionMessage Subject is invalid.
53
     */
54
    public function testSubjectInPayloadOnly()
55
    {
56
        $subjectClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Subject')
57
            ->getMock();
58
59
        $subjectClaim->expects($this->once())
60
            ->method('getValue')
61
            ->will($this->returnValue('a_subject'));
62
63
        $this->token->expects($this->once())
64
            ->method('getPayload')
65
            ->will($this->returnValue($this->payload));
66
67
        $this->payload->expects($this->once())
68
            ->method('findClaimByName')
69
            ->with(Claim\Subject::NAME)
70
            ->will($this->returnValue($subjectClaim));
71
72
        $verifier = new SubjectVerifier();
73
        $verifier->verify($this->token);
74
    }
75
76
    /**
77
     * @expectedException Emarref\Jwt\Exception\VerificationException
78
     * @expectedExceptionMessage Subject is invalid.
79
     */
80
    public function testSubjectInContextOnly()
81
    {
82
        $this->token->expects($this->once())
83
            ->method('getPayload')
84
            ->will($this->returnValue($this->payload));
85
86
        $this->payload->expects($this->once())
87
            ->method('findClaimByName')
88
            ->with(Claim\Subject::NAME)
89
            ->will($this->returnValue(null));
90
91
        $verifier = new SubjectVerifier('a_subject');
92
        $verifier->verify($this->token);
93
    }
94
95
    /**
96
     * @expectedException Emarref\Jwt\Exception\VerificationException
97
     * @expectedExceptionMessage Subject is invalid.
98
     */
99
    public function testSubjectMismatch()
100
    {
101
        $subjectClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Subject')
102
            ->getMock();
103
104
        $subjectClaim->expects($this->once())
105
            ->method('getValue')
106
            ->will($this->returnValue('a_subject'));
107
108
        $this->token->expects($this->once())
109
            ->method('getPayload')
110
            ->will($this->returnValue($this->payload));
111
112
        $this->payload->expects($this->once())
113
            ->method('findClaimByName')
114
            ->with(Claim\Subject::NAME)
115
            ->will($this->returnValue($subjectClaim));
116
117
        $verifier = new SubjectVerifier('some_other_subject');
118
        $verifier->verify($this->token);
119
    }
120
121
    public function testSuccess()
122
    {
123
        $subjectClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Subject')
124
            ->getMock();
125
126
        $subjectClaim->expects($this->once())
127
            ->method('getValue')
128
            ->will($this->returnValue('a_subject'));
129
130
        $this->token->expects($this->once())
131
            ->method('getPayload')
132
            ->will($this->returnValue($this->payload));
133
134
        $this->payload->expects($this->once())
135
            ->method('findClaimByName')
136
            ->with(Claim\Subject::NAME)
137
            ->will($this->returnValue($subjectClaim));
138
139
        $verifier = new SubjectVerifier('a_subject');
140
        $verifier->verify($this->token);
141
    }
142
}
143