Completed
Push — master ( aafa22...ae7595 )
by Alejandro
24s queued 12s
created

LcobucciJwtProviderTest::expectedTokenIsCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 12
rs 10
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