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..5d53939 100644 --- a/tests/HashidsTest.php +++ b/tests/HashidsTest.php @@ -13,6 +13,8 @@ use Hashids\Hashids; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresFunction; use PHPUnit\Framework\TestCase; class HashidsTest extends TestCase @@ -64,7 +66,7 @@ public static function alphabetProvider() ]; } - /** @dataProvider alphabetProvider */ + #[DataProvider('alphabetProvider')] public function testAlphabet($alphabets) { $numbers = [1, 2, 3]; @@ -88,7 +90,7 @@ public static function saltProvider() ]; } - /** @dataProvider saltProvider */ + #[DataProvider('saltProvider')] public function testSalt($salts) { $numbers = [1, 2, 3]; @@ -111,7 +113,7 @@ public static function minLengthProvider() ]; } - /** @dataProvider minLengthProvider */ + #[DataProvider('minLengthProvider')] public function testMinLength($lengths) { $numbers = [1, 2, 3]; @@ -133,7 +135,7 @@ public static function encodeTypesProvider() ]; } - /** @dataProvider encodeTypesProvider */ + #[DataProvider('encodeTypesProvider')] public function testEncodeTypes($params) { $numbers = [1, 2, 3]; @@ -169,7 +171,7 @@ public static function defaultParamsProvider() ]; } - /** @dataProvider defaultParamsProvider */ + #[DataProvider('defaultParamsProvider')] public function testDefaultParams($id, $numbers) { $hashids = new Hashids(); @@ -202,7 +204,7 @@ public static function customParamsProvider() ]; } - /** @dataProvider customParamsProvider */ + #[DataProvider('customParamsProvider')] public function testCustomParams($id, $numbers) { $minLength = 30; @@ -232,7 +234,7 @@ public static function defaultParamsHexProvider() ]; } - /** @dataProvider defaultParamsHexProvider */ + #[DataProvider('defaultParamsHexProvider')] public function testDefaultParamsHex($id, $hex) { $hashids = new Hashids(); @@ -258,7 +260,7 @@ public static function customParamsHexProvider() ]; } - /** @dataProvider customParamsHexProvider */ + #[DataProvider('customParamsHexProvider')] public function testCustomParamsHex($id, $hex) { $minLength = 30; @@ -283,7 +285,7 @@ public static function bigNumberDataProvider() ]; } - /** @dataProvider bigNumberDataProvider */ + #[DataProvider('bigNumberDataProvider')] public function testBigNumberEncode($number, $hash) { $hashids = new Hashids('this is my salt'); @@ -291,7 +293,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,16 +311,14 @@ public static function jsHashidsDataProvider() ]; } - /** @dataProvider jsHashidsDataProvider */ + #[DataProvider('jsHashidsDataProvider')] public function testJsHashidsCompatible($salt, $minHashLength, $alphabet, $numbers, $hash) { $hashids = new Hashids($salt, $minHashLength, $alphabet); $this->assertEquals($hash, $hashids->encode($numbers)); } - /** - * @requires function bcscale - */ + #[RequiresFunction('bcscale')] public function testBehaviourForDifferentBCMathAccuracy() { bcscale(2); 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')));