Completed
Pull Request — master (#48)
by Alejandro
03:09
created

LcobucciJwtProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provideMercureConfigs() 0 8 1
A expectedTokenIsCreated() 0 12 1
A setUp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Common\Mercure;
6
7
use Cake\Chronos\Chronos;
8
use Lcobucci\JWT\Configuration;
9
use PHPUnit\Framework\TestCase;
10
use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider;
11
12
class LcobucciJwtProviderTest extends TestCase
13
{
14
    private Configuration $jwtConfig;
15
16
    public function setUp(): void
17
    {
18
        $this->jwtConfig = Configuration::forUnsecuredSigner();
19
    }
20
21
    /**
22
     * @test
23
     * @dataProvider provideMercureConfigs
24
     */
25
    public function expectedTokenIsCreated(
26
        array $mercureConfig,
27
        string $expectedIssuer,
28
        ?Chronos $expiresAt,
29
        Chronos $expectedExpiration
30
    ): void {
31
        $token = $this->jwtConfig->getParser()->parse(
32
            (new LcobucciJwtProvider($this->jwtConfig, $mercureConfig))($expiresAt),
33
        );
34
35
        $this->assertTrue($token->hasBeenIssuedBy($expectedIssuer));
36
        $this->assertTrue($token->isExpired($expectedExpiration->addSeconds(5)));
37
    }
38
39
    public function provideMercureConfigs(): iterable
40
    {
41
        yield 'without issuer' => [[], 'Shlink', null, Chronos::now()->addMinutes(10)];
42
        yield 'with issuer' => [
43
            ['jwt_issuer' => $issuer = 'foobar'],
44
            $issuer,
45
            $expires = Chronos::now()->addMonths(5),
46
            $expires,
47
        ];
48
    }
49
}
50