test(UuidHelper): add unit tests for UUID version verification

Includes tests for checking if UUIDs are v4 or v7 and retrieving their version.
This commit is contained in:
Jérémy Munsch 2026-08-13 10:24:05 +02:00
parent 40c360f766
commit 57756ce6ae
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
2 changed files with 47 additions and 1 deletions

View file

@ -11,7 +11,7 @@ final readonly class UuidHelper
{
private function __construct()
{
// Static class
throw new \LogicException('Static class');
}
public static function isV4(UuidInterface $uuid): bool

View file

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
use Ramsey\Uuid\Uuid;
use Shared\Helpers\UuidHelper;
covers(UuidHelper::class);
describe('Uuid Helper', function (): void {
it('can verify an UUID is v4', function (): void {
// GIVEN
$uuidV4 = Uuid::uuid4();
// WHEN
$result = UuidHelper::isV4($uuidV4);
// THEN
expect($result)->toBeTrue();
});
it('can verify an UUID is v7', function (): void {
// GIVEN
$uuidV7 = Uuid::uuid7();
// WHEN
$result = UuidHelper::isV7($uuidV7);
// THEN
expect($result)->toBeTrue();
});
it('can get the version of an UUID', function (): void {
// GIVEN
$uuidV4 = Uuid::uuid4();
$uuidV7 = Uuid::uuid7();
// WHEN
$resultV4 = UuidHelper::version($uuidV4);
$resultV7 = UuidHelper::version($uuidV7);
// THEN
expect($resultV4)->toBe(4)
->and($resultV7)->toBe(7);
});
});