-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoCheckInvariantsTest.php
More file actions
43 lines (32 loc) · 1.55 KB
/
AutoCheckInvariantsTest.php
File metadata and controls
43 lines (32 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
use ComplexHeart\Domain\Model\Exceptions\InvariantViolation;
use ComplexHeart\Domain\Model\Test\Fixtures\TypeSafety\Email;
use ComplexHeart\Domain\Model\Test\Fixtures\TypeSafety\Money;
use ComplexHeart\Domain\Model\Test\Fixtures\TypeSafety\CustomEntity;
use ComplexHeart\Domain\Model\ValueObjects\UUIDValue;
test('ValueObject should auto-check invariants and fail', function () {
Email::make('invalid-email');
})->throws(InvariantViolation::class);
test('ValueObject should auto-check invariants and succeed', function () {
$email = Email::make('valid@example.com');
expect($email)->toBeInstanceOf(Email::class);
});
test('ValueObject with multiple invariants should validate all', function () {
Money::make(-10, 'USD');
})->throws(InvariantViolation::class);
test('ValueObject should fail on invalid currency invariant', function () {
Money::make(100, 'US');
})->throws(InvariantViolation::class);
test('Entity with auto-check disabled should not check invariants', function () {
// This should NOT throw even though name is empty
$entity = CustomEntity::make(UUIDValue::random(), '');
expect($entity)->toBeInstanceOf(CustomEntity::class);
});
test('Entity with auto-check enabled would fail on invalid data', function () {
// Entities have auto-check enabled by default (via IsEntity)
// But our CustomEntity overrides it to false
// Let's test that regular entities DO auto-check
// This should throw because invalid email
Email::make('invalid-email');
})->throws(InvariantViolation::class);