@@ 80-117 (lines=38) @@ | ||
77 | /** |
|
78 | * testGetToken. |
|
79 | */ |
|
80 | public function testGetToken() |
|
81 | { |
|
82 | $mockHandler = new MockHandler([ |
|
83 | function (RequestInterface $request) { |
|
84 | ||
85 | $this->assertTrue($request->hasHeader('timeout')); |
|
86 | $this->assertEquals( |
|
87 | 3, |
|
88 | $request->getHeaderLine('timeout') |
|
89 | ); |
|
90 | ||
91 | return new Response( |
|
92 | 200, |
|
93 | ['Content-Type' => 'application/json'], |
|
94 | json_encode(['token' => '1453720507']) |
|
95 | ); |
|
96 | }, |
|
97 | ]); |
|
98 | ||
99 | $handler = HandlerStack::create($mockHandler); |
|
100 | ||
101 | $authClient = new Client([ |
|
102 | 'handler' => $handler, |
|
103 | ]); |
|
104 | ||
105 | $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']); |
|
106 | ||
107 | $jwtManager = new JwtManager( |
|
108 | $authClient, |
|
109 | $authStrategy, |
|
110 | null, |
|
111 | ['token_url' => '/api/token', 'timeout' => 3] |
|
112 | ); |
|
113 | $token = $jwtManager->getJwtToken(); |
|
114 | ||
115 | $this->assertInstanceOf(JwtToken::class, $token); |
|
116 | $this->assertEquals('1453720507', $token->getToken()); |
|
117 | } |
|
118 | ||
119 | public function testGetTokenWithTokenKeyOption() |
|
120 | { |
|
@@ 119-156 (lines=38) @@ | ||
116 | $this->assertEquals('1453720507', $token->getToken()); |
|
117 | } |
|
118 | ||
119 | public function testGetTokenWithTokenKeyOption() |
|
120 | { |
|
121 | $mockHandler = new MockHandler([ |
|
122 | function (RequestInterface $request) { |
|
123 | ||
124 | $this->assertTrue($request->hasHeader('timeout')); |
|
125 | $this->assertEquals( |
|
126 | 3, |
|
127 | $request->getHeaderLine('timeout') |
|
128 | ); |
|
129 | ||
130 | return new Response( |
|
131 | 200, |
|
132 | ['Content-Type' => 'application/json'], |
|
133 | json_encode(['tokenkey' => '1453720507']) |
|
134 | ); |
|
135 | }, |
|
136 | ]); |
|
137 | ||
138 | $handler = HandlerStack::create($mockHandler); |
|
139 | ||
140 | $authClient = new Client([ |
|
141 | 'handler' => $handler, |
|
142 | ]); |
|
143 | ||
144 | $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']); |
|
145 | ||
146 | $jwtManager = new JwtManager( |
|
147 | $authClient, |
|
148 | $authStrategy, |
|
149 | null, |
|
150 | ['token_url' => '/api/token', 'timeout' => 3, 'token_key' => 'tokenkey'] |
|
151 | ); |
|
152 | $token = $jwtManager->getJwtToken(); |
|
153 | ||
154 | $this->assertInstanceOf(JwtToken::class, $token); |
|
155 | $this->assertEquals('1453720507', $token->getToken()); |
|
156 | } |
|
157 | ||
158 | public function testGetTokenShouldGetNewTokenIfCachedTokenIsNotValid() |
|
159 | { |