/** * @param UncommittedEvents $stream * @return CommittedEvents */ public function commit(UncommittedEvents $stream) { $aggregateId = $stream->first()->getAggregateIdentity(); foreach ($stream as $event) { $this->events[(string) $aggregateId][] = $event; } return new CommittedEvents($aggregateId, $stream->getEvents()); }
function it_should_add_events_in_memory() { $identity = BasketId::generate(); $event = new BasketWasPickedUp($identity); $stream = new UncommittedEvents($identity); $stream->append($event); $this->commit($stream); $this->getAggregateHistoryFor($identity)->first()->shouldbe($event); }
/** * Register a event happening on the aggregate * * @param DomainEvent $event * @return static */ public function recordThat(DomainEvent $event) { $this->bumpVersion(); if (is_null($this->uncommittedEvents)) { $this->uncommittedEvents = new UncommittedEvents($this->getIdentity()); } $this->uncommittedEvents->append($event); $this->when($event); return $this; }