From 8055545ce02accd96b950d31ba2123e9cf19eea3 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Thu, 16 Apr 2026 11:40:25 +0200 Subject: [PATCH 1/2] PHPunit 12.x support --- composer.json | 2 +- tests/HashidsTest.php | 23 ++++++++++++----------- tests/MathTest.php | 15 ++++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 4842a5a..1c38b76 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^10.5|^11.2" + "phpunit/phpunit": "^10.5|^11.2|^12.0" }, "suggest": { "ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).", diff --git a/tests/HashidsTest.php b/tests/HashidsTest.php index 268e402..c0c0499 100644 --- a/tests/HashidsTest.php +++ b/tests/HashidsTest.php @@ -13,6 +13,7 @@ use Hashids\Hashids; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class HashidsTest extends TestCase @@ -64,7 +65,7 @@ public static function alphabetProvider() ]; } - /** @dataProvider alphabetProvider */ + #[DataProvider('alphabetProvider')] public function testAlphabet($alphabets) { $numbers = [1, 2, 3]; @@ -88,7 +89,7 @@ public static function saltProvider() ]; } - /** @dataProvider saltProvider */ + #[DataProvider('saltProvider')] public function testSalt($salts) { $numbers = [1, 2, 3]; @@ -111,7 +112,7 @@ public static function minLengthProvider() ]; } - /** @dataProvider minLengthProvider */ + #[DataProvider('minLengthProvider')] public function testMinLength($lengths) { $numbers = [1, 2, 3]; @@ -133,7 +134,7 @@ public static function encodeTypesProvider() ]; } - /** @dataProvider encodeTypesProvider */ + #[DataProvider('encodeTypesProvider')] public function testEncodeTypes($params) { $numbers = [1, 2, 3]; @@ -169,7 +170,7 @@ public static function defaultParamsProvider() ]; } - /** @dataProvider defaultParamsProvider */ + #[DataProvider('defaultParamsProvider')] public function testDefaultParams($id, $numbers) { $hashids = new Hashids(); @@ -202,7 +203,7 @@ public static function customParamsProvider() ]; } - /** @dataProvider customParamsProvider */ + #[DataProvider('customParamsProvider')] public function testCustomParams($id, $numbers) { $minLength = 30; @@ -232,7 +233,7 @@ public static function defaultParamsHexProvider() ]; } - /** @dataProvider defaultParamsHexProvider */ + #[DataProvider('defaultParamsHexProvider')] public function testDefaultParamsHex($id, $hex) { $hashids = new Hashids(); @@ -258,7 +259,7 @@ public static function customParamsHexProvider() ]; } - /** @dataProvider customParamsHexProvider */ + #[DataProvider('customParamsHexProvider')] public function testCustomParamsHex($id, $hex) { $minLength = 30; @@ -283,7 +284,7 @@ public static function bigNumberDataProvider() ]; } - /** @dataProvider bigNumberDataProvider */ + #[DataProvider('bigNumberDataProvider')] public function testBigNumberEncode($number, $hash) { $hashids = new Hashids('this is my salt'); @@ -291,7 +292,7 @@ public function testBigNumberEncode($number, $hash) $this->assertEquals($hash, $encoded); } - /** @dataProvider bigNumberDataProvider */ + #[DataProvider('bigNumberDataProvider')] public function testBigNumberDecode($number, $hash) { $hashids = new Hashids('this is my salt'); @@ -309,7 +310,7 @@ public static function jsHashidsDataProvider() ]; } - /** @dataProvider jsHashidsDataProvider */ + #[DataProvider('jsHashidsDataProvider')] public function testJsHashidsCompatible($salt, $minHashLength, $alphabet, $numbers, $hash) { $hashids = new Hashids($salt, $minHashLength, $alphabet); diff --git a/tests/MathTest.php b/tests/MathTest.php index 10e1c8f..d3689a8 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -13,6 +13,7 @@ use Hashids\Math\BCMath; use Hashids\Math\Gmp; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -36,25 +37,25 @@ public static function mathProvider() throw new RuntimeException('Missing math extension for Hashids, install either bcmath or gmp.'); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testAdd($math) { $this->assertEquals($math->get(3), $math->add(1, 2)); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testMultiply($math) { $this->assertEquals($math->get(12), $math->multiply(2, 6)); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testDivide($math) { $this->assertEquals($math->get(2), $math->divide(4, 2)); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testGreaterThan($math) { $this->assertTrue($math->greaterThan('18446744073709551615', '9223372036854775807')); @@ -62,19 +63,19 @@ public function testGreaterThan($math) $this->assertFalse($math->greaterThan('9223372036854775807', '9223372036854775807')); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testMod($math) { $this->assertEquals($math->get(15), $math->mod('18446744073709551615', '100')); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testIntval($math) { $this->assertSame(9223372036854775807, $math->intval('9223372036854775807')); } - /** @dataProvider mathProvider */ + #[DataProvider('mathProvider')] public function testStrval($math) { $this->assertSame('18446744073709551615', $math->strval($math->add('0', '18446744073709551615'))); From 15c296521366cb60fea6618acbc737a17540deac Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Thu, 16 Apr 2026 12:03:56 +0200 Subject: [PATCH 2/2] Fix forgotten annotation causing tests to fail --- tests/HashidsTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/HashidsTest.php b/tests/HashidsTest.php index c0c0499..5d53939 100644 --- a/tests/HashidsTest.php +++ b/tests/HashidsTest.php @@ -14,6 +14,7 @@ use Hashids\Hashids; use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresFunction; use PHPUnit\Framework\TestCase; class HashidsTest extends TestCase @@ -317,9 +318,7 @@ public function testJsHashidsCompatible($salt, $minHashLength, $alphabet, $numbe $this->assertEquals($hash, $hashids->encode($numbers)); } - /** - * @requires function bcscale - */ + #[RequiresFunction('bcscale')] public function testBehaviourForDifferentBCMathAccuracy() { bcscale(2);