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

AudienceVerifierTest::testNoAudienceInToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\Claim;
6
7
class AudienceVerifierTest extends \PHPUnit_Framework_TestCase
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 audience value.
29
     */
30
    public function testInvalidAudience()
31
    {
32
        new AudienceVerifier(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 testNoAudienceInToken()
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\Audience::NAME)
44
            ->will($this->returnValue(null));
45
46
        $verifier = new AudienceVerifier();
47
        $verifier->verify($this->token);
48
    }
49
50
    /**
51
     * @expectedException Emarref\Jwt\Exception\VerificationException
52
     * @expectedExceptionMessage Audience is invalid.
53
     */
54
    public function testInvalidAudienceInToken()
55
    {
56
        $expectedAudience = 'urn://myaudience';
57
58
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
59
60
        $audienceClaim->expects($this->once())
61
            ->method('getValue')
62
            ->will($this->returnValue($expectedAudience));
63
64
        $this->payload->expects($this->once())
65
            ->method('findClaimByName')
66
            ->with(Claim\Audience::NAME)
67
            ->will($this->returnValue($audienceClaim));
68
69
        $this->token->expects($this->once())
70
            ->method('getPayload')
71
            ->will($this->returnValue($this->payload));
72
73
        $verifier = new AudienceVerifier('foobar');
74
        $verifier->verify($this->token);
75
    }
76
77
    public function testArrayAudience()
78
    {
79
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
80
81
        $audienceClaim->expects($this->once())
82
                      ->method('getValue')
83
                      ->will($this->returnValue(['urn://audienceone', 'urn://audiencetwo']));
84
85
        $this->payload->expects($this->once())
86
                      ->method('findClaimByName')
87
                      ->with(Claim\Audience::NAME)
88
                      ->will($this->returnValue($audienceClaim));
89
90
        $this->token->expects($this->once())
91
                    ->method('getPayload')
92
                    ->will($this->returnValue($this->payload));
93
94
        $verifier = new AudienceVerifier('urn://audienceone');
95
        $verifier->verify($this->token);
96
    }
97
98
    public function testStringAudience()
99
    {
100
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
101
102
        $audienceClaim->expects($this->once())
103
                      ->method('getValue')
104
                      ->will($this->returnValue('urn://audienceone'));
105
106
        $this->payload->expects($this->once())
107
                      ->method('findClaimByName')
108
                      ->with(Claim\Audience::NAME)
109
                      ->will($this->returnValue($audienceClaim));
110
111
        $this->token->expects($this->once())
112
                    ->method('getPayload')
113
                    ->will($this->returnValue($this->payload));
114
115
        $verifier = new AudienceVerifier('urn://audienceone');
116
        $verifier->verify($this->token);
117
    }
118
}
119