diff --git a/composer.json b/composer.json index 960e2f8..545dc9b 100644 --- a/composer.json +++ b/composer.json @@ -45,6 +45,6 @@ "lint": "parallel-lint", "phpstan": "phpstan analyse --memory-limit=512M", "psalm": "psalm", - "phpcs": "phpcs --standard=PSR12" + "phpcs": "phpcs --standard=PSR12 --exclude=Generic.Files.LineLength" } } diff --git a/src/Config/Constants.php b/src/Config/Constants.php index 0aa3c28..85dff18 100644 --- a/src/Config/Constants.php +++ b/src/Config/Constants.php @@ -22,7 +22,7 @@ class Constants public static string $ORG_CLAIM = 'org'; - public static function getValidIdentityClaims() + public static function getValidIdentityClaims(): array { return array_merge( self::$VALID_IDENTITY_STRING_CLAIMS, @@ -31,7 +31,7 @@ public static function getValidIdentityClaims() ); } - public static function getValidScopes() + public static function getValidScopes(): array { return array_merge( self::$VALID_IDENTITY_STRING_CLAIMS, diff --git a/src/Config/HelloConfig.php b/src/Config/HelloConfig.php index 4710484..6781d1a 100644 --- a/src/Config/HelloConfig.php +++ b/src/Config/HelloConfig.php @@ -10,6 +10,11 @@ class HelloConfig implements ConfigInterface private string $logoutApiRoute; private bool $sameSiteStrict; private ?string $clientId; + + /** + * Include encrypted cookie in auth response + * @var ?bool $cookieToken + */ private ?bool $cookieToken = null; private ?string $redirectURI; private string $helloDomain; @@ -52,7 +57,7 @@ public function __construct( 'loggedOut' => '/', 'error' => '/error', ], - ?bool $cookieToken = null, + ?bool $cookieToken = null, // include encrypted cookie in auth response ?bool $logDebug = null, ?array $error = null ) { diff --git a/src/Exception/CallbackException.php b/src/Exception/CallbackException.php index d7f7b2e..5497c94 100644 --- a/src/Exception/CallbackException.php +++ b/src/Exception/CallbackException.php @@ -11,9 +11,9 @@ class CallbackException extends Exception public function __construct( array $errorDetails, - $message = "Callback Exception", - $code = 0, - Throwable $previous = null + string $message = "Callback Exception", + int $code = 0, + ?Throwable $previous = null ) { $this->errorDetails = $errorDetails; parent::__construct($message, $code, $previous); diff --git a/src/Exception/SameSiteCallbackException.php b/src/Exception/SameSiteCallbackException.php index d36bd16..607ad62 100644 --- a/src/Exception/SameSiteCallbackException.php +++ b/src/Exception/SameSiteCallbackException.php @@ -10,9 +10,9 @@ class SameSiteCallbackException extends Exception private array $errorDetails; public function __construct( - $message = "Same Site Callback Exception", - $code = 0, - Throwable $previous = null + string $message = "Same Site Callback Exception", + int $code = 0, + ?Throwable $previous = null ) { parent::__construct($message, $code, $previous); } diff --git a/src/Handler/Callback.php b/src/Handler/Callback.php index 9ee6126..da2b85a 100644 --- a/src/Handler/Callback.php +++ b/src/Handler/Callback.php @@ -16,6 +16,7 @@ use HelloCoop\Lib\TokenParser; use Exception; use HelloCoop\Utils\CurlWrapper; +use Throwable; class Callback { @@ -260,13 +261,13 @@ public function handleCallback(): ?string * * @param array $error Error details including 'target_uri', 'error', and 'error_description'. * @param string $errorMessage A message describing the error. - * @param \Throwable|null $previous Previous exception for chaining (optional). + * @param Throwable|null $previous Previous exception for chaining (optional). * * @return string The error page URL. * * @throws CallbackException If no error URI is provided. */ - private function sendErrorPage(array $error, string $errorMessage, \Throwable $previous = null): string + private function sendErrorPage(array $error, string $errorMessage, ?Throwable $previous = null): string { $error_uri = $error['target_uri'] ?? $this->config->getRoutes()['error'] ?? null; if ($error_uri) { diff --git a/src/HelloClient.php b/src/HelloClient.php index 35eb821..554d562 100644 --- a/src/HelloClient.php +++ b/src/HelloClient.php @@ -31,9 +31,9 @@ class HelloClient public function __construct( ConfigInterface $config, - HelloRequestInterface $helloRequest = null, - HelloResponseInterface $helloResponse = null, - PageRendererInterface $pageRenderer = null + ?HelloRequestInterface $helloRequest = null, + ?HelloResponseInterface $helloResponse = null, + ?PageRendererInterface $pageRenderer = null ) { $this->config = $config; $this->helloRequest = $helloRequest ??= new HelloRequest(); diff --git a/src/Lib/PKCE.php b/src/Lib/PKCE.php index 79d5a3a..f73ce8c 100644 --- a/src/Lib/PKCE.php +++ b/src/Lib/PKCE.php @@ -4,7 +4,7 @@ class PKCE { - const VERIFIER_LENGTH = 43; + public const VERIFIER_LENGTH = 43; /** Generate cryptographically strong random string * @param int $size The desired length of the string diff --git a/src/Type/AuthCookie.php b/src/Type/AuthCookie.php index d24d51f..3dd2356 100644 --- a/src/Type/AuthCookie.php +++ b/src/Type/AuthCookie.php @@ -5,7 +5,8 @@ use InvalidArgumentException; // Authentication cookie class, extending Claims -class AuthCookie extends Claims { +class AuthCookie extends Claims +{ /** @var int */ public $iat; @@ -15,7 +16,8 @@ class AuthCookie extends Claims { */ public $extraProperties = []; - public function __construct(string $sub, int $iat) { + public function __construct(string $sub, int $iat) + { parent::__construct($sub); $this->iat = $iat; } @@ -23,21 +25,24 @@ public function __construct(string $sub, int $iat) { /** * Add an extra property. */ - public function setExtraProperty(string $key, $value): void { + public function setExtraProperty(string $key, $value): void + { $this->extraProperties[$key] = $value; } /** * Get an extra property. */ - public function getExtraProperty(string $key) { + public function getExtraProperty(string $key) + { return $this->extraProperties[$key] ?? null; } /** * Create an instance from an array of key-value pairs. */ - public static function fromArray(array $data): self { + public static function fromArray(array $data): self + { if (!isset($data['sub'], $data['iat'])) { throw new InvalidArgumentException('Missing required keys "sub" or "iat".'); } @@ -52,11 +57,12 @@ public static function fromArray(array $data): self { return $instance; } - + /** * Convert the instance to an array of key-value pairs. */ - public function toArray(): array { + public function toArray(): array + { return array_merge(['sub' => $this->sub, 'iat' => $this->iat], $this->extraProperties); } -} \ No newline at end of file +} diff --git a/src/Type/AuthUpdates.php b/src/Type/AuthUpdates.php index 5178dab..496b2fb 100644 --- a/src/Type/AuthUpdates.php +++ b/src/Type/AuthUpdates.php @@ -1,49 +1,61 @@ additionalProperties = $updates; } // Magic methods for dynamic properties - public function __set(string $name, $value): void { + public function __set(string $name, $value): void + { $this->additionalProperties[$name] = $value; } - public function __get(string $name) { + public function __get(string $name) + { return $this->additionalProperties[$name] ?? null; } - public function __isset(string $name): bool { + public function __isset(string $name): bool + { return isset($this->additionalProperties[$name]); } - public function __unset(string $name): void { + public function __unset(string $name): void + { unset($this->additionalProperties[$name]); } // ArrayAccess implementation - public function offsetExists($offset): bool { + public function offsetExists($offset): bool + { return isset($this->additionalProperties[$offset]); } - public function offsetGet($offset) { + public function offsetGet($offset): ?string + { return $this->additionalProperties[$offset] ?? null; } - public function offsetSet($offset, $value): void { + public function offsetSet($offset, $value): void + { $this->additionalProperties[$offset] = $value; } - public function offsetUnset($offset): void { + public function offsetUnset($offset): void + { unset($this->additionalProperties[$offset]); } - public function toArray(): array { + public function toArray(): array + { return array_merge(get_object_vars($this), $this->additionalProperties); } -} \ No newline at end of file +} diff --git a/src/Type/Claims.php b/src/Type/Claims.php index b544130..5ca36ea 100644 --- a/src/Type/Claims.php +++ b/src/Type/Claims.php @@ -6,13 +6,17 @@ use HelloCoop\Type\Common\OptionalAccountClaimsTrait; use HelloCoop\Type\Common\OptionalOrgClaimTrait; -class Claims { - use OptionalStringClaimsTrait, OptionalAccountClaimsTrait, OptionalOrgClaimTrait; +class Claims +{ + use OptionalStringClaimsTrait; + use OptionalAccountClaimsTrait; + use OptionalOrgClaimTrait; /** @var string */ public $sub; - public function __construct(string $sub) { + public function __construct(string $sub) + { $this->sub = $sub; } -} \ No newline at end of file +} diff --git a/src/Type/Common/OptionalAccountClaimsTrait.php b/src/Type/Common/OptionalAccountClaimsTrait.php index c05f72d..27c866b 100644 --- a/src/Type/Common/OptionalAccountClaimsTrait.php +++ b/src/Type/Common/OptionalAccountClaimsTrait.php @@ -2,10 +2,11 @@ namespace HelloCoop\Type\Common; -trait OptionalAccountClaimsTrait { +trait OptionalAccountClaimsTrait +{ /** * @var array * An associative array of account claims (e.g., ['github' => ['id' => '123', 'username' => 'user']]). */ public $claims = []; -} \ No newline at end of file +} diff --git a/src/Type/Common/OptionalOrgClaimTrait.php b/src/Type/Common/OptionalOrgClaimTrait.php index 4e97232..6bef94c 100644 --- a/src/Type/Common/OptionalOrgClaimTrait.php +++ b/src/Type/Common/OptionalOrgClaimTrait.php @@ -2,10 +2,11 @@ namespace HelloCoop\Type\Common; -trait OptionalOrgClaimTrait { +trait OptionalOrgClaimTrait +{ /** * @var array{id: string, domain: string}|null * Optional organization claim. */ public $org; -} \ No newline at end of file +} diff --git a/src/Type/Common/OptionalStringClaimsTrait.php b/src/Type/Common/OptionalStringClaimsTrait.php index 9798c9c..d35623d 100644 --- a/src/Type/Common/OptionalStringClaimsTrait.php +++ b/src/Type/Common/OptionalStringClaimsTrait.php @@ -1,14 +1,16 @@ codeVerifier = $codeVerifier; $this->nonce = $nonce; $this->redirectUri = $redirectUri; $this->targetUri = $targetUri; } - public static function fromArray(array $data): self { + public static function fromArray(array $data): self + { if (!isset($data['code_verifier'])) { throw new InvalidArgumentException('Missing code_verifier'); } @@ -42,7 +45,8 @@ public static function fromArray(array $data): self { ); } - public function toArray(): array { + public function toArray(): array + { return [ 'code_verifier' => $this->codeVerifier, 'nonce' => $this->nonce, @@ -51,4 +55,3 @@ public function toArray(): array { ]; } } - diff --git a/tests/Config/HelloConfigBuilderTest.php b/tests/Config/HelloConfigBuilderTest.php index 81d31fe..79d58ca 100644 --- a/tests/Config/HelloConfigBuilderTest.php +++ b/tests/Config/HelloConfigBuilderTest.php @@ -8,7 +8,7 @@ class HelloConfigBuilderTest extends TestCase { - public function testHelloConfigBuilderBuildsConfigCorrectly() + public function testHelloConfigBuilderBuildsConfigCorrectly(): void { // Arrange: Create the builder and set values $builder = new HelloConfigBuilder(); diff --git a/tests/Handler/CallbackTest.php b/tests/Handler/CallbackTest.php index 986eec5..8809ae8 100644 --- a/tests/Handler/CallbackTest.php +++ b/tests/Handler/CallbackTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->tokenFetcherMock->method('fetchToken')->willReturn('valid_token_id'); } - public function testHandleCallbackSuccessfulLogin() + public function testHandleCallbackSuccessfulLogin(): void { $_COOKIE['oidcName'] = $this->crypto->encrypt([ 'code_verifier' => 'test_verifier', @@ -68,7 +68,7 @@ public function testHandleCallbackSuccessfulLogin() $this->assertEquals('http://api.example.com?uri=example.com&appName=MyApp&redirectURI=https%3A%2F%2Fexample.com%2Fcallback&targetURI=%2Fdashboard&wildcard_console=true', $result); } - public function testHandleCallbackMissingCode() + public function testHandleCallbackMissingCode(): void { $_COOKIE['oidcName'] = $this->crypto->encrypt([ 'code_verifier' => 'test_verifier', @@ -89,7 +89,7 @@ public function testHandleCallbackMissingCode() $this->assertEquals('/dashboard?error=invalid_request&error_description=Missing+code+parameter', $this->callback->handleCallback()); } - public function testHandleCallbackInvalidTokenAudience() + public function testHandleCallbackInvalidTokenAudience(): void { // Set up mock behaviors $_GET = array_merge($_GET, [ diff --git a/tests/Handler/LoginTest.php b/tests/Handler/LoginTest.php index aa5f156..ceb944c 100644 --- a/tests/Handler/LoginTest.php +++ b/tests/Handler/LoginTest.php @@ -36,7 +36,7 @@ protected function setUp(): void ); } - public function testGenerateLoginUrlSuccess() + public function testGenerateLoginUrlSuccess(): void { // Setup mocks $_GET = [ @@ -75,7 +75,7 @@ public function testGenerateLoginUrlSuccess() //$this->assertEquals('https://wallet.hello.coop/authorize?client_id=valid_client_id&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=openid&response_type=code&response_mode=query&nonce=1234&prompt=consent&code_challenge=yyhvlwTA3oVJcnTpkLV70DjqXb794Ar5Sgth12qbRsM&code_challenge_method=S256&provider_hint=google&login_hint=user%40example.com&domain_hint=example.com', $url); } - public function testGenerateLoginUrlMissingClientId() + public function testGenerateLoginUrlMissingClientId(): void { $_GET = [ 'provider_hint' => 'google', @@ -98,7 +98,7 @@ public function testGenerateLoginUrlMissingClientId() $this->login->generateLoginUrl(); } - public function testGenerateLoginUrlMissingRedirectURI() + public function testGenerateLoginUrlMissingRedirectURI(): void { $_GET = [ 'provider_hint' => 'google', diff --git a/tests/HelloClientTest.php b/tests/HelloClientTest.php index efd3a36..816b6ba 100644 --- a/tests/HelloClientTest.php +++ b/tests/HelloClientTest.php @@ -40,7 +40,7 @@ protected function setUp(): void $this->pageRendererMock->method('renderErrorPage')->willReturn("error_page"); } - public function testRouteHandlesAuth() + public function testRouteHandlesAuth(): void { // Simulate $_GET parameters $_GET = ['op' => 'auth']; @@ -61,7 +61,7 @@ public function testRouteHandlesAuth() $this->assertSame('auth_response', $result); } - public function testRouteHandlesCallback() + public function testRouteHandlesCallback(): void { // Simulate $_GET parameters $_GET = ['code' => 'callback_code']; @@ -88,7 +88,7 @@ public function testRouteHandlesCallback() $this->assertSame('/dashboard', $result); } - public function testRouteHandlesCallbackException() + public function testRouteHandlesCallbackException(): void { // Simulate $_GET parameters $_GET = ['code' => 'callback_code']; diff --git a/tests/HelloRequest/HelloRequestTest.php b/tests/HelloRequest/HelloRequestTest.php index e8522d9..365085d 100644 --- a/tests/HelloRequest/HelloRequestTest.php +++ b/tests/HelloRequest/HelloRequestTest.php @@ -14,26 +14,26 @@ protected function setUp(): void $this->request = new HelloRequest(); } - public function testFetchReturnsGetParameter() + public function testFetchReturnsGetParameter(): void { $_GET['test'] = 'value'; $this->assertSame('value', $this->request->fetch('test')); } - public function testFetchReturnsPostParameterIfGetNotSet() + public function testFetchReturnsPostParameterIfGetNotSet(): void { unset($_GET['test']); $_POST['test'] = 'value'; $this->assertSame('value', $this->request->fetch('test')); } - public function testFetchReturnsDefaultIfNeitherGetNorPostIsSet() + public function testFetchReturnsDefaultIfNeitherGetNorPostIsSet(): void { unset($_GET['test'], $_POST['test']); $this->assertSame('default', $this->request->fetch('test', 'default')); } - public function testFetchMultipleReturnsCorrectValues() + public function testFetchMultipleReturnsCorrectValues(): void { $_GET = ['key1' => 'value1']; $_POST = ['key2' => 'value2']; @@ -47,28 +47,28 @@ public function testFetchMultipleReturnsCorrectValues() ], $result); } - public function testFetchHeaderReturnsHeaderValue() + public function testFetchHeaderReturnsHeaderValue(): void { $_SERVER['HTTP_TEST_HEADER'] = 'HeaderValue'; $this->assertSame('HeaderValue', $this->request->fetchHeader('Test-Header')); } - public function testFetchHeaderReturnsDefaultIfHeaderNotSet() + public function testFetchHeaderReturnsDefaultIfHeaderNotSet(): void { unset($_SERVER['HTTP_TEST_HEADER']); $this->assertSame('default', $this->request->fetchHeader('Test-Header', 'default')); } - public function testGetCookieReturnsCookieValue() + public function testGetCookieReturnsCookieValue(): void { $_COOKIE['test_cookie'] = 'cookie_value'; $this->assertSame('cookie_value', $this->request->getCookie('test_cookie')); } - public function testGetCookieReturnsNullIfCookieNotSet() + public function testGetCookieReturnsNullIfCookieNotSet(): void { unset($_COOKIE['test_cookie']); diff --git a/tests/HelloResponse/HelloResponseTest.php b/tests/HelloResponse/HelloResponseTest.php index b26e714..e999eab 100644 --- a/tests/HelloResponse/HelloResponseTest.php +++ b/tests/HelloResponse/HelloResponseTest.php @@ -17,7 +17,7 @@ protected function setUp(): void $this->response = new HelloResponse(); } - public function testSetHeader() + public function testSetHeader(): void { $headerMock = $this->getFunctionMock('HelloCoop\HelloResponse', 'header'); $headerMock->expects($this->once()) @@ -26,7 +26,7 @@ public function testSetHeader() $this->response->setHeader('Content-Type', 'application/json'); } - public function testSetHeaderWithArrayValue() + public function testSetHeaderWithArrayValue(): void { $headerMock = $this->getFunctionMock('HelloCoop\HelloResponse', 'header'); $headerMock->expects($this->once()) @@ -35,7 +35,7 @@ public function testSetHeaderWithArrayValue() $this->response->setHeader('X-Custom-Header', ['value1', 'value2']); } - public function testSetCookie() + public function testSetCookie(): void { $setCookieMock = $this->getFunctionMock('HelloCoop\HelloResponse', 'setcookie'); $setCookieMock->expects($this->once()) @@ -55,7 +55,7 @@ public function testSetCookie() $this->response->setCookie('test_cookie', 'test_value'); } - public function testDeleteCookie() + public function testDeleteCookie(): void { $setCookieMock = $this->getFunctionMock('HelloCoop\HelloResponse', 'setcookie'); $setCookieMock->expects($this->once()) @@ -70,7 +70,7 @@ public function testDeleteCookie() $this->response->deleteCookie('delete_cookie'); } - public function testRedirect() + public function testRedirect(): void { // Mock the header function $headerMock = $this->getFunctionMock('HelloCoop\HelloResponse', 'header'); diff --git a/tests/Lib/AuthHelperTest.php b/tests/Lib/AuthHelperTest.php index f56a156..f40c814 100644 --- a/tests/Lib/AuthHelperTest.php +++ b/tests/Lib/AuthHelperTest.php @@ -19,7 +19,7 @@ protected function setUp(): void $this->authHelper = new AuthHelper($this->pkceMock); } - public function testCreateAuthRequestSuccess() + public function testCreateAuthRequestSuccess(): void { $this->pkceMock->method('generate')->willReturn([ 'code_challenge' => 'test-challenge', @@ -39,7 +39,7 @@ public function testCreateAuthRequestSuccess() $this->assertEquals('test-verifier', $result['code_verifier']); } - public function testMissingClientIdThrowsException() + public function testMissingClientIdThrowsException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('client_id is required in the authorization request.'); @@ -49,7 +49,7 @@ public function testMissingClientIdThrowsException() ]); } - public function testInvalidScopeThrowsException() + public function testInvalidScopeThrowsException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('One or more passed scopes are invalid.'); @@ -61,7 +61,7 @@ public function testInvalidScopeThrowsException() ]); } - public function testAddDefaultsToScopes() + public function testAddDefaultsToScopes(): void { $config = [ 'client_id' => 'test-client-id', diff --git a/tests/Lib/AuthTest.php b/tests/Lib/AuthTest.php index 12f9e96..dfe1ca3 100644 --- a/tests/Lib/AuthTest.php +++ b/tests/Lib/AuthTest.php @@ -6,7 +6,6 @@ use HelloCoop\Lib\Auth; use HelloCoop\Type\Auth as AuthType; use HelloCoop\Tests\Traits\ServiceMocksTrait; -use Exception; class AuthTest extends TestCase { @@ -24,7 +23,7 @@ protected function setUp(): void $this->configMock, ); } - public function testSaveAuthCookieSuccess() + public function testSaveAuthCookieSuccess(): void { $authMock = AuthType::fromArray([ 'isLoggedIn' => true, diff --git a/tests/Lib/PKCETest.php b/tests/Lib/PKCETest.php index 4e58eb9..4368090 100644 --- a/tests/Lib/PKCETest.php +++ b/tests/Lib/PKCETest.php @@ -17,7 +17,7 @@ protected function setUp(): void } /** @test */ - public function testGeneratesAVerifierOfCorrectLength() + public function testGeneratesAVerifierOfCorrectLength(): void { // Test the default length of the verifier $verifier = $this->pkce->generateVerifier(); @@ -30,7 +30,7 @@ public function testGeneratesAVerifierOfCorrectLength() } /** @test */ - public function testGeneratesAValidCodeChallenge() + public function testGeneratesAValidCodeChallenge(): void { // Generate a verifier and its corresponding challenge $verifier = $this->pkce->generateVerifier(); @@ -42,7 +42,7 @@ public function testGeneratesAValidCodeChallenge() } /** @test */ - public function testGeneratesPkceChallengePair() + public function testGeneratesPkceChallengePair(): void { $pkcePair = $this->pkce->generatePkce(); @@ -55,7 +55,7 @@ public function testGeneratesPkceChallengePair() } /** @test */ - public function testVerifiesTheCorrectChallenge() + public function testVerifiesTheCorrectChallenge(): void { // Generate a verifier and a challenge pair $pkcePair = $this->pkce->generatePkce(); @@ -71,7 +71,7 @@ public function testVerifiesTheCorrectChallenge() } /** @test */ - public function testGeneratesACodeVerifierAndChallengePair() + public function testGeneratesACodeVerifierAndChallengePair(): void { // Generate the code verifier and challenge pair $pkcePair = $this->pkce->generate(); diff --git a/tests/Lib/TokenParserTest.php b/tests/Lib/TokenParserTest.php index 695facf..ed6f304 100644 --- a/tests/Lib/TokenParserTest.php +++ b/tests/Lib/TokenParserTest.php @@ -14,7 +14,7 @@ protected function setUp(): void // Initialize the PKCE instance here $this->tokenParser = new TokenParser(); } - public function testParseTokenSuccess() + public function testParseTokenSuccess(): void { $token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjoxNjU0MjA4ODAwfQ.sflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'; @@ -28,7 +28,7 @@ public function testParseTokenSuccess() $this->assertArrayHasKey('exp', $result['payload']); } - public function testParseTokenInvalidJson() + public function testParseTokenInvalidJson(): void { $invalidToken = 'invalid.token.format'; @@ -38,7 +38,7 @@ public function testParseTokenInvalidJson() $this->tokenParser->parseToken($invalidToken); } - public function testParseTokenInvalidFormat() + public function testParseTokenInvalidFormat(): void { $invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'; diff --git a/tests/Type/AuthCookieTest.php b/tests/Type/AuthCookieTest.php index 7846e97..6feaa77 100644 --- a/tests/Type/AuthCookieTest.php +++ b/tests/Type/AuthCookieTest.php @@ -8,7 +8,7 @@ class AuthCookieTest extends TestCase { - public function testConstructorInitializesProperties() + public function testConstructorInitializesProperties(): void { $sub = 'user123'; $iat = time(); @@ -19,7 +19,7 @@ public function testConstructorInitializesProperties() $this->assertSame($iat, $authCookie->iat); } - public function testSetAndGetExtraProperty() + public function testSetAndGetExtraProperty(): void { $authCookie = new AuthCookie('user123', time()); @@ -31,7 +31,7 @@ public function testSetAndGetExtraProperty() $this->assertNull($authCookie->getExtraProperty('nonexistent_key')); } - public function testFromArrayCreatesInstanceWithValidData() + public function testFromArrayCreatesInstanceWithValidData(): void { $data = [ 'sub' => 'user123', @@ -48,7 +48,7 @@ public function testFromArrayCreatesInstanceWithValidData() $this->assertSame(456, $authCookie->getExtraProperty('custom2')); } - public function testFromArrayThrowsExceptionForMissingKeys() + public function testFromArrayThrowsExceptionForMissingKeys(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing required keys "sub" or "iat".'); @@ -56,4 +56,4 @@ public function testFromArrayThrowsExceptionForMissingKeys() $data = ['sub' => 'user123']; // Missing 'iat' AuthCookie::fromArray($data); } -} \ No newline at end of file +} diff --git a/tests/Type/AuthTest.php b/tests/Type/AuthTest.php index 2db3e30..8d480d7 100644 --- a/tests/Type/AuthTest.php +++ b/tests/Type/AuthTest.php @@ -8,11 +8,11 @@ class AuthTest extends TestCase { - public function testConstructorInitializesProperties() + public function testConstructorInitializesProperties(): void { $authCookie = new AuthCookie('user123', time()); $authCookie->setExtraProperty('role', 'admin'); - + $auth = new Auth(true, $authCookie, 'token123'); $this->assertTrue($auth->isLoggedIn); @@ -20,7 +20,7 @@ public function testConstructorInitializesProperties() $this->assertSame('token123', $auth->cookieToken); } - public function testConstructorWithNullValues() + public function testConstructorWithNullValues(): void { $auth = new Auth(false); @@ -29,7 +29,7 @@ public function testConstructorWithNullValues() $this->assertNull($auth->cookieToken); } - public function testAuthCookieProperties() + public function testAuthCookieProperties(): void { $authCookie = new AuthCookie('user123', time()); $authCookie->setExtraProperty('role', 'admin'); @@ -40,7 +40,7 @@ public function testAuthCookieProperties() $this->assertSame('admin', $auth->authCookie->getExtraProperty('role')); } - public function testAuthWithoutCookieToken() + public function testAuthWithoutCookieToken(): void { $auth = new Auth(true); diff --git a/tests/Type/OIDCTest.php b/tests/Type/OIDCTest.php index ca95b96..26c1b17 100644 --- a/tests/Type/OIDCTest.php +++ b/tests/Type/OIDCTest.php @@ -5,8 +5,10 @@ use HelloCoop\Type\OIDC; use PHPUnit\Framework\TestCase; -class OIDCTest extends TestCase { - public function testFromArrayValidData(): void { +class OIDCTest extends TestCase +{ + public function testFromArrayValidData(): void + { $data = [ 'code_verifier' => 'test_verifier', 'nonce' => 'test_nonce', @@ -23,7 +25,8 @@ public function testFromArrayValidData(): void { $this->assertEquals('/home', $oidc->targetUri); } - public function testFromArrayMissingKeys(): void { + public function testFromArrayMissingKeys(): void + { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Missing code_verifier'); @@ -36,7 +39,8 @@ public function testFromArrayMissingKeys(): void { OIDC::fromArray($data); } - public function testToArray(): void { + public function testToArray(): void + { $oidc = new OIDC('test_verifier', 'test_nonce', 'https://example.com/callback', '/home'); $expected = [ diff --git a/tests/Utils/QueryParamFetcherTest.php b/tests/Utils/QueryParamFetcherTest.php index a4249cb..230594d 100644 --- a/tests/Utils/QueryParamFetcherTest.php +++ b/tests/Utils/QueryParamFetcherTest.php @@ -7,6 +7,7 @@ class QueryParamFetcherTest extends TestCase { + protected array $originalGet; protected function setUp(): void { // Backup the original $_GET superglobal @@ -19,7 +20,7 @@ protected function tearDown(): void $_GET = $this->originalGet; } - public function testFetchWithExistingKeys() + public function testFetchWithExistingKeys(): void { $_GET = [ 'key1' => 'value1', @@ -34,7 +35,7 @@ public function testFetchWithExistingKeys() ], $result); } - public function testFetchWithNonExistentKeys() + public function testFetchWithNonExistentKeys(): void { $_GET = [ 'key1' => 'value1', @@ -48,7 +49,7 @@ public function testFetchWithNonExistentKeys() ], $result); } - public function testFetchWithMixedKeys() + public function testFetchWithMixedKeys(): void { $_GET = [ 'key1' => 'value1',