From dea8599b1eee5d5fc0f051a9d0177b86d87fc9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 13 Aug 2026 13:12:30 +0200 Subject: [PATCH] test(UuidHelper): update UUID version checks and remove mocks Refactor tests to directly use UUID instances instead of mocks. --- tests/Unit/Shared/Helpers/UuidHelperTest.php | 35 ++++++-------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/tests/Unit/Shared/Helpers/UuidHelperTest.php b/tests/Unit/Shared/Helpers/UuidHelperTest.php index 04e702c..9545f53 100644 --- a/tests/Unit/Shared/Helpers/UuidHelperTest.php +++ b/tests/Unit/Shared/Helpers/UuidHelperTest.php @@ -4,15 +4,13 @@ declare(strict_types=1); namespace Tests\Unit\Shared\Helpers; -use Ramsey\Uuid\Fields\FieldsInterface; +use Ramsey\Uuid\Guid\Guid; use Ramsey\Uuid\Uuid; -use Ramsey\Uuid\UuidInterface; 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(); @@ -33,31 +31,20 @@ describe('Uuid Helper Unit Tests', function (): void { ->and(UuidHelper::isV7($uuidV4))->toBeFalse(); }); - it('gets version from string index fallback when fields are not Rfc4122', function (): void { + it('can get the version of an UUID including Guid', function (): void { // GIVEN - $mockFields = \Mockery::mock(FieldsInterface::class); - $mockUuid = \Mockery::mock(UuidInterface::class); - $mockUuid->shouldReceive('getFields')->andReturn($mockFields); - $mockUuid->shouldReceive('toString')->andReturn('00000000-0000-4000-8000-000000000000'); + $uuidV4 = Uuid::uuid4(); + $uuidV7 = Uuid::uuid7(); + $guid = Guid::fromString('00000000-0000-4000-8000-000000000000'); // WHEN - $version = UuidHelper::version($mockUuid); + $resultV4 = UuidHelper::version($uuidV4); + $resultV7 = UuidHelper::version($uuidV7); + $resultGuid = UuidHelper::version($guid); // THEN - expect($version)->toBe(4); - }); - - it('returns 0 when UUID string length is shorter than 15 and not Rfc4122', function (): void { - // GIVEN - $mockFields = \Mockery::mock(FieldsInterface::class); - $mockUuid = \Mockery::mock(UuidInterface::class); - $mockUuid->shouldReceive('getFields')->andReturn($mockFields); - $mockUuid->shouldReceive('toString')->andReturn('short'); - - // WHEN - $version = UuidHelper::version($mockUuid); - - // THEN - expect($version)->toBe(0); + expect($resultV4)->toBe(4) + ->and($resultV7)->toBe(7) + ->and($resultGuid)->toBe(4); }); });