Skip to content

Commit

Permalink
ci: use cobertura instead of clover and update phpunit (#13)
Browse files Browse the repository at this point in the history
* ci: use covertura coverage instead of clover

* ci: add coverage-badge
  • Loading branch information
Strobotti authored Apr 30, 2024
1 parent d06d2b8 commit 4ae5aa6
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: "${{ runner.os }}-${{ hashFiles('**/composer.lock') }}"
Expand All @@ -42,7 +42,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: "${{ runner.os }}-${{ hashFiles('**/composer.lock') }}"
Expand All @@ -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
20 changes: 20 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: "${{ runner.os }}-${{ hashFiles('**/composer.lock') }}"

- name: Install Composer
uses: php-actions/composer@v6

- name: Run PHPUnit
run: php -d xdebug.mode=coverage ./vendor/bin/phpunit

- name: Make Coverage Badge
uses: action-badges/[email protected]
with:
file-name: coverage.svg
badge-branch: gh-pages
coverage-file-name: tests/coverage.latest/coverage.xml
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Execute Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v3
Expand Down
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# php-jwk

[![Latest Stable Version](https://poser.pugx.org/strobotti/php-jwk/v/stable)](https://packagist.org/packages/strobotti/php-jwk)
![coverage](https://raw.githubusercontent.com/Strobotti/php-jwk/gh-pages/.badges/master/coverage.svg)
[![License](https://poser.pugx.org/strobotti/php-jwk/license)](https://packagist.org/packages/strobotti/php-jwk)

A small PHP library to handle JWKs (Json Web Keys)
Expand Down
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);
}
}
Loading

0 comments on commit 4ae5aa6

Please sign in to comment.