|
7 | 7 | use Thenativeweb\Eventsourcingdb\EventCandidate; |
8 | 8 | use Thenativeweb\Eventsourcingdb\IsEventQlQueryTrue; |
9 | 9 | use Thenativeweb\Eventsourcingdb\IsSubjectOnEventId; |
| 10 | +use Thenativeweb\Eventsourcingdb\IsSubjectPopulated; |
10 | 11 | use Thenativeweb\Eventsourcingdb\IsSubjectPristine; |
11 | 12 | use Thenativeweb\Eventsourcingdb\Tests\Trait\ClientTestTrait; |
12 | 13 |
|
@@ -104,6 +105,68 @@ public function testSupportsTheIsSubjectPristinePrecondition(): void |
104 | 105 | ); |
105 | 106 | } |
106 | 107 |
|
| 108 | + public function testRejectsWritingToEmptySubjectWhenUsingTheIsSubjectPopulatedPrecondition(): void |
| 109 | + { |
| 110 | + $eventCandidate = new EventCandidate( |
| 111 | + source: 'https://www.eventsourcingdb.io', |
| 112 | + subject: '/test', |
| 113 | + type: 'io.eventsourcingdb.test', |
| 114 | + data: [ |
| 115 | + 'value' => 42, |
| 116 | + ], |
| 117 | + ); |
| 118 | + |
| 119 | + $this->expectExceptionMessage("Failed to write events, got HTTP status code '409', expected '200'"); |
| 120 | + |
| 121 | + $this->client->writeEvents( |
| 122 | + [ |
| 123 | + $eventCandidate, |
| 124 | + ], |
| 125 | + [ |
| 126 | + new IsSubjectPopulated('/test'), |
| 127 | + ], |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + public function testSupportsTheIsSubjectPopulatedPrecondition(): void |
| 132 | + { |
| 133 | + $firstEvent = new EventCandidate( |
| 134 | + source: 'https://www.eventsourcingdb.io', |
| 135 | + subject: '/test', |
| 136 | + type: 'io.eventsourcingdb.test', |
| 137 | + data: [ |
| 138 | + 'value' => 23, |
| 139 | + ], |
| 140 | + ); |
| 141 | + |
| 142 | + $secondEvent = new EventCandidate( |
| 143 | + source: 'https://www.eventsourcingdb.io', |
| 144 | + subject: '/test', |
| 145 | + type: 'io.eventsourcingdb.test', |
| 146 | + data: [ |
| 147 | + 'value' => 42, |
| 148 | + ], |
| 149 | + ); |
| 150 | + |
| 151 | + $this->client->writeEvents([ |
| 152 | + $firstEvent, |
| 153 | + ]); |
| 154 | + |
| 155 | + $writtenEvents = $this->client->writeEvents( |
| 156 | + [ |
| 157 | + $secondEvent, |
| 158 | + ], |
| 159 | + [ |
| 160 | + new IsSubjectPopulated('/test'), |
| 161 | + ], |
| 162 | + ); |
| 163 | + |
| 164 | + $this->assertCount(1, $writtenEvents); |
| 165 | + $this->assertInstanceOf(CloudEvent::class, $writtenEvents[0]); |
| 166 | + $this->assertSame('1', $writtenEvents[0]->id); |
| 167 | + $this->assertSame(42, $writtenEvents[0]->data['value']); |
| 168 | + } |
| 169 | + |
107 | 170 | public function testSupportsTheIsSubjectOnEventIdPrecondition(): void |
108 | 171 | { |
109 | 172 | $firstEvent = new EventCandidate( |
|
0 commit comments