Skip to content

Commit

Permalink
Merge pull request #2 from danielburger1337/phpunit11
Browse files Browse the repository at this point in the history
Upgrade to PHPUnit 11
  • Loading branch information
danielburger1337 authored Feb 24, 2024
2 parents 355320c + 5c31835 commit 17affa2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 49 deletions.
27 changes: 3 additions & 24 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,19 @@ jobs:
operating-system: [ubuntu-latest]
php-versions: ["8.1", "8.2"]

name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

env:
PHP_EXTENSIONS: mbstring
key: cache-v1
name: PHPUnit with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}

steps:
- uses: actions/checkout@v3

- name: Setup Cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.PHP_EXTENSIONS }}
key: ${{ env.key }}

- name: Cache PHP extensions
uses: actions/cache@v3
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.PHP_EXTENSIONS }}

###> Composer ###
- name: Install Composer packages
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
###< Composer ###

- name: Execute tests via PHPUnit
- name: Run PHPUnit
run: $GITHUB_WORKSPACE/vendor/bin/phpunit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"require-dev": {
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^11.0"
},
"config": {
"sort-packages": true
Expand Down
22 changes: 11 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./src</directory>
</exclude>
</coverage>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
colors="true" bootstrap="vendor/autoload.php">
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
</php>

<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>

<testsuites>
<testsuite name="SHA3-SHAKE Test Suite">
<directory>./tests/</directory>
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
25 changes: 12 additions & 13 deletions tests/SHA3ShakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace danielburger1337\SHA3Shake\Tests;

use danielburger1337\SHA3Shake\SHA3Shake;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class SHA3Test extends TestCase
#[CoversClass(SHA3Shake::class)]
class SHA3ShakeTest extends TestCase
{
/**
* Test that only even output lengths are accepted.
*/
#[Test]
public function testShakeOutputLength(): void
{
SHA3Shake::shake128('', 256);
Expand All @@ -22,9 +24,8 @@ public function testShakeOutputLength(): void
SHA3Shake::shake256('', 57);
}

/**
* @dataProvider shake128Provider
*/
#[Test]
#[DataProvider('shake128Provider')]
public function testShake128(string $string, int $outputLength, string $expected): void
{
$hash = SHA3Shake::shake128($string, $outputLength, false);
Expand All @@ -35,9 +36,8 @@ public function testShake128(string $string, int $outputLength, string $expected
$this->assertEquals(SHA3Shake::shake128($string, $outputLength, true), \hex2bin($expected));
}

/**
* @dataProvider shake256Provider
*/
#[Test]
#[DataProvider('shake256Provider')]
public function testShake256(string $string, int $outputLength, string $expected): void
{
$hash = SHA3Shake::shake256($string, $outputLength, false);
Expand All @@ -48,7 +48,7 @@ public function testShake256(string $string, int $outputLength, string $expected
$this->assertEquals(SHA3Shake::shake256($string, $outputLength, true), \hex2bin($expected));
}

protected function shake128Provider(): array
public static function shake128Provider(): array
{
return [
[
Expand All @@ -60,11 +60,10 @@ protected function shake128Provider(): array
];
}

protected function shake256Provider(): array
public static function shake256Provider(): array
{
return [
[
// @see https://bitbucket.org/openid/connect/issues/1125
'YmJiZTAwYmYtMzgyOC00NzhkLTkyOTItNjJjNDM3MGYzOWIy9sFhvH8K_x8UIHj1osisS57f5DduL',
114,
'b01fd4ef68f26f45a0b57f13b15a2a2679ba083dbde56f607d20d1c648a50772c02fb4448bd258bad456fecd72138943f1c39f3197fcde08b8',
Expand Down

0 comments on commit 17affa2

Please sign in to comment.