ldc-cocotte/tests/Unit/Shared/ValueObjects/CrmHashcodeTest.php

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\ValueObjects;
use Ramsey\Uuid\Exception\InvalidUuidStringException;
use Ramsey\Uuid\Uuid;
use Shared\ValueObjects\CrmHashcode;
covers(CrmHashcode::class);
it('instantiates from Uuid v4 and fromString with matching value and string cast', function (): void {
// GIVEN
$uuid = Uuid::uuid4();
$v4String = $uuid->toString();
// WHEN
$fromUuid = new CrmHashcode($uuid);
$fromString = CrmHashcode::fromString($v4String);
// THEN
expect($fromUuid->value)->toBe($v4String)
->and((string) $fromUuid)->toBe($v4String)
->and($fromString->value)->toBe($v4String)
->and((string) $fromString)->toBe($v4String);
});
it('rejects non-v4 uuids with DomainException', function (): void {
// GIVEN
$v7 = Uuid::uuid7();
$v1 = Uuid::uuid1();
// WHEN & THEN
expect(static fn (): CrmHashcode => new CrmHashcode($v7))
->toThrow(\DomainException::class)
->and(static fn (): CrmHashcode => new CrmHashcode($v1))
->toThrow(\DomainException::class);
});
it('throws InvalidUuidStringException when fromString receives invalid uuid', function (): void {
// GIVEN / WHEN / THEN
expect(static fn (): CrmHashcode => CrmHashcode::fromString('not-a-uuid'))
->toThrow(InvalidUuidStringException::class);
});