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