From 8e4b9114086301df54075a1672e41853f0e8c9a1 Mon Sep 17 00:00:00 2001 From: Daniel Burger <48986191+danielburger1337@users.noreply.github.com> Date: Sat, 24 Feb 2024 05:55:45 +0100 Subject: [PATCH 1/2] Upgrade to PHPUnit 11 --- composer.json | 2 +- phpunit.xml.dist | 22 +++++++++++----------- tests/SHA3ShakeTest.php | 25 ++++++++++++------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index aaeadd8..46347a1 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require-dev": { "phpstan/phpstan": "^1.4", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^11.0" }, "config": { "sort-packages": true diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e6898f1..741cd20 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,21 @@ - - - - ./ - - - ./src - - - + + + + + src/ + + + - ./tests/ + tests/ diff --git a/tests/SHA3ShakeTest.php b/tests/SHA3ShakeTest.php index 9bc0da7..3f48505 100644 --- a/tests/SHA3ShakeTest.php +++ b/tests/SHA3ShakeTest.php @@ -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); @@ -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); @@ -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); @@ -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 [ [ @@ -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', From 5c31835f016c47ac65ac51a9188beb4fa6da589b Mon Sep 17 00:00:00 2001 From: Daniel Burger <48986191+danielburger1337@users.noreply.github.com> Date: Sat, 24 Feb 2024 05:58:12 +0100 Subject: [PATCH 2/2] Update PHPUnit workflow --- .github/workflows/phpunit.yml | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 084c4a9..5fd77b3 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,29 +16,10 @@ 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 @@ -46,10 +27,8 @@ jobs: 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