-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAttributeAggregateMetadataFactoryTest.php
More file actions
130 lines (108 loc) · 5.13 KB
/
Copy pathAttributeAggregateMetadataFactoryTest.php
File metadata and controls
130 lines (108 loc) · 5.13 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
namespace Patchlevel\EventSourcing\Tests\Unit\Metadata\Aggregate;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\ArgumentTypeIsMissing;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootMetadataFactory;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\DuplicateEmptyApplyAttribute;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\MixedApplyAttributeUsage;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\MessageDeleted;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\NameChanged;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyBothUsage;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyIntersection;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyMultipleApply;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyNoType;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithEmptyApply;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithSharedApplyContext;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithStream;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithSuppressAll;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\SplittingEvent;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(AttributeAggregateRootMetadataFactory::class)]
final class AttributeAggregateMetadataFactoryTest extends TestCase
{
public function testProfile(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$metadata = $metadataFactory->metadata(Profile::class);
self::assertSame(
[
ProfileCreated::class => 'applyProfileCreated',
ProfileVisited::class => 'applyProfileCreated',
NameChanged::class => 'applyNameChanged',
SplittingEvent::class => 'applySplittingEvent',
],
$metadata->applyMethods,
);
self::assertFalse($metadata->suppressAll);
self::assertSame(
[MessageDeleted::class => true],
$metadata->suppressEvents,
);
self::assertSame('profile-{id}', $metadata->streamName);
self::assertSame('profile-foo', $metadata->streamName('foo'));
}
public function testApplyWithNoEventClass(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$metadata = $metadataFactory->metadata(ProfileWithEmptyApply::class);
self::assertSame(
[
ProfileCreated::class => 'applyProfileCreated',
ProfileVisited::class => 'applyProfileCreated',
NameChanged::class => 'applyNameChanged',
],
$metadata->applyMethods,
);
self::assertFalse($metadata->suppressAll);
self::assertSame([], $metadata->suppressEvents);
}
public function streamName(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$metadata = $metadataFactory->metadata(ProfileWithStream::class);
self::assertSame('other-{id}', $metadata->streamName);
self::assertSame('other-foo', $metadata->streamName('foo'));
}
public function testBrokenApplyWithNoType(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$this->expectException(ArgumentTypeIsMissing::class);
$metadataFactory->metadata(ProfileWithBrokenApplyNoType::class);
}
public function testBrokenApplyWithIntersectionType(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$this->expectException(ArgumentTypeIsMissing::class);
$metadataFactory->metadata(ProfileWithBrokenApplyIntersection::class);
}
public function testBrokenApplyWithMultipleApply(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$this->expectException(DuplicateEmptyApplyAttribute::class);
$metadataFactory->metadata(ProfileWithBrokenApplyMultipleApply::class);
}
public function testBrokenApplyWithBothUsages(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$this->expectException(MixedApplyAttributeUsage::class);
$metadataFactory->metadata(ProfileWithBrokenApplyBothUsage::class);
}
public function testSuppressAll(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$metadata = $metadataFactory->metadata(ProfileWithSuppressAll::class);
self::assertTrue($metadata->suppressAll);
self::assertSame([], $metadata->suppressEvents);
}
public function testSharedApplyContext(): void
{
$metadataFactory = new AttributeAggregateRootMetadataFactory();
$metadata = $metadataFactory->metadata(ProfileWithSharedApplyContext::class);
self::assertFalse($metadata->suppressAll);
self::assertSame([ProfileCreated::class => true], $metadata->suppressEvents);
}
}