50 lines
1.3 KiB
PHP
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);
|
|
});
|
|
});
|