| @@ 22-58 (lines=37) @@ | ||
| 19 | /** |
|
| 20 | * testGetToken. |
|
| 21 | */ |
|
| 22 | public function testGetToken() |
|
| 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 | public function testGetTokenWithTokenKeyOption() |
|
| 61 | { |
|
| @@ 60-96 (lines=37) @@ | ||
| 57 | $this->assertEquals('1453720507', $token->getToken()); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function testGetTokenWithTokenKeyOption() |
|
| 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 | ||