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:
parent
40c360f766
commit
57756ce6ae
2 changed files with 47 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
46
tests/Integration/Shared/Helpers/UuidHelperTest.php
Normal file
46
tests/Integration/Shared/Helpers/UuidHelperTest.php
Normal 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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue