JwtAuthTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testJwtEncode() 0 12 1
A testJwtDecode() 0 7 1
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use SapphireTest;
6
7
/**
8
 * Test the JWT auth mechanism
9
 * @todo: add more tests
10
 * @author Christian Blank <[email protected]>
11
 */
12
class JwtAuthTest extends SapphireTest {
13
14
15
    public function testJwtEncode() {
16
        $data = [
17
            "sub" => "1234567890",
18
            "name" => "John Doe",
19
            "admin" => true
20
        ];
21
        $result = JwtAuth::jwt_encode($data, "secret");
22
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\JwtAuthTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
            "eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.2a2f70f937182a2daa5c1e79ed832899c3ebb14412b214c0cb0484b8199b64a2",
24
            $result
25
        );
26
    }
27
28
    public function testJwtDecode() {
29
        $token = "eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.2a2f70f937182a2daa5c1e79ed832899c3ebb14412b214c0cb0484b8199b64a2";
30
        $result = JwtAuth::jwt_decode($token, "secret");
31
        $this->assertEquals("1234567890", $result['sub']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\JwtAuthTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
        $this->assertEquals(true, $result['admin']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\JwtAuthTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        $this->assertEquals("John Doe", $result['name']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\JwtAuthTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
    }
35
36
}
37