diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2b55422..618a3b3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,4 +51,4 @@ jobs: uses: php-actions/composer@v6 - name: Run PHPUnit - run: vendor/bin/phpunit + run: php -d xdebug.mode=coverage ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index b5f31bd..54029c9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ composer.lock composer.phar vendor coverage.xml -clover.xml .php_cs.cache +.phpunit.cache diff --git a/composer.json b/composer.json index dbacaa2..de638ab 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ } }, "require-dev": { - "phpunit/phpunit": "^9.0", + "ext-xml": "*", + "phpunit/phpunit": "^10.0", "friendsofphp/php-cs-fixer": "^2.16" }, "scripts": { diff --git a/phpunit.xml b/phpunit.xml index 80dd7a5..9784b09 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,17 +1,22 @@ + + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + bootstrap="vendor/autoload.php" + cacheDirectory=".phpunit.cache"> + + + + + tests - - + + + ./src/ - - - - - + + diff --git a/tests/Key/AbstractKeyTest.php b/tests/Key/AbstractKeyTest.php index f3a61f5..5495f34 100644 --- a/tests/Key/AbstractKeyTest.php +++ b/tests/Key/AbstractKeyTest.php @@ -26,7 +26,7 @@ public function testCreateFromJSON(): void $key = AbstractKeyTest__AbstractKey__Mock::createFromJSON($json); - static::assertSame($json, "{$key}"); + $this->assertSame($json, "{$key}"); } public function testSettersAndGetters(): void @@ -38,17 +38,17 @@ public function testSettersAndGetters(): void ->setKeyId('asdf') ; - static::assertSame(KeyInterface::ALGORITHM_RS256, $key->getAlgorithm()); - static::assertSame(KeyInterface::PUBLIC_KEY_USE_SIGNATURE, $key->getPublicKeyUse()); - static::assertSame(KeyInterface::KEY_TYPE_RSA, $key->getKeyType()); - static::assertSame('asdf', $key->getKeyId()); + $this->assertSame(KeyInterface::ALGORITHM_RS256, $key->getAlgorithm()); + $this->assertSame(KeyInterface::PUBLIC_KEY_USE_SIGNATURE, $key->getPublicKeyUse()); + $this->assertSame(KeyInterface::KEY_TYPE_RSA, $key->getKeyType()); + $this->assertSame('asdf', $key->getKeyId()); // Test nullable fields $key->setKeyId(null); $key->setPublicKeyUse(null); - static::assertNull($key->getKeyId()); - static::assertNull($key->getPublicKeyUse()); + $this->assertNull($key->getKeyId()); + $this->assertNull($key->getPublicKeyUse()); } } diff --git a/tests/Key/RsaTest.php b/tests/Key/RsaTest.php index 1382f7c..253804f 100644 --- a/tests/Key/RsaTest.php +++ b/tests/Key/RsaTest.php @@ -19,15 +19,15 @@ public function testCreateFromJSON(array $expected, string $input): void { $key = Rsa::createFromJSON($input); - static::assertSame($expected['kty'], $key->getKeyType()); - static::assertSame($expected['kid'], $key->getKeyId()); - static::assertSame($expected['use'], $key->getPublicKeyUse()); - static::assertSame($expected['alg'], $key->getAlgorithm()); - static::assertSame($expected['n'], $key->getModulus()); - static::assertSame($expected['e'], $key->getExponent()); + $this->assertSame($expected['kty'], $key->getKeyType()); + $this->assertSame($expected['kid'], $key->getKeyId()); + $this->assertSame($expected['use'], $key->getPublicKeyUse()); + $this->assertSame($expected['alg'], $key->getAlgorithm()); + $this->assertSame($expected['n'], $key->getModulus()); + $this->assertSame($expected['e'], $key->getExponent()); } - public function provideCreateFromJSON(): \Generator + public static function provideCreateFromJSON(): \Generator { yield [ 'expected' => [ @@ -50,7 +50,7 @@ public function provideCreateFromJSON(): \Generator } EOT ]; - } +} public function testToString(): void { @@ -67,7 +67,7 @@ public function testToString(): void $key = Rsa::createFromJSON($json); - static::assertSame($json, "{$key}"); + $this->assertSame($json, "{$key}"); } public function testSettersAndGetters(): void @@ -80,7 +80,7 @@ public function testSettersAndGetters(): void ->setModulus($n) ; - static::assertSame($e, $key->getExponent()); - static::assertSame($n, $key->getModulus()); + $this->assertSame($e, $key->getExponent()); + $this->assertSame($n, $key->getModulus()); } } diff --git a/tests/KeyConverterTest.php b/tests/KeyConverterTest.php index c48beb0..5979635 100644 --- a/tests/KeyConverterTest.php +++ b/tests/KeyConverterTest.php @@ -21,13 +21,13 @@ final class KeyConverterTest extends TestCase public function testKeyToPem(KeyInterface $key, string $expected): void { $converter = new KeyConverter(); - static::assertSame( + $this->assertSame( \str_replace("\r", '', $expected), \str_replace("\r", '', $converter->keyToPem($key)) ); } - public function provideKeyToPem(): \Generator + public static function provideKeyToPem(): \Generator { yield [ 'key' => Rsa::createFromJSON('{ @@ -50,7 +50,7 @@ public function provideKeyToPem(): \Generator -----END PUBLIC KEY----- EOT ]; - } +} public function testUnsupportedKeyTypeRaisesException(): void { @@ -62,11 +62,11 @@ public function testUnsupportedKeyTypeRaisesException(): void try { $converter->keyToPem($key); - static::fail('converting an unsupported key to PEM should throw an exception'); + $this->fail('converting an unsupported key to PEM should throw an exception'); } catch (\InvalidArgumentException $e) { - static::assertTrue(true); + $this->assertTrue(true); } catch (\Throwable $e) { - static::fail(\sprintf('converting an unsupported key to PEM threw an unexpected exception %s', \get_class($e))); + $this->fail(\sprintf('converting an unsupported key to PEM threw an unexpected exception %s', \get_class($e))); } } } diff --git a/tests/KeyFactoryTest.php b/tests/KeyFactoryTest.php index 4372057..108739b 100644 --- a/tests/KeyFactoryTest.php +++ b/tests/KeyFactoryTest.php @@ -21,11 +21,11 @@ public function testCreateFromPem(string $pem, array $options, array $json, stri $factory = new KeyFactory(); $key = $factory->createFromPem($pem, $options); - static::assertInstanceOf($expectedInstance, $key); - static::assertSame($json, $key->jsonSerialize()); + $this->assertInstanceOf($expectedInstance, $key); + $this->assertSame($json, $key->jsonSerialize()); } - public function provideCreateFromPem(): \Generator + public static function provideCreateFromPem(): \Generator { yield [ 'pem' => <<<'EOT' @@ -40,20 +40,20 @@ public function provideCreateFromPem(): \Generator -----END PUBLIC KEY----- EOT , - 'options' => [ - 'use' => 'sig', - 'alg' => 'RS256', - 'kid' => 'eXaunmL', - ], - 'json' => [ - 'kty' => 'RSA', - 'use' => 'sig', - 'alg' => 'RS256', - 'kid' => 'eXaunmL', - 'n' => '4dGQ7bQK8LgILOdLsYzfZjkEAoQeVC_aqyc8GC6RX7dq_KvRAQAWPvkam8VQv4GK5T4ogklEKEvj5ISBamdDNq1n52TpxQwI2EqxSk7I9fKPKhRt4F8-2yETlYvye-2s6NeWJim0KBtOVrk0gWvEDgd6WOqJl_yt5WBISvILNyVg1qAAM8JeX6dRPosahRVDjA52G2X-Tip84wqwyRpUlq2ybzcLh3zyhCitBOebiRWDQfG26EH9lTlJhll-p_Dg8vAXxJLIJ4SNLcqgFeZe4OfHLgdzMvxXZJnPp_VgmkcpUdRotazKZumj6dBPcXI_XID4Z4Z3OM1KrZPJNdUhxw', - 'e' => 'AQAB', - ], - 'expectedInstance' => Rsa::class, - ]; - } + 'options' => [ + 'use' => 'sig', + 'alg' => 'RS256', + 'kid' => 'eXaunmL', + ], + 'json' => [ + 'kty' => 'RSA', + 'use' => 'sig', + 'alg' => 'RS256', + 'kid' => 'eXaunmL', + 'n' => '4dGQ7bQK8LgILOdLsYzfZjkEAoQeVC_aqyc8GC6RX7dq_KvRAQAWPvkam8VQv4GK5T4ogklEKEvj5ISBamdDNq1n52TpxQwI2EqxSk7I9fKPKhRt4F8-2yETlYvye-2s6NeWJim0KBtOVrk0gWvEDgd6WOqJl_yt5WBISvILNyVg1qAAM8JeX6dRPosahRVDjA52G2X-Tip84wqwyRpUlq2ybzcLh3zyhCitBOebiRWDQfG26EH9lTlJhll-p_Dg8vAXxJLIJ4SNLcqgFeZe4OfHLgdzMvxXZJnPp_VgmkcpUdRotazKZumj6dBPcXI_XID4Z4Z3OM1KrZPJNdUhxw', + 'e' => 'AQAB', + ], + 'expectedInstance' => Rsa::class, + ]; +} } diff --git a/tests/KeySetFactoryTest.php b/tests/KeySetFactoryTest.php index a9eb2fa..953b4a6 100644 --- a/tests/KeySetFactoryTest.php +++ b/tests/KeySetFactoryTest.php @@ -23,7 +23,7 @@ public function testCreateFromJSON(string $input): void $keys = $factory->createFromJSON($input); $json = $keys->jsonSerialize(); - static::assertSame(\json_decode($input, true), $json); + $this->assertSame(\json_decode($input, true), $json); } public function testInvalidJsonReturnsEmptyKeySet(): void @@ -37,7 +37,7 @@ public function testInvalidJsonReturnsEmptyKeySet(): void $this->assertCount(0, $keySet); } - public function provideCreateFromJSON(): \Generator + public static function provideCreateFromJSON(): \Generator { yield [ 'input' => <<<'EOT' @@ -63,5 +63,5 @@ public function provideCreateFromJSON(): \Generator } EOT ]; - } +} } diff --git a/tests/KeySetTest.php b/tests/KeySetTest.php index 2729ed5..d56c182 100644 --- a/tests/KeySetTest.php +++ b/tests/KeySetTest.php @@ -18,10 +18,10 @@ final class KeySetTest extends TestCase */ public function testToString(string $expected, KeySet $keySet): void { - static::assertSame($expected, "{$keySet}"); + $this->assertSame($expected, "{$keySet}"); } - public function provideCreateFromJSON(): \Generator + public static function provideCreateFromJSON(): \Generator { $keyJson = <<<'EOT' { @@ -34,8 +34,8 @@ public function provideCreateFromJSON(): \Generator } EOT; - yield [ - 'expected' => <<<'EOT' + yield [ + 'expected' => <<<'EOT' { "keys": [ { @@ -50,10 +50,10 @@ public function provideCreateFromJSON(): \Generator } EOT , - 'keySet' => (new KeySet()) - ->addKey(Rsa::createFromJSON($keyJson)), - ]; - } + 'keySet' => (new KeySet()) + ->addKey(Rsa::createFromJSON($keyJson)), + ]; +} public function testAddKeyThrowsErrorOnDuplicateKid(): void { @@ -93,21 +93,21 @@ public function testGetKeyById(): void $keySet = new KeySet(); $keySet->addKey($key); - static::assertSame($key, $keySet->getKeyById('86D88Kf')); + $this->assertSame($key, $keySet->getKeyById('86D88Kf')); - static::assertNull($keySet->getKeyById('asdf')); + $this->assertNull($keySet->getKeyById('asdf')); } public function testCountable(): void { $keyset = new KeySet(); - static::assertCount(0, $keyset); + $this->assertCount(0, $keyset); $keyset->addKey(new Rsa()); - static::assertCount(1, $keyset); + $this->assertCount(1, $keyset); $keyset->addKey(new Rsa()); - static::assertCount(2, $keyset); + $this->assertCount(2, $keyset); } public function testIteratorAggregate(): void @@ -120,19 +120,19 @@ public function testIteratorAggregate(): void ++$count; } - static::assertSame(0, $count); + $this->assertSame(0, $count); $keyset->addKey(new Rsa()); $keyset->addKey(new Rsa()); $keyset->addKey(new Rsa()); foreach ($keyset as $index => $key) { - static::assertInstanceOf(Rsa::class, $key); - static::assertSame($index, $count); + $this->assertInstanceOf(Rsa::class, $key); + $this->assertSame($index, $count); ++$count; } - static::assertSame(3, $count); + $this->assertSame(3, $count); } } diff --git a/tests/Util/Base64UrlConverterTest.php b/tests/Util/Base64UrlConverterTest.php index 4e5a022..d653db5 100644 --- a/tests/Util/Base64UrlConverterTest.php +++ b/tests/Util/Base64UrlConverterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Strobotti\JWK\Key\Tests; +namespace Strobotti\JWK\Tests\Util; use PHPUnit\Framework\TestCase; use Strobotti\JWK\Util\Base64UrlConverter; @@ -19,10 +19,10 @@ public function testDecode(string $expected, string $input): void { $converter = new Base64UrlConverter(); - static::assertSame($expected, $converter->decode($input)); + $this->assertSame($expected, $converter->decode($input)); } - public function provideDecode(): \Generator + public static function provideDecode(): \Generator { yield [ 'expected' => '/a+quick+brown+fox/jumped-over/the_lazy_dog/', @@ -40,7 +40,7 @@ public function testEncode(string $expected, string $input): void static::assertSame($expected, $converter->encode($input)); } - public function provideEncode(): \Generator + public static function provideEncode(): \Generator { yield [ 'expected' => 'L2ErcXVpY2srYnJvd24rZm94L2p1bXBlZC1vdmVyL3RoZV9sYXp5X2RvZy8',