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