File: ConstraintTestCase.php

package info (click to toggle)
php-lcobucci-jwt 5.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,304 kB
  • sloc: php: 6,674; makefile: 49
file content (42 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);

namespace Lcobucci\JWT\Tests\Validation\Constraint;

use Closure;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\JwtFacade;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Token\DataSet;
use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\Token\Signature;
use Lcobucci\JWT\UnencryptedToken;
use PHPUnit\Framework\TestCase;

abstract class ConstraintTestCase extends TestCase
{
    /**
     * @param array<non-empty-string, mixed> $claims
     * @param array<non-empty-string, mixed> $headers
     */
    protected function buildToken(
        array $claims = [],
        array $headers = [],
        ?Signature $signature = null,
    ): Plain {
        return new Plain(
            new DataSet($headers, ''),
            new DataSet($claims, ''),
            $signature ?? new Signature('sig+hash', 'sig+encoded'),
        );
    }

    protected function issueToken(Signer $signer, Signer\Key $key, ?Closure $customization = null): UnencryptedToken
    {
        return (new JwtFacade())->issue(
            $signer,
            $key,
            $customization ?? static fn (Builder $builder) => $builder,
        );
    }
}