Skip to content

Commit

Permalink
ci: use covertura coverage instead of clover
Browse files Browse the repository at this point in the history
  • Loading branch information
Strobotti committed Apr 30, 2024
1 parent d06d2b8 commit f1eae72
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ composer.lock
composer.phar
vendor
coverage.xml
clover.xml
.php_cs.cache
.phpunit.cache
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"ext-xml": "*",
"phpunit/phpunit": "^10.0",
"friendsofphp/php-cs-fixer": "^2.16"
},
"scripts": {
Expand Down
23 changes: 14 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
bootstrap="vendor/autoload.php">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache">
<coverage>
<report>
<cobertura outputFile="tests/coverage.latest/coverage.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<logging/>
<source>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
</logging>
</include>
</source>
</phpunit>
14 changes: 7 additions & 7 deletions tests/Key/AbstractKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}

Expand Down
22 changes: 11 additions & 11 deletions tests/Key/RsaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -50,7 +50,7 @@ public function provideCreateFromJSON(): \Generator
}
EOT
];
}
}

public function testToString(): void
{
Expand All @@ -67,7 +67,7 @@ public function testToString(): void

$key = Rsa::createFromJSON($json);

static::assertSame($json, "{$key}");
$this->assertSame($json, "{$key}");
}

public function testSettersAndGetters(): void
Expand All @@ -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());
}
}
12 changes: 6 additions & 6 deletions tests/KeyConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('{
Expand All @@ -50,7 +50,7 @@ public function provideKeyToPem(): \Generator
-----END PUBLIC KEY-----
EOT
];
}
}

public function testUnsupportedKeyTypeRaisesException(): void
{
Expand All @@ -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)));
}
}
}
38 changes: 19 additions & 19 deletions tests/KeyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
];
}
}
6 changes: 3 additions & 3 deletions tests/KeySetFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +37,7 @@ public function testInvalidJsonReturnsEmptyKeySet(): void
$this->assertCount(0, $keySet);
}

public function provideCreateFromJSON(): \Generator
public static function provideCreateFromJSON(): \Generator
{
yield [
'input' => <<<'EOT'
Expand All @@ -63,5 +63,5 @@ public function provideCreateFromJSON(): \Generator
}
EOT
];
}
}
}
34 changes: 17 additions & 17 deletions tests/KeySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
{
Expand All @@ -34,8 +34,8 @@ public function provideCreateFromJSON(): \Generator
}
EOT;

yield [
'expected' => <<<'EOT'
yield [
'expected' => <<<'EOT'
{
"keys": [
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/Util/Base64UrlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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/',
Expand All @@ -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',
Expand Down

0 comments on commit f1eae72

Please sign in to comment.