Completed
Push — master ( 954646...a87a0a )
by Guillaume
9s
created

JwtManagerTest::testGetTokenWithTokenKeyOption()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 22

Duplication

Lines 37
Ratio 100 %

Importance

Changes 0
Metric Value
dl 37
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace Eljam\GuzzleJwt\Tests\Manager;
4
5
use Eljam\GuzzleJwt\JwtToken;
6
use Eljam\GuzzleJwt\Manager\JwtManager;
7
use Eljam\GuzzleJwt\Strategy\Auth\QueryAuthStrategy;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\HandlerStack;
10
use GuzzleHttp\Handler\MockHandler;
11
use GuzzleHttp\Psr7\Response;
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * @author Guillaume Cavavana <[email protected]>
16
 */
17
class JwtManagerTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * testGetToken.
21
     */
22 View Code Duplication
    public function testGetToken()
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...
23
    {
24
        $mockHandler = new MockHandler([
25
            function (RequestInterface $request) {
26
27
                $this->assertTrue($request->hasHeader('timeout'));
28
                $this->assertEquals(
29
                    3,
30
                    $request->getHeader('timeout')[0]
31
                );
32
33
                return new Response(
34
                    200,
35
                    ['Content-Type' => 'application/json'],
36
                    json_encode(['token' => '1453720507'])
37
                );
38
            },
39
        ]);
40
41
        $handler = HandlerStack::create($mockHandler);
42
43
        $authClient = new Client([
44
            'handler' => $handler,
45
        ]);
46
47
        $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']);
48
49
        $jwtManager = new JwtManager(
50
            $authClient,
51
            $authStrategy,
52
            ['token_url' => '/api/token', 'timeout' => 3]
53
        );
54
        $token = $jwtManager->getJwtToken();
55
56
        $this->assertInstanceOf(JwtToken::class, $token);
57
        $this->assertEquals('1453720507', $token->getToken());
58
    }
59
60 View Code Duplication
    public function testGetTokenWithTokenKeyOption()
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...
61
    {
62
        $mockHandler = new MockHandler([
63
            function (RequestInterface $request) {
64
65
                $this->assertTrue($request->hasHeader('timeout'));
66
                $this->assertEquals(
67
                    3,
68
                    $request->getHeader('timeout')[0]
69
                );
70
71
                return new Response(
72
                    200,
73
                    ['Content-Type' => 'application/json'],
74
                    json_encode(['tokenkey' => '1453720507'])
75
                );
76
            },
77
        ]);
78
79
        $handler = HandlerStack::create($mockHandler);
80
81
        $authClient = new Client([
82
            'handler' => $handler,
83
        ]);
84
85
        $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']);
86
87
        $jwtManager = new JwtManager(
88
            $authClient,
89
            $authStrategy,
90
            ['token_url' => '/api/token', 'timeout' => 3, 'token_key' => 'tokenkey']
91
        );
92
        $token = $jwtManager->getJwtToken();
93
94
        $this->assertInstanceOf(JwtToken::class, $token);
95
        $this->assertEquals('1453720507', $token->getToken());
96
    }
97
}
98