/** * 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; }
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); }