Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
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\Ulid;
13
14describe('Creation', function (): void {
15    it('creates from uuid string', function (): void {
16        $ulid = Ulid::from('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
17
18        expect($ulid->getValue())->toMatch('/^[0-9A-Z]{26}$/');
19    });
20
21    it('creates from base32 string', function (): void {
22        $ulid = Ulid::from('01JE5Z89F7YQNMKWTDQMR6WX0A');
23
24        expect($ulid->getValue())->toBe('01JE5Z89F7YQNMKWTDQMR6WX0A');
25    });
26});
27
28describe('Equality', function (): void {
29    it('compares by value and converts to string', function (): void {
30        $id1 = Ulid::from('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
31        $id2 = Ulid::from('01933e42-4d1e-7fa8-9a7c-3b6f4e8d9c0a');
32
33        expect((string) $id1)->toBe($id1->getValue())
34            ->and($id1->equals($id2))->toBeTrue()
35        ;
36    });
37});
38
39describe('Validation', function (): void {
40    it('rejects invalid string', function (): void {
41        expect(fn (): Ulid => Ulid::from('invalid'))->toThrow(InvalidArgumentException::class);
42    });
43
44    it('rejects integer', function (): void {
45        expect(fn (): Ulid => Ulid::from(123))->toThrow(LogicException::class);
46    });
47});