private function checkEventStorage() { if ($this->forced === true) { return; } $storedEvents = $this->eventStorage->getAll(); foreach ($storedEvents as $storedEvent) { if (get_class($storedEvent) != 'Domain\\EventModel\\Event\\ThemeWasCreated') { throw new EventStorageNotEmptyException(); } } }
private function populate() { $events = $this->eventStorage->getAll(); foreach ($events as $event) { $this->stats->increaseTotalEvents(); $eventClass = explode('\\', get_class($event)); $method = 'on' . end($eventClass); if (method_exists($this->listener, $method)) { $this->listener->when($event); $this->stats->increaseProcessedEvents(); } } $this->projectionStorage->flush(); $this->stats->setPopulatedProjections(count($this->projectionStorage->find(static::getProjectionName()))); }
function it_should_run_populator(BulkProjectionStorage $projectionStorage, EventStorage $eventStorage, DomainEventListener $listener) { $projectionStorage->find('post-list')->willReturn($projections = [new PostListProjection(PostId::generate(), 'Post title', new \DateTime())]); foreach ($projections as $projection) { $projectionStorage->remove($projection)->shouldBeCalled(); } $projectionStorage->flush()->shouldBeCalled(); $eventStorage->getAll()->willReturn($events = [new PostWasPublished(PostId::generate(), 'title', 'content', new \DateTime())]); foreach ($events as $event) { $eventClass = explode('\\', get_class($event)); $method = 'on' . end($eventClass); if (method_exists($listener, $method)) { $listener->when($event)->shouldBeCalled(); } } $projectionStorage->flush()->shouldBeCalled(); $this->run(); }