diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3e3608..48bc9ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.2', '8.3', '8.4', '8.5'] + php-version: ['8.3', '8.4', '8.5'] os: [ubuntu-latest, windows-latest] steps: diff --git a/composer.json b/composer.json index c4a0c7b..0be0118 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "php-parallel-lint/php-parallel-lint": "^1.4", "phpbench/phpbench": "^1.4", "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^10.5", + "phpunit/phpunit": "^12.5.22", "ramsey/conventional-commits": "^1.5", "slevomat/coding-standard": "^8.25", "squizlabs/php_codesniffer": "^4.0" diff --git a/src/Utils.php b/src/Utils.php index b207547..62dedfc 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -137,6 +137,8 @@ private static function convertLargeBaseToBase36(array $digits, int $base): stri */ public static function hexToBase36(string $hexValue): string { + $hexValue = preg_replace('/[^0-9a-fA-F]/', '', $hexValue) ?? ''; + if ($hexValue === '' || $hexValue === '0') { return '0'; } diff --git a/tests/Cuid2Test.php b/tests/Cuid2Test.php index 9c15694..6673139 100644 --- a/tests/Cuid2Test.php +++ b/tests/Cuid2Test.php @@ -6,6 +6,7 @@ use Exception; use OutOfRangeException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Visus\Cuid2\Cuid2; @@ -119,9 +120,8 @@ public function testStringRepresentationsAreConsistent(): void /** * @throws Exception - * - * @dataProvider invalidLengthProvider */ + #[DataProvider('invalidLengthProvider')] public function testThrowsExceptionForInvalidLength(int $length): void { $this->expectException(OutOfRangeException::class); @@ -200,9 +200,8 @@ public function testGeneratesUniqueValuesInLargeSample(): void /** * @throws Exception - * - * @dataProvider validLengthProvider */ + #[DataProvider('validLengthProvider')] public function testGeneratesCorrectLength(int $length): void { $cuid = new Cuid2($length); @@ -226,9 +225,8 @@ public function testStaticGenerateCreatesDefaultLength(): void /** * @throws Exception - * - * @dataProvider validLengthProvider */ + #[DataProvider('validLengthProvider')] public function testStaticGenerateCreatesCustomLength(int $length): void { $cuid = Cuid2::generate($length); @@ -240,9 +238,8 @@ public function testStaticGenerateCreatesCustomLength(int $length): void /** * @throws Exception - * - * @dataProvider invalidLengthProvider */ + #[DataProvider('invalidLengthProvider')] public function testStaticGenerateThrowsExceptionForInvalidLength(int $length): void { $this->expectException(OutOfRangeException::class); @@ -262,17 +259,13 @@ public function testStaticGenerateProducesUniqueValues(): void $this->assertNotEquals((string) $cuid1, (string) $cuid2); } - /** - * @dataProvider validCuidProvider - */ + #[DataProvider('validCuidProvider')] public function testIsValidAcceptsValidCuids(string $cuid, ?int $expectedLength = null): void { $this->assertTrue(Cuid2::isValid($cuid, $expectedLength)); } - /** - * @dataProvider invalidCuidProvider - */ + #[DataProvider('invalidCuidProvider')] public function testIsValidRejectsInvalidCuids(string $cuid, ?int $expectedLength = null): void { $this->assertFalse(Cuid2::isValid($cuid, $expectedLength)); diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 5df4125..c373a07 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -4,6 +4,7 @@ namespace Visus\Cuid2\Test; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Visus\Cuid2\Utils; @@ -56,9 +57,7 @@ public static function invalidHexCharactersProvider(): array ]; } - /** - * @dataProvider hexToBase36Provider - */ + #[DataProvider('hexToBase36Provider')] public function testHexToBase36Conversion(string $hex, string $expected): void { $result = Utils::hexToBase36($hex); @@ -126,9 +125,7 @@ public function testHexToBase36ProducesUniqueOutputsForDifferentInputs(): void ); } - /** - * @dataProvider invalidHexCharactersProvider - */ + #[DataProvider('invalidHexCharactersProvider')] public function testHexToBase36HandlesInvalidCharactersGracefully(string $hex, string $_expected): void { // Invalid characters are treated as 0 based on the match default case