ldc-arcadia-api/tests/Unit/Shared/Helpers/UuidHelperTest.php
Jérémy Munsch dea8599b1e
test(UuidHelper): update UUID version checks and remove mocks
Refactor tests to directly use UUID instances instead of mocks.
2026-08-13 13:12:30 +02:00

50 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\Helpers;
use Ramsey\Uuid\Guid\Guid;
use Ramsey\Uuid\Uuid;
use Shared\Helpers\UuidHelper;
covers(UuidHelper::class);
describe('Uuid Helper Unit Tests', function (): void {
it('correctly checks if UUID is v4', function (): void {
// GIVEN
$uuidV4 = Uuid::uuid4();
$uuidV7 = Uuid::uuid7();
// WHEN & THEN
expect(UuidHelper::isV4($uuidV4))->toBeTrue()
->and(UuidHelper::isV4($uuidV7))->toBeFalse();
});
it('correctly checks if UUID is v7', function (): void {
// GIVEN
$uuidV4 = Uuid::uuid4();
$uuidV7 = Uuid::uuid7();
// WHEN & THEN
expect(UuidHelper::isV7($uuidV7))->toBeTrue()
->and(UuidHelper::isV7($uuidV4))->toBeFalse();
});
it('can get the version of an UUID including Guid', function (): void {
// GIVEN
$uuidV4 = Uuid::uuid4();
$uuidV7 = Uuid::uuid7();
$guid = Guid::fromString('00000000-0000-4000-8000-000000000000');
// WHEN
$resultV4 = UuidHelper::version($uuidV4);
$resultV7 = UuidHelper::version($uuidV7);
$resultGuid = UuidHelper::version($guid);
// THEN
expect($resultV4)->toBe(4)
->and($resultV7)->toBe(7)
->and($resultGuid)->toBe(4);
});
});