Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
33 / 33
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 Tests\Phexium\Fake\Domain\IntValueObject;
13use Tests\Phexium\Fake\Domain\StringValueObject;
14
15describe('Creation', function (): void {
16    it('creates a string VO using static factory method', function (): void {
17        $string = StringValueObject::fromString('FooBar');
18
19        expect($string->getValue())->toBe('FooBar');
20        expect($string->jsonSerialize())->toBe('FooBar');
21        expect((string) $string)->toBe('FooBar');
22    });
23});
24
25describe('Equality', function (): void {
26    it('considers two string VOs with same value as equal', function (): void {
27        $string1 = StringValueObject::fromString('FooBar');
28        $string2 = StringValueObject::fromString('FooBar');
29
30        expect($string1->equals($string2))->toBeTrue();
31    });
32
33    it('considers two string VOs with different values as not equal', function (): void {
34        $string1 = StringValueObject::fromString('FooBar');
35        $string2 = StringValueObject::fromString('FooQix');
36
37        expect($string1->equals($string2))->toBeFalse();
38    });
39
40    it('considers a string VO and another value object type as not equal', function (): void {
41        $other = IntValueObject::fromInt(12);
42        $object = StringValueObject::fromString('FooBar');
43
44        expect($object->equals($other))->toBeFalse();
45    });
46});
47
48describe('Validation', function (): void {
49    it('throws exception for empty string VO', function (): void {
50        expect(fn (): StringValueObject => StringValueObject::fromString(''))
51            ->toThrow(InvalidArgumentException::class, 'StringValueObject cannot be empty')
52        ;
53    });
54});