php-simple-jwt/tests/JWTTokenTest.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2021-02-11 12:22:51 +00:00
<?php
2023-04-09 00:40:21 +00:00
namespace NoccyLabs\SimpleJWT;
2021-02-11 12:22:51 +00:00
2023-04-09 00:40:21 +00:00
use NoccyLabs\SimpleJWT\Key\JWTPlaintextKey;
2021-02-11 12:22:51 +00:00
2023-04-09 00:40:21 +00:00
class JWTTokenTest extends \PHPUnit\Framework\TestCase
2021-02-11 12:22:51 +00:00
{
2023-04-09 00:40:21 +00:00
/**
2023-04-09 22:04:43 +00:00
* @covers NoccyLabs\SimpleJWT\JWTToken
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
* @covers NoccyLabs\SimpleJWT\JWTUtil
2023-04-09 00:40:21 +00:00
*/
2021-02-11 12:22:51 +00:00
public function testGeneratingTokens()
{
2023-04-09 00:40:21 +00:00
$key = new JWTPlaintextKey("test");
2021-02-11 12:22:51 +00:00
2023-04-09 00:40:21 +00:00
$tok = new JWTToken($key);
2021-02-11 12:22:51 +00:00
$tok->addClaim("foo", true);
$token = $tok->getSignedToken();
$this->assertNotNull($token);
$this->assertTrue($tok->isGenerated());
}
2023-04-09 00:40:21 +00:00
/**
2023-04-09 22:04:43 +00:00
* @covers NoccyLabs\SimpleJWT\JWTToken
* @covers NoccyLabs\SimpleJWT\Key\JWTPlaintextKey
* @covers NoccyLabs\SimpleJWT\Collection\PropertyBag
* @covers NoccyLabs\SimpleJWT\JWTUtil
2023-04-09 00:40:21 +00:00
*/
2021-02-11 12:22:51 +00:00
public function testParsingTokens()
{
2023-04-09 00:40:21 +00:00
$key = new JWTPlaintextKey("test");
2021-02-11 12:22:51 +00:00
2023-04-09 00:40:21 +00:00
$tok = new JWTToken($key);
2021-02-11 12:22:51 +00:00
$tok->addClaim("foo", true);
$token = $tok->getSignedToken();
2023-04-09 00:40:21 +00:00
$parsed = new JWTToken($key, $token);
2021-02-11 12:22:51 +00:00
$this->assertTrue($parsed->isValid());
$this->assertFalse($parsed->isGenerated());
}
2023-04-09 00:40:21 +00:00
}