Skip to content

Commit

Permalink
adds early return if no pending event is present
Browse files Browse the repository at this point in the history
closes prooph#42
  • Loading branch information
oqq committed Jan 4, 2017
1 parent f26bc80 commit ecc932d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Aggregate/AggregateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ public function saveAggregateRoot($eventSourcedAggregateRoot): void

$createStream = false;

$firstEvent = $domainEvents[0];
$firstEvent = reset($domainEvents);

if ($this->isFirstEvent($firstEvent) && $this->oneStreamPerAggregate) {
if (false === $firstEvent) {
return;
}

if ($this->oneStreamPerAggregate && $this->isFirstEvent($firstEvent)) {
$createStream = true;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Aggregate/AggregateRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,15 @@ public function it_used_provided_stream_name(): void

$this->repository->saveAggregateRoot($user);
}

/**
* @test
* @see https://github.com/prooph/event-sourcing/issues/42
*/
public function it_does_not_throw_an_exception_if_no_pending_event_is_present()
{
$user = User::create('John Doe', 'contact@prooph.de');
$this->repository->saveAggregateRoot($user);
$this->repository->saveAggregateRoot($user);
}
}

0 comments on commit ecc932d

Please sign in to comment.