Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10pest()->group('unit');
11
12use Phexium\Domain\Id\UuidV4;
13use Phexium\Domain\Id\UuidV7;
14
15describe('Creation', function (): void {
16    it('creates UuidV4 from string', function (): void {
17        $uuid = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
18
19        expect($uuid->getValue())->toBe('550e8400-e29b-41d4-a716-446655440000')
20            ->and((string) $uuid)->toBe('550e8400-e29b-41d4-a716-446655440000')
21        ;
22    });
23
24    it('creates UuidV7 from string', function (): void {
25        $uuid = UuidV7::from('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
26
27        expect($uuid->getValue())->toBe('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
28    });
29});
30
31describe('Equality', function (): void {
32    it('compares by value', function (): void {
33        $id1 = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
34        $id2 = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
35        $id3 = UuidV4::from('660e8400-e29b-41d4-a716-446655440000');
36
37        expect($id1->equals($id2))->toBeTrue()
38            ->and($id1->equals($id3))->toBeFalse()
39        ;
40    });
41});
42
43describe('Validation', function (): void {
44    it('rejects invalid uuid', function (): void {
45        expect(fn (): UuidV4 => UuidV4::from('not-a-uuid'))->toThrow(InvalidArgumentException::class);
46    });
47
48    it('rejects integer', function (): void {
49        expect(fn (): UuidV4 => UuidV4::from(123))->toThrow(LogicException::class);
50    });
51});