Skip to content

Commit f3c8a5e

Browse files
chore(deps): update dependency phpunit/phpunit to v12 [security] (#285)
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Alan Brault <alan.brault@visus.io> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Alan Brault <alan.brault@visus.io>
1 parent 9eeefea commit f3c8a5e

5 files changed

Lines changed: 14 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
strategy:
119119
fail-fast: false
120120
matrix:
121-
php-version: ['8.2', '8.3', '8.4', '8.5']
121+
php-version: ['8.3', '8.4', '8.5']
122122
os: [ubuntu-latest, windows-latest]
123123

124124
steps:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php-parallel-lint/php-parallel-lint": "^1.4",
2727
"phpbench/phpbench": "^1.4",
2828
"phpstan/phpstan": "^1.9",
29-
"phpunit/phpunit": "^10.5",
29+
"phpunit/phpunit": "^12.5.22",
3030
"ramsey/conventional-commits": "^1.5",
3131
"slevomat/coding-standard": "^8.25",
3232
"squizlabs/php_codesniffer": "^4.0"

src/Utils.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ private static function convertLargeBaseToBase36(array $digits, int $base): stri
137137
*/
138138
public static function hexToBase36(string $hexValue): string
139139
{
140+
$hexValue = preg_replace('/[^0-9a-fA-F]/', '', $hexValue) ?? '';
141+
140142
if ($hexValue === '' || $hexValue === '0') {
141143
return '0';
142144
}

tests/Cuid2Test.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use OutOfRangeException;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011
use Visus\Cuid2\Cuid2;
1112

@@ -119,9 +120,8 @@ public function testStringRepresentationsAreConsistent(): void
119120

120121
/**
121122
* @throws Exception
122-
*
123-
* @dataProvider invalidLengthProvider
124123
*/
124+
#[DataProvider('invalidLengthProvider')]
125125
public function testThrowsExceptionForInvalidLength(int $length): void
126126
{
127127
$this->expectException(OutOfRangeException::class);
@@ -200,9 +200,8 @@ public function testGeneratesUniqueValuesInLargeSample(): void
200200

201201
/**
202202
* @throws Exception
203-
*
204-
* @dataProvider validLengthProvider
205203
*/
204+
#[DataProvider('validLengthProvider')]
206205
public function testGeneratesCorrectLength(int $length): void
207206
{
208207
$cuid = new Cuid2($length);
@@ -226,9 +225,8 @@ public function testStaticGenerateCreatesDefaultLength(): void
226225

227226
/**
228227
* @throws Exception
229-
*
230-
* @dataProvider validLengthProvider
231228
*/
229+
#[DataProvider('validLengthProvider')]
232230
public function testStaticGenerateCreatesCustomLength(int $length): void
233231
{
234232
$cuid = Cuid2::generate($length);
@@ -240,9 +238,8 @@ public function testStaticGenerateCreatesCustomLength(int $length): void
240238

241239
/**
242240
* @throws Exception
243-
*
244-
* @dataProvider invalidLengthProvider
245241
*/
242+
#[DataProvider('invalidLengthProvider')]
246243
public function testStaticGenerateThrowsExceptionForInvalidLength(int $length): void
247244
{
248245
$this->expectException(OutOfRangeException::class);
@@ -262,17 +259,13 @@ public function testStaticGenerateProducesUniqueValues(): void
262259
$this->assertNotEquals((string) $cuid1, (string) $cuid2);
263260
}
264261

265-
/**
266-
* @dataProvider validCuidProvider
267-
*/
262+
#[DataProvider('validCuidProvider')]
268263
public function testIsValidAcceptsValidCuids(string $cuid, ?int $expectedLength = null): void
269264
{
270265
$this->assertTrue(Cuid2::isValid($cuid, $expectedLength));
271266
}
272267

273-
/**
274-
* @dataProvider invalidCuidProvider
275-
*/
268+
#[DataProvider('invalidCuidProvider')]
276269
public function testIsValidRejectsInvalidCuids(string $cuid, ?int $expectedLength = null): void
277270
{
278271
$this->assertFalse(Cuid2::isValid($cuid, $expectedLength));

tests/UtilsTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Visus\Cuid2\Test;
66

7+
use PHPUnit\Framework\Attributes\DataProvider;
78
use PHPUnit\Framework\TestCase;
89
use Visus\Cuid2\Utils;
910

@@ -56,9 +57,7 @@ public static function invalidHexCharactersProvider(): array
5657
];
5758
}
5859

59-
/**
60-
* @dataProvider hexToBase36Provider
61-
*/
60+
#[DataProvider('hexToBase36Provider')]
6261
public function testHexToBase36Conversion(string $hex, string $expected): void
6362
{
6463
$result = Utils::hexToBase36($hex);
@@ -126,9 +125,7 @@ public function testHexToBase36ProducesUniqueOutputsForDifferentInputs(): void
126125
);
127126
}
128127

129-
/**
130-
* @dataProvider invalidHexCharactersProvider
131-
*/
128+
#[DataProvider('invalidHexCharactersProvider')]
132129
public function testHexToBase36HandlesInvalidCharactersGracefully(string $hex, string $_expected): void
133130
{
134131
// Invalid characters are treated as 0 based on the match default case

0 commit comments

Comments
 (0)