Code Duplication    Length = 59-59 lines in 2 locations

Tests/Manager/JwtManagerTest.php 2 locations

@@ 158-216 (lines=59) @@
155
        $this->assertEquals('1453720507', $token->getToken());
156
    }
157
158
    public function testGetTokenShouldGetNewTokenIfCachedTokenIsNotValid()
159
    {
160
        $mockHandler = new MockHandler(
161
            [
162
                function (RequestInterface $request) {
163
164
                    $this->assertTrue($request->hasHeader('timeout'));
165
                    $this->assertEquals(
166
                        3,
167
                        $request->getHeaderLine('timeout')
168
                    );
169
170
                    return new Response(
171
                        200,
172
                        ['Content-Type' => 'application/json'],
173
                        json_encode(['token' => '1453720507'])
174
                    );
175
                },
176
                function (RequestInterface $request) {
177
178
                    $this->assertTrue($request->hasHeader('timeout'));
179
                    $this->assertEquals(
180
                        3,
181
                        $request->getHeaderLine('timeout')
182
                    );
183
184
                    return new Response(
185
                        200,
186
                        ['Content-Type' => 'application/json'],
187
                        json_encode(['token' => 'foo123'])
188
                    );
189
                },
190
            ]
191
        );
192
193
        $handler = HandlerStack::create($mockHandler);
194
195
        $authClient = new Client([
196
            'handler' => $handler,
197
        ]);
198
199
        $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']);
200
201
        $jwtManager = new JwtManager(
202
            $authClient,
203
            $authStrategy,
204
            null,
205
            ['token_url' => '/api/token', 'timeout' => 3]
206
        );
207
        $token = $jwtManager->getJwtToken();
208
209
        $this->assertInstanceOf(JwtToken::class, $token);
210
        $this->assertEquals('1453720507', $token->getToken());
211
212
        $token = $jwtManager->getJwtToken();
213
214
        $this->assertInstanceOf(JwtToken::class, $token);
215
        $this->assertEquals('foo123', $token->getToken());
216
    }
217
218
    public function testGetTokenShouldUseTheCachedTokenIfItIsValid()
219
    {
@@ 218-276 (lines=59) @@
215
        $this->assertEquals('foo123', $token->getToken());
216
    }
217
218
    public function testGetTokenShouldUseTheCachedTokenIfItIsValid()
219
    {
220
        $mockHandler = new MockHandler(
221
            [
222
                function (RequestInterface $request) {
223
224
                    $this->assertTrue($request->hasHeader('timeout'));
225
                    $this->assertEquals(
226
                        3,
227
                        $request->getHeaderLine('timeout')
228
                    );
229
230
                    return new Response(
231
                        200,
232
                        ['Content-Type' => 'application/json'],
233
                        json_encode(['token' => '1453720507', 'expires_in' => 3600])
234
                    );
235
                },
236
                function (RequestInterface $request) {
237
238
                    $this->assertTrue($request->hasHeader('timeout'));
239
                    $this->assertEquals(
240
                        3,
241
                        $request->getHeaderLine('timeout')
242
                    );
243
244
                    return new Response(
245
                        200,
246
                        ['Content-Type' => 'application/json'],
247
                        json_encode(['token' => 'foo123'])
248
                    );
249
                },
250
            ]
251
        );
252
253
        $handler = HandlerStack::create($mockHandler);
254
255
        $authClient = new Client([
256
            'handler' => $handler,
257
        ]);
258
259
        $authStrategy = new QueryAuthStrategy(['username' => 'admin', 'password' => 'admin']);
260
261
        $jwtManager = new JwtManager(
262
            $authClient,
263
            $authStrategy,
264
            null,
265
            ['token_url' => '/api/token', 'timeout' => 3]
266
        );
267
        $token = $jwtManager->getJwtToken();
268
269
        $this->assertInstanceOf(JwtToken::class, $token);
270
        $this->assertEquals('1453720507', $token->getToken());
271
272
        $token = $jwtManager->getJwtToken();
273
274
        $this->assertInstanceOf(JwtToken::class, $token);
275
        $this->assertEquals('1453720507', $token->getToken());
276
    }
277
278
    public function testGetTokenShouldUseTheCachedTokenIfItIsValidBasedOnExpField()
279
    {