Completed
Push — develop ( 82de8f...bd9a33 )
by Wisoot
02:14
created

ClaimTest::testCreateClaimWithMalformedException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 19
loc 19
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
use Carbon\Carbon;
4
use Illuminate\Support\Facades\Config;
5
use WWON\JwtGuard\Claim;
6
7
class ClaimTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
    /**
11
     * testConstructor method
12
     */
13
    public function testConstructor()
14
    {
15
        $ttl = 100;
16
        $now = Carbon::now()->timestamp;
17
18
        Config::shouldReceive('get')
19
            ->once()
20
            ->with('app.url')
21
            ->andReturn('http://www.test.com');
22
23
        Config::shouldReceive('get')
24
            ->once()
25
            ->with('jwt.ttl')
26
            ->andReturn($ttl);
27
28
        Config::shouldReceive('get')
29
            ->once()
30
            ->with('jwt.ttl')
31
            ->andReturn($ttl);
32
33
        Config::shouldReceive('get')
34
            ->once()
35
            ->with('jwt.leeway')
36
            ->andReturn(0);
37
38
        $claim = new Claim();
39
40
        $this->assertEquals('http://www.test.com', $claim->iss);
41
        $this->assertEquals($now, $claim->iat, '', 2);
42
        $this->assertEquals($now + 6000, $claim->exp, '', 2);
43
        $this->assertEquals($now + 6000, $claim->nat, '', 2);
44
        $this->assertEquals(0, $claim->leeway);
45
    }
46
47
    /**
48
     * testCreateClaim method
49
     */
50
    public function testCreateClaim()
51
    {
52
        $now = Carbon::now()->timestamp;
53
54
        Config::shouldReceive('get')
55
            ->once()
56
            ->with('jwt.leeway')
57
            ->andReturn(0);
58
59
        $claim = new Claim([
60
            'iss' => 'http://www.test.com',
61
            'iat' => $now,
62
            'exp' => $now + 6000,
63
            'nat' => $now + 6000,
64
            'jti' => 'asdjhasiudhasud'
65
        ]);
66
67
        $this->assertEquals('http://www.test.com', $claim->iss);
68
        $this->assertEquals($now, $claim->iat);
69
        $this->assertEquals($now + 6000, $claim->exp);
70
        $this->assertEquals($now + 6000, $claim->nat);
71
        $this->assertEquals('asdjhasiudhasud', $claim->jti);
72
        $this->assertEquals(0, $claim->leeway);
73
    }
74
75
    /**
76
     * testCreateClaimWithMalformedException method
77
     */
78 View Code Duplication
    public function testCreateClaimWithMalformedException()
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...
79
    {
80
        $now = Carbon::now()->timestamp;
81
82
        Config::shouldReceive('get')
83
            ->once()
84
            ->with('jwt.leeway')
85
            ->andReturn(0);
86
87
        $this->setExpectedException(\WWON\JwtGuard\Exceptions\MalformedException::class);
88
89
        $claim = new Claim([
0 ignored issues
show
Unused Code introduced by
$claim 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...
90
            'iss' => 'http://www.test.com',
91
            'iat' => $now,
92
            'exp' => $now - 6000,
93
            'nat' => $now - 6000,
94
            'jti' => 'asdjhasiudhasud'
95
        ]);
96
    }
97
98
    /**
99
     * testCreateClaimWithInaccessibleException method
100
     */
101 View Code Duplication
    public function testCreateClaimWithInaccessibleException()
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...
102
    {
103
        $now = Carbon::now()->timestamp;
104
105
        Config::shouldReceive('get')
106
            ->once()
107
            ->with('jwt.leeway')
108
            ->andReturn(0);
109
110
        $this->setExpectedException(\WWON\JwtGuard\Exceptions\InaccessibleException::class);
111
112
        $claim = new Claim([
0 ignored issues
show
Unused Code introduced by
$claim 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...
113
            'iss' => 'http://www.test.com',
114
            'iat' => $now - 6000,
115
            'exp' => $now + 6000,
116
            'nat' => $now - 10,
117
            'jti' => 'asdjhasiudhasud'
118
        ]);
119
    }
120
121
    /**
122
     * testCreateClaimWithTokenExpiredException method
123
     */
124 View Code Duplication
    public function testCreateClaimWithTokenExpiredException()
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...
125
    {
126
        $now = Carbon::now()->timestamp;
127
128
        Config::shouldReceive('get')
129
            ->once()
130
            ->with('jwt.leeway')
131
            ->andReturn(0);
132
133
        $this->setExpectedException(\WWON\JwtGuard\Exceptions\TokenExpiredException::class);
134
135
        $claim = new Claim([
0 ignored issues
show
Unused Code introduced by
$claim 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...
136
            'iss' => 'http://www.test.com',
137
            'iat' => $now - 6000,
138
            'exp' => $now - 1000,
139
            'nat' => $now - 1000,
140
            'jti' => 'asdjhasiudhasud'
141
        ]);
142
    }
143
144
}