Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
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 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | use Tests\Phexium\Fake\Domain\IntValueObject; |
| 11 | use Tests\Phexium\Fake\Domain\StringValueObject; |
| 12 | |
| 13 | test('Can create an string VO using static factory method', function (): void { |
| 14 | $string = StringValueObject::fromString('FooBar'); |
| 15 | |
| 16 | expect($string->getValue())->toBe('FooBar'); |
| 17 | expect($string->jsonSerialize())->toBe('FooBar'); |
| 18 | expect((string) $string)->toBe('FooBar'); |
| 19 | }); |
| 20 | |
| 21 | test('Two string VO with same value are equal', function (): void { |
| 22 | $string1 = StringValueObject::fromString('FooBar'); |
| 23 | $string2 = StringValueObject::fromString('FooBar'); |
| 24 | |
| 25 | expect($string1->equals($string2))->toBeTrue(); |
| 26 | }); |
| 27 | |
| 28 | test('Two string VO with different values are not equal', function (): void { |
| 29 | $string1 = StringValueObject::fromString('FooBar'); |
| 30 | $string2 = StringValueObject::fromString('FooQix'); |
| 31 | |
| 32 | expect($string1->equals($string2))->toBeFalse(); |
| 33 | }); |
| 34 | |
| 35 | test('A string VO and another value object are not equal', function (): void { |
| 36 | $other = IntValueObject::fromInt(12); |
| 37 | $object = StringValueObject::fromString('FooBar'); |
| 38 | |
| 39 | expect($object->equals($other))->toBeFalse(); |
| 40 | }); |
| 41 | |
| 42 | it('throws exception for empty string VO', function (): void { |
| 43 | expect(fn (): StringValueObject => StringValueObject::fromString('')) |
| 44 | ->toThrow(InvalidArgumentException::class, 'StringValueObject cannot be empty') |
| 45 | ; |
| 46 | }); |