| Total Complexity | 2 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class BuilderTest extends TestCase |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var JwtConfiguration |
||
| 19 | */ |
||
| 20 | private $config; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Builder |
||
| 24 | */ |
||
| 25 | private $builder; |
||
| 26 | |||
| 27 | protected function setUp() |
||
| 28 | { |
||
| 29 | $this->config = JwtConfiguration::forSymmetricSigner(new Signer\None(), new Signer\Key('')); |
||
| 30 | $this->builder = new Builder($this->config, new FixedClaims([ |
||
| 31 | 'sub' => '[email protected]', |
||
| 32 | 'iss' => 'github', |
||
| 33 | 'aud' => 'app', |
||
| 34 | 'exp' => new DateTimeImmutable('2018-02-09 07:10:00'), |
||
| 35 | 'iat' => new DateTimeImmutable('2018-02-09 06:10:00'), |
||
| 36 | 'nbf' => new DateTimeImmutable('2018-02-09 06:10:00'), |
||
| 37 | 'jti' => '123', |
||
| 38 | 'foo' => 'bar', |
||
| 39 | 'baz' => 'qux', |
||
| 40 | ])); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @test |
||
| 45 | */ |
||
| 46 | public function it_builds_jwt_string() |
||
| 47 | { |
||
| 48 | $user = new User('[email protected]', 'qwerty'); |
||
| 49 | |||
| 50 | $jwtToken = $this->config->getParser()->parse($this->builder->fromUser($user)); |
||
| 51 | |||
| 52 | $this->assertEquals([ |
||
| 53 | 'sub' => '[email protected]', |
||
| 54 | 'iss' => 'github', |
||
| 55 | 'aud' => ['app'], |
||
| 56 | 'exp' => new DateTimeImmutable('2018-02-09 07:10:00'), |
||
| 57 | 'iat' => new DateTimeImmutable('2018-02-09 06:10:00'), |
||
| 58 | 'nbf' => new DateTimeImmutable('2018-02-09 06:10:00'), |
||
| 59 | 'jti' => '123', |
||
| 60 | 'foo' => 'bar', |
||
| 61 | 'baz' => 'qux', |
||
| 62 | ], $jwtToken->claims()->all()); |
||
| 63 | } |
||
| 65 |