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.

NotBeforeVerifierTest::testValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\Claim\NotBefore;
6
7
class NotBeforeVerifierTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token\Payload
11
     */
12
    private $payload;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token
16
     */
17
    private $token;
18
19
    /**
20
     * @var NotBeforeVerifier
21
     */
22
    private $verifier;
23
24 View Code Duplication
    public function setUp()
25
    {
26
        $this->payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock();
27
28
        $this->token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock();
29
30
        $this->token->expects($this->any())
31
            ->method('getPayload')
32
            ->will($this->returnValue($this->payload));
33
34
        $this->verifier = new NotBeforeVerifier();
35
    }
36
37 View Code Duplication
    public function testMissingNotBefore()
38
    {
39
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
40
                      ->method('findClaimByName')
41
                      ->with(NotBefore::NAME)
42
                      ->will($this->returnValue(null));
43
44
        $this->verifier->verify($this->token);
45
    }
46
47
    /**
48
     * @expectedException \Emarref\Jwt\Exception\TooEarlyException
49
     * @expectedExceptionMessageRegExp /Token must not be processed before "[\w,:+\d ]+"/
50
     */
51 View Code Duplication
    public function testNotBefore()
52
    {
53
        $dateTime = new \DateTime('1 day');
54
55
        $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock();
56
57
        $notBeforeClaim->expects($this->exactly(3))
58
            ->method('getValue')
59
            ->will($this->returnValue($dateTime->getTimestamp()));
60
61
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
62
            ->method('findClaimByName')
63
            ->with(NotBefore::NAME)
64
            ->will($this->returnValue($notBeforeClaim));
65
66
        $this->verifier->verify($this->token);
67
    }
68
69
    /**
70
     * @expectedException \InvalidArgumentException
71
     * @expectedExceptionMessage Invalid not before timestamp "foobar"
72
     */
73 View Code Duplication
    public function testUnexpectedValue()
74
    {
75
        $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock();
76
77
        $notBeforeClaim->expects($this->exactly(2))
78
                        ->method('getValue')
79
                        ->will($this->returnValue('foobar'));
80
81
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
82
                      ->method('findClaimByName')
83
                      ->with(NotBefore::NAME)
84
                      ->will($this->returnValue($notBeforeClaim));
85
86
        $this->verifier->verify($this->token);
87
    }
88
89 View Code Duplication
    public function testValid()
90
    {
91
        $past = new \DateTime('5 minutes ago', new \DateTimeZone('UTC'));
92
93
        $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock();
94
95
        $notBeforeClaim->expects($this->exactly(2))
96
            ->method('getValue')
97
            ->will($this->returnValue($past->getTimestamp()));
98
99
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
            ->method('findClaimByName')
101
            ->with(NotBefore::NAME)
102
            ->will($this->returnValue($notBeforeClaim));
103
104
        $this->verifier->verify($this->token);
105
    }
106
}
107