Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
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
10use Phexium\Domain\Id\UuidV4;
11use Phexium\Domain\Id\UuidV7;
12
13test('UuidV4 from string', function (): void {
14    $uuid = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
15
16    expect($uuid->getValue())->toBe('550e8400-e29b-41d4-a716-446655440000')
17        ->and((string) $uuid)->toBe('550e8400-e29b-41d4-a716-446655440000')
18    ;
19});
20
21test('UuidV7 from string', function (): void {
22    $uuid = UuidV7::from('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
23
24    expect($uuid->getValue())->toBe('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
25});
26
27test('equals compares by value', function (): void {
28    $id1 = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
29    $id2 = UuidV4::from('550e8400-e29b-41d4-a716-446655440000');
30    $id3 = UuidV4::from('660e8400-e29b-41d4-a716-446655440000');
31
32    expect($id1->equals($id2))->toBeTrue()
33        ->and($id1->equals($id3))->toBeFalse()
34    ;
35});
36
37test('rejects invalid uuid', function (): void {
38    expect(fn (): UuidV4 => UuidV4::from('not-a-uuid'))->toThrow(InvalidArgumentException::class);
39});
40
41test('rejects integer', function (): void {
42    expect(fn (): UuidV4 => UuidV4::from(123))->toThrow(LogicException::class);
43});