diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 031c1e1..6a508d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.2', '7.3', '7.4'] + php-versions: ['7.4', '8.0'] name: PHP ${{ matrix.php-versions }} Test steps: - name: Checkout diff --git a/composer.json b/composer.json index e8ecf19..e45b946 100644 --- a/composer.json +++ b/composer.json @@ -11,22 +11,22 @@ } ], "require": { - "php": ">=7.2.0", - "rbdwllr/reallysimplejwt": "^3.0", + "php": ">=7.4.0", + "rbdwllr/reallysimplejwt": "^4.0", "psr/http-message": "^1.0", "psr/http-server-middleware": "^1.0", - "nyholm/psr7": "^1.2" + "nyholm/psr7": "^1.5" }, "require-dev": { - "phpunit/phpunit": "^8.0", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-mockery": "^0.11", - "phpmd/phpmd": "^2.7", - "squizlabs/php_codesniffer": "^3.0", - "mockery/mockery": "^1.3", - "infection/infection": "^0.14", - "phploc/phploc": "^5.0", - "sebastian/phpcpd": "^4.0" + "phpunit/phpunit": "^9.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-mockery": "^1.0", + "phpmd/phpmd": "^2.12", + "squizlabs/php_codesniffer": "^3.6", + "mockery/mockery": "^1.5", + "infection/infection": "^0.20", + "phploc/phploc": "^7.0", + "sebastian/phpcpd": "^6.0" }, "autoload": { "psr-4": { diff --git a/src/Auth/Authorise.php b/src/Auth/Authorise.php index 98d4c17..b2ff95f 100644 --- a/src/Auth/Authorise.php +++ b/src/Auth/Authorise.php @@ -71,9 +71,9 @@ private function validate(string $token): Auth { $jwt = new Jwt(); - $parse = $jwt->parser($token, $this->secret); + $validator = $jwt->validator($token, $this->secret); - $validate = new Validate($parse); + $validate = new Validate($validator); $validationState = $validate->validate(); diff --git a/src/Factory/Jwt.php b/src/Factory/Jwt.php index 2668132..64aa072 100644 --- a/src/Factory/Jwt.php +++ b/src/Factory/Jwt.php @@ -4,12 +4,10 @@ namespace PsrJwt\Factory; +use ReallySimpleJWT\Tokens; use ReallySimpleJWT\Build; -use ReallySimpleJWT\Validate; -use ReallySimpleJWT\Encode; use ReallySimpleJWT\Parse; -use ReallySimpleJWT\Secret; -use ReallySimpleJWT\Jwt as RSJwt; +use ReallySimpleJWT\Validate; /** * PSR-JWT wraps around the ReallySimpleJWT library to provide token @@ -26,27 +24,32 @@ class Jwt */ public function builder(): Build { - return new Build( - 'JWT', - new Validate(), - new Secret(), - new Encode() - ); + $tokens = new Tokens(); + + return $tokens->builder(); } /** - * Allow for the parsing and validation of JSON Web Tokens. + * Allow for the parsing of JSON Web Tokens. * * @return Parse */ public function parser(string $token, string $secret): Parse { - $jwt = new RSJwt($token, $secret); + $tokens = new Tokens(); + + return $tokens->parser($token, $secret); + } + + /** + * Allow for the validation JSON Web Tokens. + * + * @return Validate + */ + public function validator(string $token, string $secret): Validate + { + $tokens = new Tokens(); - return new Parse( - $jwt, - new Validate(), - new Encode() - ); + return $tokens->validator($token, $secret); } } diff --git a/src/Factory/JwtMiddleware.php b/src/Factory/JwtMiddleware.php index 6ad6189..369165b 100644 --- a/src/Factory/JwtMiddleware.php +++ b/src/Factory/JwtMiddleware.php @@ -37,7 +37,7 @@ public static function html(string $secret, string $tokenKey = '', string $body * * @param string $tokenKey * @param string $secret - * @param array $body + * @param mixed[] $body * @return JwtAuthMiddleware */ public static function json(string $secret, string $tokenKey = '', array $body = []): JwtAuthMiddleware diff --git a/src/Handler/Json.php b/src/Handler/Json.php index fdb2b6a..c3a6a52 100644 --- a/src/Handler/Json.php +++ b/src/Handler/Json.php @@ -18,14 +18,14 @@ class Json extends Authorise implements RequestHandlerInterface { /** - * @var array The content to add to the response body. + * @var mixed[] The content to add to the response body. */ private $body; /** * @param string $secret * @param string $tokenKey - * @param array $body + * @param mixed[] $body */ public function __construct(string $secret, string $tokenKey, array $body) { diff --git a/src/Helper/Request.php b/src/Helper/Request.php index 39a855f..b66ab9a 100644 --- a/src/Helper/Request.php +++ b/src/Helper/Request.php @@ -33,6 +33,8 @@ public function getParsedToken(ServerRequestInterface $request, string $tokenKey /** * Retrieve the JWT header information from a request. + * + * @return mixed[] */ public function getTokenHeader(ServerRequestInterface $request, string $tokenKey): array { @@ -41,6 +43,8 @@ public function getTokenHeader(ServerRequestInterface $request, string $tokenKey /** * Retrieve the JWT payload information from a request. + * + * @return mixed[] */ public function getTokenPayload(ServerRequestInterface $request, string $tokenKey): array { diff --git a/src/Parser/Parse.php b/src/Parser/Parse.php index fe0fffb..16241a2 100644 --- a/src/Parser/Parse.php +++ b/src/Parser/Parse.php @@ -13,7 +13,7 @@ class Parse { /** - * @var array $parsers + * @var mixed[] $parsers */ private $parsers = []; diff --git a/src/Validation/Validate.php b/src/Validation/Validate.php index 1e0570f..73100e2 100644 --- a/src/Validation/Validate.php +++ b/src/Validation/Validate.php @@ -4,8 +4,9 @@ namespace PsrJwt\Validation; -use ReallySimpleJWT\Parse; +use ReallySimpleJWT\Validate as RSValidate; use ReallySimpleJWT\Exception\ValidateException; +use ReallySimpleJWT\Exception\ParseException; /** * Validate the JSON Web Token will parse, has a valid signature, is ready to @@ -14,29 +15,27 @@ class Validate { /** - * @param Parse $parse + * @param RSValidate $validate */ - private $parse; + private RSValidate $validate; - /** - * @param Parse $parse - */ - public function __construct(Parse $parse) + public function __construct(RSValidate $validate) { - $this->parse = $parse; + $this->validate = $validate; } /** * The JSON Web Token must be valid and not have expired. * - * @return array + * @return mixed[] */ public function validate(): array { try { - $this->parse->validate() - ->validateExpiration(); - } catch (ValidateException $e) { + $this->validate->structure() + ->signature() + ->expiration(); + } catch (ValidateException | ParseException $e) { if (in_array($e->getCode(), [1, 2, 3, 4], true)) { return ['code' => $e->getCode(), 'message' => $e->getMessage()]; } @@ -48,13 +47,14 @@ public function validate(): array /** * The token must be ready to use. * - * @return array + * @param mixed[] $validationState + * @return mixed[] */ public function validateNotBefore(array $validationState): array { try { - $this->parse->validateNotBefore(); - } catch (ValidateException $e) { + $this->validate->notBefore(); + } catch (ValidateException | ParseException $e) { if ($e->getCode() === 5) { return ['code' => $e->getCode(), 'message' => $e->getMessage()]; } diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php index e6fa1c3..39b0bf0 100644 --- a/tests/Auth/AuthTest.php +++ b/tests/Auth/AuthTest.php @@ -10,7 +10,7 @@ class AuthTest extends TestCase /** * @covers PsrJwt\Auth\Auth::__construct */ - public function testAuth() + public function testAuth(): Auth { $auth = new Auth(200, 'Ok'); $this->assertInstanceOf(Auth::class, $auth); @@ -21,7 +21,7 @@ public function testAuth() * @depends testAuth * @covers PsrJwt\Auth\Auth::getCode */ - public function testGetCode($auth) + public function testGetCode(Auth $auth): void { $this->assertSame(200, $auth->getCode()); } @@ -30,7 +30,7 @@ public function testGetCode($auth) * @depends testAuth * @covers PsrJwt\Auth\Auth::getMessage */ - public function testGetMessage($auth) + public function testGetMessage(Auth $auth): void { $this->assertSame('Ok', $auth->getMessage()); } diff --git a/tests/Auth/AuthoriseTest.php b/tests/Auth/AuthoriseTest.php index e8ce02e..b0817cd 100644 --- a/tests/Auth/AuthoriseTest.php +++ b/tests/Auth/AuthoriseTest.php @@ -7,6 +7,7 @@ use PsrJwt\Auth\Authorise; use PsrJwt\Auth\Auth; use PsrJwt\Factory\Jwt; +use PsrJwt\Parser\ParseException; use ReflectionMethod; use Mockery as m; @@ -15,7 +16,7 @@ class AuthoriseTest extends TestCase /** * @covers PsrJwt\Auth\Authorise::__construct */ - public function testAuthorise() + public function testAuthorise(): void { $auth = new Authorise('secret', 'jwt'); $this->assertInstanceOf(Authorise::class, $auth); @@ -34,7 +35,7 @@ public function testAuthorise() * @uses PsrJwt\Parser\Cookie * @uses PsrJwt\Parser\Request */ - public function testAuthoriseOk() + public function testAuthoriseOk(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -81,7 +82,7 @@ public function testAuthoriseOk() * @uses PsrJwt\Parser\Request * @uses PsrJwt\Parser\ParseException */ - public function testAuthoriseBadRequest() + public function testAuthoriseBadRequest(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -116,7 +117,7 @@ public function testAuthoriseBadRequest() * @uses PsrJwt\Factory\Jwt * @uses PsrJwt\Validation\Validate */ - public function testValidate() + public function testValidate(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -142,7 +143,7 @@ public function testValidate() * @uses PsrJwt\Factory\Jwt * @uses PsrJwt\Validation\Validate */ - public function testValidateBadSecret() + public function testValidateBadSecret(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -168,7 +169,7 @@ public function testValidateBadSecret() * @uses PsrJwt\Factory\Jwt * @uses PsrJwt\Validation\Validate */ - public function testValidateBadExpiration() + public function testValidateBadExpiration(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -195,7 +196,7 @@ public function testValidateBadExpiration() * @uses PsrJwt\Factory\Jwt * @uses PsrJwt\Validation\Validate */ - public function testValidateBadNotBefore() + public function testValidateBadNotBefore(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -220,7 +221,7 @@ public function testValidateBadNotBefore() * @uses PsrJwt\Auth\Authorise::__construct * @uses PsrJwt\Auth\Auth */ - public function testValidationResponse() + public function testValidationResponse(): void { $auth = new Authorise('secret', 'jwt'); @@ -238,7 +239,7 @@ public function testValidationResponse() * @uses PsrJwt\Auth\Authorise::__construct * @uses PsrJwt\Auth\Auth */ - public function testValidationResponseErrors() + public function testValidationResponseErrors(): void { $auth = new Authorise('secret', 'jwt'); @@ -272,7 +273,7 @@ public function testValidationResponseErrors() * @uses PsrJwt\Parser\Body * @uses PsrJwt\Parser\Request */ - public function testGetToken() + public function testGetToken(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -299,7 +300,7 @@ public function testGetToken() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenCookie() + public function testGetTokenCookie(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -329,7 +330,7 @@ public function testGetTokenCookie() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenBody() + public function testGetTokenBody(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -362,7 +363,7 @@ public function testGetTokenBody() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenBodyObject() + public function testGetTokenBodyObject(): void { $token = new \stdClass(); $token->my_token = 'ghi.123.xyz'; @@ -398,7 +399,7 @@ public function testGetTokenBodyObject() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenQuery() + public function testGetTokenQuery(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -425,8 +426,6 @@ public function testGetTokenQuery() } /** - * @expectedException PsrJwt\Parser\ParseException - * @expectedExceptionMessage JSON Web Token not set in request. * @covers PsrJwt\Auth\Authorise::getToken * @uses PsrJwt\Auth\Authorise * @uses PsrJwt\Parser\Parse @@ -437,7 +436,7 @@ public function testGetTokenQuery() * @uses PsrJwt\Parser\Request * @uses PsrJwt\Parser\ParseException */ - public function testGetTokenNoToken() + public function testGetTokenNoToken(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -458,7 +457,9 @@ public function testGetTokenNoToken() $method = new ReflectionMethod(Authorise::class, 'getToken'); $method->setAccessible(true); - $result = $method->invokeArgs($auth, [$request]); + $this->expectException(ParseException::class); + $this->expectExceptionMessage("JSON Web Token not set in request."); + $method->invokeArgs($auth, [$request]); } public function tearDown(): void diff --git a/tests/Factory/JwtMiddlewareTest.php b/tests/Factory/JwtMiddlewareTest.php index 2d188f1..0627187 100644 --- a/tests/Factory/JwtMiddlewareTest.php +++ b/tests/Factory/JwtMiddlewareTest.php @@ -20,7 +20,7 @@ class JwtMiddlewareTest extends TestCase * @uses PsrJwt\Auth\Authorise * @uses PsrJwt\Handler\Html */ - public function testJwtMiddlewareHtml() + public function testJwtMiddlewareHtml(): void { $this->assertInstanceOf( JwtAuthMiddleware::class, @@ -44,7 +44,7 @@ public function testJwtMiddlewareHtml() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testFactoryValidation() + public function testFactoryValidation(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -90,7 +90,7 @@ public function testFactoryValidation() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testJsonFactoryValidation() + public function testJsonFactoryValidation(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); diff --git a/tests/Factory/JwtTest.php b/tests/Factory/JwtTest.php index 18e98ba..c89778c 100644 --- a/tests/Factory/JwtTest.php +++ b/tests/Factory/JwtTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use ReallySimpleJWT\Build; use ReallySimpleJWT\Parse; +use ReallySimpleJWT\Validate; use PsrJwt\Factory\Jwt; class JwtTest extends TestCase @@ -12,7 +13,7 @@ class JwtTest extends TestCase /** * @covers PsrJwt\Factory\Jwt::builder */ - public function testJwtBuilder() + public function testJwtBuilder(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -23,11 +24,22 @@ public function testJwtBuilder() /** * @covers PsrJwt\Factory\Jwt::parser */ - public function testJwtParser() + public function testJwtParser(): void { $jwt = new Jwt(); $jwt = $jwt->parser('aaa.bbb.ccc', 'secret'); $this->assertInstanceOf(Parse::class, $jwt); } + + /** + * @covers PsrJwt\Factory\Jwt::validator + */ + public function testJwtValidator(): void + { + $jwt = new Jwt(); + $jwt = $jwt->validator('aaa.bbb.ccc', 'secret'); + + $this->assertInstanceOf(Validate::class, $jwt); + } } diff --git a/tests/Handler/HtmlTest.php b/tests/Handler/HtmlTest.php index 67488de..befb1ab 100644 --- a/tests/Handler/HtmlTest.php +++ b/tests/Handler/HtmlTest.php @@ -17,7 +17,7 @@ class HtmlTest extends TestCase * @covers PsrJwt\Handler\Html::__construct * @uses PsrJwt\Auth\Authorise */ - public function testAuthHandler() + public function testAuthHandler(): void { $auth = new Html('secret', 'tokenKey', 'body'); @@ -40,7 +40,7 @@ public function testAuthHandler() * @uses PsrJwt\Parser\Parse * @uses PsrJwt\Parser\Request */ - public function testAuthoriseOk() + public function testAuthoriseOk(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -89,7 +89,7 @@ public function testAuthoriseOk() * @uses PsrJwt\Parser\Parse * @uses PsrJwt\Parser\Request */ - public function testAuthoriseNoBody() + public function testAuthoriseNoBody(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -138,7 +138,7 @@ public function testAuthoriseNoBody() * @uses PsrJwt\Parser\Request * @uses PsrJwt\Parser\ParseException */ - public function testAuthoriseBadRequest() + public function testAuthoriseBadRequest(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -186,7 +186,7 @@ public function testAuthoriseBadRequest() * @uses PsrJwt\Parser\Parse * @uses PsrJwt\Parser\Request */ - public function testAuthoriseUnauthorized() + public function testAuthoriseUnauthorized(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); diff --git a/tests/Handler/JsonTest.php b/tests/Handler/JsonTest.php index f067a50..e784f3e 100644 --- a/tests/Handler/JsonTest.php +++ b/tests/Handler/JsonTest.php @@ -17,7 +17,7 @@ class JsonTest extends TestCase * @covers PsrJwt\Handler\Json::__construct * @uses PsrJwt\Auth\Authorise */ - public function testJsonAuthHandler() + public function testJsonAuthHandler(): void { $auth = new Json('secret', 'tokenKey', ['body']); @@ -41,11 +41,13 @@ public function testJsonAuthHandler() * @uses PsrJwt\Parser\Bearer * @uses PsrJwt\Parser\Request */ - public function testAuthoriseOk() + public function testAuthoriseOk(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); $token = $jwt->setSecret('Secret123!456$') + ->setExpiration(time() + 10) + ->setNotBefore(time() - 10) ->setIssuer('localhost') ->build() ->getToken(); @@ -90,11 +92,13 @@ public function testAuthoriseOk() * @uses PsrJwt\Parser\Parse * @uses PsrJwt\Parser\Request */ - public function testAuthoriseFail() + public function testAuthoriseFail(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); $token = $jwt->setSecret('Secret123!456$') + ->setExpiration(time() + 10) + ->setNotBefore(time() - 10) ->setIssuer('localhost') ->build() ->getToken(); diff --git a/tests/Helper/RequestTest.php b/tests/Helper/RequestTest.php index 066ef88..36188d0 100644 --- a/tests/Helper/RequestTest.php +++ b/tests/Helper/RequestTest.php @@ -19,7 +19,7 @@ class RequestTest extends TestCase /** * @covers PsrJwt\Helper\Request */ - public function testRequest() + public function testRequest(): void { $request = new Request(); @@ -36,7 +36,7 @@ public function testRequest() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetParsedToken() + public function testGetParsedToken(): void { $httpRequest = m::mock(ServerRequestInterface::class); $httpRequest->shouldReceive('getHeader') @@ -62,7 +62,7 @@ public function testGetParsedToken() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenHeader() + public function testGetTokenHeader(): void { $httpRequest = m::mock(ServerRequestInterface::class); $httpRequest->shouldReceive('getHeader') @@ -88,7 +88,7 @@ public function testGetTokenHeader() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testGetTokenPayload() + public function testGetTokenPayload(): void { $httpRequest = m::mock(ServerRequestInterface::class); $httpRequest->shouldReceive('getHeader') diff --git a/tests/JwtAuthMiddlewareTest.php b/tests/JwtAuthMiddlewareTest.php index 3402800..db14630 100644 --- a/tests/JwtAuthMiddlewareTest.php +++ b/tests/JwtAuthMiddlewareTest.php @@ -21,7 +21,7 @@ class JwtAuthMiddlewareTest extends TestCase * @uses PsrJwt\Auth\Authorise * @uses PsrJwt\Handler\Html */ - public function testJwtAuthProcess() + public function testJwtAuthProcess(): void { $authorise = new Html('secret', 'jwt', ''); @@ -46,7 +46,7 @@ public function testJwtAuthProcess() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\Request */ - public function testProcess() + public function testProcess(): void { $jwt = $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -97,7 +97,7 @@ public function testProcess() * @uses PsrJwt\Parser\Request * @uses PsrJwt\Parser\ParseException */ - public function testProcessFail() + public function testProcessFail(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getCookieParams') @@ -143,7 +143,7 @@ public function testProcessFail() * @uses PsrJwt\Parser\Request * @uses PsrJwt\Handler\Html */ - public function testInvoke() + public function testInvoke(): void { $jwt = new Jwt(); $jwt = $jwt->builder(); @@ -197,7 +197,7 @@ public function testInvoke() * @uses PsrJwt\Handler\Html * @uses PsrJwt\Parser\Request */ - public function testInvokeFail() + public function testInvokeFail(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getCookieParams') diff --git a/tests/Parser/BearerTest.php b/tests/Parser/BearerTest.php index b541c55..fe74837 100644 --- a/tests/Parser/BearerTest.php +++ b/tests/Parser/BearerTest.php @@ -13,7 +13,7 @@ class BearerTest extends TestCase /** * @covers PsrJwt\Parser\Bearer */ - public function testBearer() + public function testBearer(): void { $bearer = new Bearer(); @@ -24,7 +24,7 @@ public function testBearer() /** * @covers PsrJwt\Parser\Bearer::parse */ - public function testParse() + public function testParse(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -41,7 +41,7 @@ public function testParse() /** * @covers PsrJwt\Parser\Bearer::parse */ - public function testParseInvalid() + public function testParseInvalid(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') diff --git a/tests/Parser/BodyTest.php b/tests/Parser/BodyTest.php index a13e9bf..b771606 100644 --- a/tests/Parser/BodyTest.php +++ b/tests/Parser/BodyTest.php @@ -14,7 +14,7 @@ class BodyTest extends TestCase /** * @covers PsrJwt\Parser\Body::__construct */ - public function testBody() + public function testBody(): void { $body = new Body('jwt'); @@ -26,7 +26,7 @@ public function testBody() * @covers PsrJwt\Parser\Body::parse * @uses PsrJwt\Parser\Body::__construct */ - public function testParse() + public function testParse(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getParsedBody') @@ -43,7 +43,7 @@ public function testParse() * @covers PsrJwt\Parser\Body::parse * @uses PsrJwt\Parser\Body */ - public function testParseObject() + public function testParseObject(): void { $object = new \stdClass(); $object->jwt = 'abc.def.ghi'; @@ -63,7 +63,7 @@ public function testParseObject() * @covers PsrJwt\Parser\Body::parse * @uses PsrJwt\Parser\Body */ - public function testParseString() + public function testParseString(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getParsedBody') @@ -80,7 +80,7 @@ public function testParseString() * @covers PsrJwt\Parser\Body::parseBodyObject * @uses PsrJwt\Parser\Body::__construct */ - public function testParseBodyObject() + public function testParseBodyObject(): void { $object = new \stdClass(); $object->jwt = 'abc.def.ghi'; @@ -103,7 +103,7 @@ public function testParseBodyObject() * @covers PsrJwt\Parser\Body::parseBodyObject * @uses PsrJwt\Parser\Body::__construct */ - public function testParseBodyObjectNoKey() + public function testParseBodyObjectNoKey(): void { $object = new \stdClass(); @@ -125,7 +125,7 @@ public function testParseBodyObjectNoKey() * @covers PsrJwt\Parser\Body::parseBodyObject * @uses PsrJwt\Parser\Body::__construct */ - public function testParseBodyObjectNoObject() + public function testParseBodyObjectNoObject(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getParsedBody') diff --git a/tests/Parser/CookieTest.php b/tests/Parser/CookieTest.php index ac2c107..d53988f 100644 --- a/tests/Parser/CookieTest.php +++ b/tests/Parser/CookieTest.php @@ -13,7 +13,7 @@ class CookieTest extends TestCase /** * @covers PsrJwt\Parser\Cookie::__construct */ - public function testCookie() + public function testCookie(): void { $cookie = new Cookie('jwt'); @@ -25,7 +25,7 @@ public function testCookie() * @covers PsrJwt\Parser\Cookie::parse * @uses PsrJwt\Parser\Cookie::__construct */ - public function testParse() + public function testParse(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getCookieParams') diff --git a/tests/Parser/ParseExceptionTest.php b/tests/Parser/ParseExceptionTest.php index d286822..c61e8ea 100644 --- a/tests/Parser/ParseExceptionTest.php +++ b/tests/Parser/ParseExceptionTest.php @@ -11,7 +11,7 @@ class ParseExceptionTest extends TestCase /** * @covers PsrJwt\Parser\ParseException */ - public function testParseException() + public function testParseException(): void { $exception = new ParseException('Error', 1, null); diff --git a/tests/Parser/ParseTest.php b/tests/Parser/ParseTest.php index 25b93fd..86743fe 100644 --- a/tests/Parser/ParseTest.php +++ b/tests/Parser/ParseTest.php @@ -18,7 +18,7 @@ class ParseTest extends TestCase /** * @covers PsrJwt\Parser\Parse */ - public function testParse() + public function testParse(): void { $parse = new Parse(); $this->assertInstanceOf(Parse::class, $parse); @@ -30,7 +30,7 @@ public function testParse() * @uses PsrJwt\Parser\Parse * @uses PsrJwt\Parser\Bearer */ - public function testFindToken() + public function testFindToken(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -54,7 +54,7 @@ public function testFindToken() * @uses PsrJwt\Parser\Body * @uses PsrJwt\Parser\Query */ - public function testFindTokenMultiParser() + public function testFindTokenMultiParser(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getHeader') @@ -79,7 +79,7 @@ public function testFindTokenMultiParser() * @covers PsrJwt\Parser\Parse::findToken * @uses PsrJwt\Parser\Parse */ - public function testFindTokenFail() + public function testFindTokenFail(): void { $request = m::mock(ServerRequestInterface::class); diff --git a/tests/Parser/QueryTest.php b/tests/Parser/QueryTest.php index 07ce9cb..ad6d5dc 100644 --- a/tests/Parser/QueryTest.php +++ b/tests/Parser/QueryTest.php @@ -13,7 +13,7 @@ class QueryTest extends TestCase /** * @covers PsrJwt\Parser\Query::__construct */ - public function testQuery() + public function testQuery(): void { $query = new Query('jwt'); @@ -25,7 +25,7 @@ public function testQuery() * @covers PsrJwt\Parser\Query::parse * @uses PsrJwt\Parser\Query::__construct */ - public function testParse() + public function testParse(): void { $request = m::mock(ServerRequestInterface::class); $request->shouldReceive('getQueryParams') diff --git a/tests/Parser/RequestTest.php b/tests/Parser/RequestTest.php index 04df038..c168dcf 100644 --- a/tests/Parser/RequestTest.php +++ b/tests/Parser/RequestTest.php @@ -14,7 +14,7 @@ class RequestTest extends TestCase * @covers PsrJwt\Parser\Request * @uses PsrJwt\Parser\Parse */ - public function testRequest() + public function testRequest(): void { $parse = new Parse(); @@ -31,12 +31,12 @@ public function testRequest() * @uses PsrJwt\Parser\Body * @uses PsrJwt\Parser\Query */ - public function testParse() + public function testParse(): void { $parse = m::mock(Parse::class); $parse->shouldReceive('addParser') ->times(4); - + $parse->shouldReceive('findToken') ->once() ->andReturn('abcdef.123.abcdef'); @@ -57,12 +57,12 @@ public function testParse() * @uses PsrJwt\Parser\Query * @uses PsrJwt\Parser\ParseException */ - public function testParseNoToken() + public function testParseNoToken(): void { $parse = m::mock(Parse::class); $parse->shouldReceive('addParser') ->times(4); - + $parse->shouldReceive('findToken') ->once() ->andReturn(''); diff --git a/tests/Validation/ValidateTest.php b/tests/Validation/ValidateTest.php index c484531..5f3e2b0 100644 --- a/tests/Validation/ValidateTest.php +++ b/tests/Validation/ValidateTest.php @@ -3,7 +3,7 @@ namespace Tests\Validation; use PHPUnit\Framework\TestCase; -use ReallySimpleJWT\Parse; +use ReallySimpleJWT\Validate as RSValidate; use PsrJwt\Factory\Jwt; use PsrJwt\Validation\Validate; @@ -13,7 +13,7 @@ class ValidateTest extends TestCase * @covers PsrJwt\Validation\Validate::__construct * @uses PsrJwt\Factory\Jwt */ - public function testValidate() + public function testValidate(): void { $jwt = new Jwt(); $builder = $jwt->builder(); @@ -24,7 +24,7 @@ public function testValidate() ->getToken(); $validate = new Validate( - $jwt->parser($token, 'Secret123!456$') + $jwt->validator($token, 'Secret123!456$') ); $this->assertInstanceOf(Validate::class, $validate); @@ -35,7 +35,7 @@ public function testValidate() * @uses PsrJwt\Validation\Validate * @uses PsrJwt\Factory\Jwt */ - public function testValidateOk() + public function testValidateOk(): void { $jwt = new Jwt(); $builder = $jwt->builder(); @@ -46,7 +46,7 @@ public function testValidateOk() ->getToken(); $validate = new Validate( - $jwt->parser($token, 'Secret123!456$') + $jwt->validator($token, 'Secret123!456$') ); $result = $validate->validate(); @@ -60,7 +60,7 @@ public function testValidateOk() * @uses PsrJwt\Validation\Validate * @uses PsrJwt\Factory\Jwt */ - public function testValidateExpiration() + public function testValidateExpiration(): void { $jwt = new Jwt(); $builder = $jwt->builder(); @@ -71,7 +71,7 @@ public function testValidateExpiration() ->getToken(); $validate = new Validate( - $jwt->parser($token, 'Secret123!456$') + $jwt->validator($token, 'Secret123!456$') ); $result = $validate->validate(); @@ -83,14 +83,14 @@ public function testValidateExpiration() /** * @covers PsrJwt\Validation\Validate::validate * @uses PsrJwt\Validation\Validate - * @uses PsrJwt\Factory\Jwt::parser + * @uses PsrJwt\Factory\Jwt::validator */ - public function testValidateTokenStructure() + public function testValidateTokenStructure(): void { $jwt = new Jwt(); $validate = new Validate( - $jwt->parser('123.abc', 'Secret123!456$') + $jwt->validator('123.abc', 'Secret123!456$') ); $result = $validate->validate(); @@ -102,14 +102,14 @@ public function testValidateTokenStructure() /** * @covers PsrJwt\Validation\Validate::validate * @uses PsrJwt\Validation\Validate - * @uses PsrJwt\Factory\Jwt::parser + * @uses PsrJwt\Factory\Jwt::validator */ - public function testValidateBadSignature() + public function testValidateBadSignature(): void { $jwt = new Jwt(); $validate = new Validate( - $jwt->parser('123.abc.456', 'Secret123!456$') + $jwt->validator('123.abc.456', 'Secret123!456$') ); $result = $validate->validate(); @@ -123,7 +123,7 @@ public function testValidateBadSignature() * @uses PsrJwt\Validation\Validate * @uses PsrJwt\Factory\Jwt */ - public function testValidateNotBefore() + public function testValidateNotBefore(): void { $jwt = new Jwt(); $builder = $jwt->builder(); @@ -134,7 +134,7 @@ public function testValidateNotBefore() ->getToken(); $validate = new Validate( - $jwt->parser($token, 'Secret123!456$') + $jwt->validator($token, 'Secret123!456$') ); $result = $validate->validateNotBefore( @@ -150,7 +150,7 @@ public function testValidateNotBefore() * @uses PsrJwt\Validation\Validate * @uses PsrJwt\Factory\Jwt */ - public function testValidateNotBeforeOk() + public function testValidateNotBeforeOk(): void { $jwt = new Jwt(); $builder = $jwt->builder(); @@ -161,7 +161,7 @@ public function testValidateNotBeforeOk() ->getToken(); $validate = new Validate( - $jwt->parser($token, 'Secret123!456$') + $jwt->validator($token, 'Secret123!456$') ); $result = $validate->validateNotBefore(