JwtBearerTest::testValidRequestGetsToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4286
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace CommerceGuys\Guzzle\Oauth2\Tests\GrantType;
4
5
use CommerceGuys\Guzzle\Oauth2\GrantType\JwtBearer;
6
use CommerceGuys\Guzzle\Oauth2\Tests\TestBase;
7
use SplFileObject;
8
9
class JwtBearerTest extends TestBase
10
{
11
    public function testMissingConfigException()
12
    {
13
        $this->setExpectedException('\\InvalidArgumentException', 'Config is missing the following keys: client_id, private_key');
14
        new JwtBearer($this->getClient());
15
    }
16
17
    public function testPrivateKeyNotSplFileObject()
18
    {
19
        $this->setExpectedException('\\InvalidArgumentException', 'private_key needs to be instance of SplFileObject');
20
        $grantType = new JwtBearer($this->getClient(), [
0 ignored issues
show
Unused Code introduced by
$grantType is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
            'client_id' => 'testClient',
22
            'private_key' => 'INVALID'
23
        ]);
24
    }
25
26 View Code Duplication
    public function testValidRequestGetsToken()
0 ignored issues
show
Duplication introduced by
This method 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...
27
    {
28
        $grantType = new JwtBearer($this->getClient(), [
29
            'client_id' => 'testClient',
30
            'private_key' => new SplFileObject(__DIR__ . '/../private.key')
31
        ]);
32
        $token = $grantType->getToken();
33
        $this->assertNotEmpty($token->getToken());
34
        $this->assertTrue($token->getExpires()->getTimestamp() > time());
35
    }
36
}
37