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.

EncryptionVerifierTest::testAlgorithmMismatch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\HeaderParameter;
6
7
class EncryptionVerifierTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token\Header
11
     */
12
    private $header;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token
16
     */
17
    private $token;
18
19
    /**
20
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Algorithm\AlgorithmInterface
21
     */
22
    private $algorithm;
23
24
    /**
25
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Encryption\EncryptionInterface
26
     */
27
    private $encryption;
28
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Encoding\EncoderInterface
31
     */
32
    private $encoder;
33
34
    /**
35
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Signature\SignerInterface
36
     */
37
    private $signer;
38
39
    public function setUp()
40
    {
41
        $this->header = $this->getMockBuilder('Emarref\Jwt\Token\Header')->getMock();
42
43
        $this->token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock();
44
45
        $this->token->expects($this->any())
46
            ->method('getHeader')
47
            ->will($this->returnValue($this->header));
48
49
        $this->algorithm = $this->getMockBuilder('Emarref\Jwt\Algorithm\None')->getMock();
50
51
        $this->encryption = $this->getMockBuilder('Emarref\Jwt\Encryption\Symmetric')
52
            ->setConstructorArgs([$this->algorithm])
53
            ->getMock();
54
55
        $this->encoder = $this->getMockBuilder('Emarref\Jwt\Encoding\Base64')->getMock();
56
57
        $this->signer = $this->getMockBuilder('Emarref\Jwt\Signature\Jws')
58
            ->disableOriginalConstructor()
59
            ->getMock();
60
    }
61
62
    /**
63
     * @expectedException \RuntimeException
64
     * @expectedExceptionMessage Algorithm parameter not found in token header.
65
     */
66
    public function testMissingAlgorithm()
67
    {
68
        $this->header->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\Header.

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...
69
            ->method('findParameterByName')
70
            ->with(HeaderParameter\Algorithm::NAME)
71
            ->will($this->returnValue(null));
72
73
        $verifier = new EncryptionVerifier($this->encryption, $this->encoder);
74
        $verifier->verify($this->token);
75
    }
76
77
    /**
78
     * @expectedException \RuntimeException
79
     * @expectedExceptionMessage Cannot use "bar" algorithm to decrypt token encrypted with algorithm "foo".
80
     */
81
    public function testAlgorithmMismatch()
82
    {
83
        $algorithmParameter = $this->getMockBuilder('Emarref\Jwt\HeaderParameter\Algorithm')->getMock();
84
85
        $algorithmParameter->expects($this->exactly(2))
86
            ->method('getValue')
87
            ->will($this->returnValue('foo'));
88
89
        $this->header->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\Header.

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...
90
            ->method('findParameterByName')
91
            ->with(HeaderParameter\Algorithm::NAME)
92
            ->will($this->returnValue($algorithmParameter));
93
94
        $this->encryption->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Encryption\EncryptionInterface.

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...
95
            ->method('getAlgorithmName')
96
            ->will($this->returnValue('bar'));
97
98
        $verifier = new EncryptionVerifier($this->encryption, $this->encoder);
99
        $verifier->verify($this->token);
100
    }
101
102
    /**
103
     * @expectedException \Emarref\Jwt\Exception\InvalidSignatureException
104
     * @expectedExceptionMessage Signature is invalid.
105
     */
106 View Code Duplication
    public function testInvalidSignature()
107
    {
108
        $algorithmParameter = $this->getMockBuilder('Emarref\Jwt\HeaderParameter\Algorithm')->getMock();
109
110
        $algorithmParameter->expects($this->once())
111
                           ->method('getValue')
112
                           ->will($this->returnValue('foo'));
113
114
        $this->header->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\Header.

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...
115
                     ->method('findParameterByName')
116
                     ->with(HeaderParameter\Algorithm::NAME)
117
                     ->will($this->returnValue($algorithmParameter));
118
119
        $this->encryption->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\Encryption\EncryptionInterface.

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...
120
                         ->method('getAlgorithmName')
121
                         ->will($this->returnValue('foo'));
122
123
        $this->encryption->expects($this->once())
124
                         ->method('verify')
125
                         ->will($this->returnValue(false));
126
127
        $this->signer->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\Signature\SignerInterface.

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...
128
                     ->method('getUnsignedValue')
129
                     ->will($this->returnValue('foo'));
130
131
        $this->token->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.

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...
132
                    ->method('getSignature')
133
                    ->will($this->returnValue('bar'));
134
135
        $verifier = new EncryptionVerifierStub($this->encryption, $this->encoder, $this->signer);
136
        $verifier->verify($this->token);
137
    }
138
139 View Code Duplication
    public function testValidSignature()
140
    {
141
        $algorithmParameter = $this->getMockBuilder('Emarref\Jwt\HeaderParameter\Algorithm')->getMock();
142
143
        $algorithmParameter->expects($this->once())
144
            ->method('getValue')
145
            ->will($this->returnValue('foo'));
146
147
        $this->header->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\Header.

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...
148
            ->method('findParameterByName')
149
            ->with(HeaderParameter\Algorithm::NAME)
150
            ->will($this->returnValue($algorithmParameter));
151
152
        $this->encryption->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\Encryption\EncryptionInterface.

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...
153
            ->method('getAlgorithmName')
154
            ->will($this->returnValue('foo'));
155
156
        $this->encryption->expects($this->once())
157
            ->method('verify')
158
            ->will($this->returnValue(true));
159
160
        $this->signer->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\Signature\SignerInterface.

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...
161
            ->method('getUnsignedValue')
162
            ->will($this->returnValue('bar'));
163
164
        $this->token->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.

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...
165
            ->method('getSignature')
166
            ->will($this->returnValue('bar'));
167
168
        $verifier = new EncryptionVerifierStub($this->encryption, $this->encoder, $this->signer);
169
        $verifier->verify($this->token);
170
    }
171
}
172