Exceptions will be thrown if aggregate has no pending events
oqq opened this issue · 4 comments
oqq commented
Tested with 5.0.0-beta1 Release
If I try to save a a aggregate root not having pending events with AggregateRepository::saveAggregateRoot
, an exception is thrown by method AggregateRepository::isFirstEvent
, since this method requires a Message
object as first argument.
$firstEvent
would be null
if there is no pending event in $domainEvents
.
$firstEvent = $domainEvents[0];
if ($this->isFirstEvent($firstEvent) && $this->oneStreamPerAggregate) {
$createStream = true;
}
I would prefer to throw a NoPendingEventsException, or not to do anything If there is no pending event.
Maybe an additional unit test is required for that use case.
prolic commented
wanna submit a PR?
prolic commented
btw: I would prefer no exception, just return early.
like:
if (empty($domainEvents)) {
return;
}
oqq commented
i am almost done.. only need to pull it. would be done today or tomorrow.