From dcc82ec43e5b58c5ac27259780b237f30759029f Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Tue, 9 Apr 2024 21:37:41 +0200 Subject: [PATCH] Remove deprecated checks and update test dependencies The deprecated checks in the UrlKeySetFactory are removed. Slow test detection is added to PHPUnit tests with the Ergebnis\PHPUnit\SlowTestDetector dependency. Several method parameters in tests are also updated for clarity and to reduce cognitive load in parsing the test setup and assertions. --- composer.json | 6 ++ phpstan-baseline.neon | 62 +------------------ phpunit.xml.dist | 6 ++ .../JoseFrameworkExtension.php | 3 - .../KeyManagement/UrlKeySetFactory.php | 16 ----- .../Console/KeySetCreationCommandTest.php | 2 + .../KeyManagement/JWKFactoryTest.php | 2 + 7 files changed, 17 insertions(+), 80 deletions(-) diff --git a/composer.json b/composer.json index d996be92..4bb580d4 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,7 @@ "ext-gmp": "*", "ext-sodium": "*", "ekino/phpstan-banned-code": "^1.0", + "ergebnis/phpunit-slow-test-detector": "^2.14", "infection/infection": "^0.28", "matthiasnoback/symfony-config-test": "^5.0", "paragonie/sodium_compat": "^1.20", @@ -74,13 +75,18 @@ "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.8", "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-doctrine": "^1.3", "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-strict-rules": "^1.4", + "phpstan/phpstan-symfony": "^1.3", "phpunit/phpunit": "^10.5.10|^11.0", "qossmic/deptrac-shim": "^1.0", "rector/rector": "^1.0", "roave/security-advisories": "dev-latest", "spomky-labs/aes-key-wrap": "^7.0", + "staabm/phpstan-dba": "^0.2.79", + "staabm/phpstan-todo-by": "^0.1.25", + "struggle-for-php/sfp-phpstan-psr-log": "^0.20.0", "symfony/browser-kit": "^7.0", "symfony/clock": "^7.0", "symfony/finder": "^7.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f627753e..2c2287f1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -35,11 +35,6 @@ parameters: count: 1 path: src/Bundle/DependencyInjection/JoseFrameworkExtension.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\DependencyInjection\\\\JoseFrameworkExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/DependencyInjection/JoseFrameworkExtension.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" count: 1 @@ -890,16 +885,6 @@ parameters: count: 1 path: src/Bundle/Resources/config/Algorithms/signature_experimental.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWEEncoder\\:\\:decode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWEEncoder.php - - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWEEncoder\\:\\:encode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWEEncoder.php - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWEEncoder\\:\\:getRecipientIndex\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -915,26 +900,6 @@ parameters: count: 1 path: src/Bundle/Serializer/JWEEncoder.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWESerializer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWESerializer.php - - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWESerializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWESerializer.php - - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSEncoder\\:\\:decode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWSEncoder.php - - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSEncoder\\:\\:encode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWSEncoder.php - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSEncoder\\:\\:getSignatureIndex\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -950,16 +915,6 @@ parameters: count: 1 path: src/Bundle/Serializer/JWSEncoder.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSSerializer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWSSerializer.php - - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSSerializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWSSerializer.php - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Services\\\\ClaimCheckerManager\\:\\:check\\(\\) has parameter \\$claims with no value type specified in iterable type array\\.$#" count: 1 @@ -1840,11 +1795,6 @@ parameters: count: 1 path: src/Library/KeyManagement/KeyConverter/ECKey.php - - - message: "#^Access to an undefined property Jose\\\\Component\\\\KeyManagement\\\\UrlKeySetFactory\\:\\:\\$requestFactory\\.$#" - count: 1 - path: src/Library/KeyManagement/UrlKeySetFactory.php - - message: "#^Call to an undefined method Jose\\\\Component\\\\KeyManagement\\\\UrlKeySetFactory\\:\\:sendPsrRequest\\(\\)\\.$#" count: 1 @@ -1855,14 +1805,9 @@ parameters: count: 1 path: src/Library/KeyManagement/UrlKeySetFactory.php - - - message: "#^Class Psr\\\\Http\\\\Client\\\\ClientInterface not found\\.$#" - count: 3 - path: src/Library/KeyManagement/UrlKeySetFactory.php - - message: "#^Instanceof between Symfony\\\\Contracts\\\\HttpClient\\\\HttpClientInterface and Symfony\\\\Contracts\\\\HttpClient\\\\HttpClientInterface will always evaluate to true\\.$#" - count: 3 + count: 2 path: src/Library/KeyManagement/UrlKeySetFactory.php - @@ -1870,11 +1815,6 @@ parameters: count: 1 path: src/Library/KeyManagement/UrlKeySetFactory.php - - - message: "#^Result of && is always false\\.$#" - count: 1 - path: src/Library/KeyManagement/UrlKeySetFactory.php - - message: "#^Parameter \\#2 \\$recipient of method Jose\\\\Component\\\\NestedToken\\\\NestedTokenLoader\\:\\:checkContentTypeHeader\\(\\) expects int, int\\|null given\\.$#" count: 1 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5e5d862e..a3f1bf06 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -32,4 +32,10 @@ ./src + + + + + + diff --git a/src/Bundle/DependencyInjection/JoseFrameworkExtension.php b/src/Bundle/DependencyInjection/JoseFrameworkExtension.php index a0d8f6b8..14e939db 100644 --- a/src/Bundle/DependencyInjection/JoseFrameworkExtension.php +++ b/src/Bundle/DependencyInjection/JoseFrameworkExtension.php @@ -29,9 +29,6 @@ public function getAlias(): string return $this->alias; } - /** - * @param array $configs - */ #[Override] public function load(array $configs, ContainerBuilder $container): void { diff --git a/src/Library/KeyManagement/UrlKeySetFactory.php b/src/Library/KeyManagement/UrlKeySetFactory.php index 3a167104..9e38b436 100644 --- a/src/Library/KeyManagement/UrlKeySetFactory.php +++ b/src/Library/KeyManagement/UrlKeySetFactory.php @@ -23,22 +23,6 @@ abstract class UrlKeySetFactory public function __construct( private readonly HttpClientInterface $client, ) { - if ($this->client instanceof ClientInterface) { - trigger_deprecation( - 'web-token/jwt-library', - '3.3', - 'Using "%s" with an instance of "%s" is deprecated, use "%s" instead.', - self::class, - ClientInterface::class, - HttpClientInterface::class - ); - } - if (! $this->client instanceof HttpClientInterface && $this->requestFactory === null) { - throw new RuntimeException(sprintf( - 'The request factory must be provided when using an instance of "%s" as client.', - ClientInterface::class - )); - } $this->cacheItemPool = new NullAdapter(); } diff --git a/tests/Component/Console/KeySetCreationCommandTest.php b/tests/Component/Console/KeySetCreationCommandTest.php index 76427db4..f585dd9d 100644 --- a/tests/Component/Console/KeySetCreationCommandTest.php +++ b/tests/Component/Console/KeySetCreationCommandTest.php @@ -4,6 +4,7 @@ namespace Jose\Tests\Component\Console; +use Ergebnis\PHPUnit\SlowTestDetector\Attribute\MaximumDuration; use InvalidArgumentException; use Jose\Component\Console\EcKeysetGeneratorCommand; use Jose\Component\Console\OctKeysetGeneratorCommand; @@ -158,6 +159,7 @@ public function iCannotCreateAnRsaKeySetWithoutKeySetSize(): void } #[Test] + #[MaximumDuration(500)] public function iCanCreateAnRsaKeySet(): void { $input = new ArrayInput([ diff --git a/tests/Component/KeyManagement/JWKFactoryTest.php b/tests/Component/KeyManagement/JWKFactoryTest.php index 0ca4f796..80cb6cf3 100644 --- a/tests/Component/KeyManagement/JWKFactoryTest.php +++ b/tests/Component/KeyManagement/JWKFactoryTest.php @@ -4,6 +4,7 @@ namespace Jose\Tests\Component\KeyManagement; +use Ergebnis\PHPUnit\SlowTestDetector\Attribute\MaximumDuration; use Jose\Component\Core\Util\Base64UrlSafe; use Jose\Component\Core\Util\ECKey; use Jose\Component\KeyManagement\JWKFactory; @@ -231,6 +232,7 @@ public function createFromValues(): void #[DataProvider('dataKeys')] #[Test] + #[MaximumDuration(500)] public function loadKeyPEMEncoded(string $filename, array $expectedValues): void { $jwk = JWKFactory::createFromKeyFile($filename);