1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/event-sourcing project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Tests\EventSourcing; |
10
|
|
|
|
11
|
|
|
use Daikon\EventSourcing\Aggregate\AggregateRevision; |
12
|
|
|
use Daikon\Interop\InvalidArgumentException; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
final class AggregateRevisionTest extends TestCase |
16
|
|
|
{ |
17
|
1 |
|
public function testMakeEmpty(): void |
18
|
|
|
{ |
19
|
1 |
|
$revision = AggregateRevision::makeEmpty(); |
20
|
1 |
|
$this->assertEquals(0, $revision->toNative()); |
21
|
1 |
|
} |
22
|
|
|
|
23
|
1 |
|
public function testFromNativeToNative(): void |
24
|
|
|
{ |
25
|
1 |
|
$this->assertEquals(42, AggregateRevision::fromNative(42)->toNative()); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
public function testFromStringToNative(): void |
29
|
|
|
{ |
30
|
1 |
|
$this->assertEquals(42, AggregateRevision::fromNative('42')->toNative()); |
31
|
1 |
|
} |
32
|
|
|
|
33
|
1 |
|
public function testToString(): void |
34
|
|
|
{ |
35
|
1 |
|
$this->assertEquals('42', (string)AggregateRevision::fromNative(42)); |
36
|
1 |
|
} |
37
|
|
|
|
38
|
1 |
|
public function testEquals(): void |
39
|
|
|
{ |
40
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
41
|
1 |
|
$this->assertTrue($revision->equals(AggregateRevision::fromNative(42))); |
42
|
1 |
|
$this->assertFalse($revision->equals(AggregateRevision::fromNative(23))); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function testIsInitial(): void |
46
|
|
|
{ |
47
|
1 |
|
$this->assertTrue(AggregateRevision::fromNative(1)->isInitial()); |
48
|
1 |
|
$this->assertFalse(AggregateRevision::fromNative(0)->isInitial()); |
49
|
1 |
|
$this->assertFalse(AggregateRevision::fromNative(42)->isInitial()); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
public function testIsGreaterThan(): void |
53
|
|
|
{ |
54
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
55
|
1 |
|
$this->assertTrue($revision->isGreaterThan(AggregateRevision::fromNative(41))); |
56
|
1 |
|
$this->assertFalse($revision->isGreaterThan(AggregateRevision::fromNative(42))); |
57
|
1 |
|
$this->assertFalse($revision->isGreaterThan(AggregateRevision::fromNative(43))); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
1 |
|
public function testIsGreaterThanOrEqual(): void |
61
|
|
|
{ |
62
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
63
|
1 |
|
$this->assertTrue($revision->isGreaterThanOrEqual(AggregateRevision::fromNative(41))); |
64
|
1 |
|
$this->assertTrue($revision->isGreaterThanOrEqual(AggregateRevision::fromNative(42))); |
65
|
1 |
|
$this->assertFalse($revision->isGreaterThanOrEqual(AggregateRevision::fromNative(43))); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
1 |
|
public function testIsLessThan(): void |
69
|
|
|
{ |
70
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
71
|
1 |
|
$this->assertTrue($revision->isLessThan(AggregateRevision::fromNative(43))); |
72
|
1 |
|
$this->assertFalse($revision->isLessThan(AggregateRevision::fromNative(42))); |
73
|
1 |
|
$this->assertFalse($revision->isLessThan(AggregateRevision::fromNative(41))); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
1 |
|
public function testIsLessThanOrEqual(): void |
77
|
|
|
{ |
78
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
79
|
1 |
|
$this->assertTrue($revision->isLessThanOrEqual(AggregateRevision::fromNative(43))); |
80
|
1 |
|
$this->assertTrue($revision->isLessThanOrEqual(AggregateRevision::fromNative(42))); |
81
|
1 |
|
$this->assertFalse($revision->isLessThanOrEqual(AggregateRevision::fromNative(41))); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
1 |
|
public function testIsWithinRange(): void |
85
|
|
|
{ |
86
|
1 |
|
$revision = AggregateRevision::fromNative(42); |
87
|
|
|
|
88
|
1 |
|
$this->assertTrue($revision->isWithinRange( |
89
|
1 |
|
AggregateRevision::fromNative(40), |
90
|
1 |
|
AggregateRevision::fromNative(43) |
91
|
|
|
)); |
92
|
1 |
|
$this->assertFalse($revision->isWithinRange( |
93
|
1 |
|
AggregateRevision::fromNative(23), |
94
|
1 |
|
AggregateRevision::fromNative(30) |
95
|
|
|
)); |
96
|
1 |
|
} |
97
|
|
|
|
98
|
1 |
|
public function testMakeFromInvalidIntegerish(): void |
99
|
|
|
{ |
100
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
101
|
1 |
|
AggregateRevision::fromNative('what'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|