Ejemplo n.º 1
0
 /**
  * @param Event $event
  * @param boolean $isNew
  */
 private function internalApplyChange(Event $event, $isNew)
 {
     $this->apply($event);
     if ((bool) $isNew) {
         $this->changes->add($event);
     }
 }
Ejemplo n.º 2
0
 public function testClearWillMakeListEmpty()
 {
     $event = $this->getMockBuilder(Event::class)->getMock();
     $instance = new Events([$event]);
     self::assertCount(1, $instance->getIterator());
     $instance->clear();
     self::assertCount(0, $instance->getIterator());
 }
Ejemplo n.º 3
0
 /**
  * @param Uuid $aggregateId
  * @param Events $events
  * @param integer $expectedPlayHead
  * @throws ConcurrencyException
  */
 public function save(Uuid $aggregateId, Events $events, $expectedPlayHead)
 {
     $expectedPlayHead = (int) $expectedPlayHead;
     if (!$this->isValidPlayHead($aggregateId, $expectedPlayHead)) {
         throw new ConcurrencyException($expectedPlayHead, $this->current->get($aggregateId->getValue()));
     }
     $playHead = $expectedPlayHead;
     foreach ($events->getIterator() as $event) {
         /* @var $event Event */
         $playHead++;
         $event->setVersion($playHead);
         $this->saveEvent($aggregateId, $event);
         $this->current->put($aggregateId->getValue(), $playHead);
         $this->eventBus->publish($event);
     }
 }
Ejemplo n.º 4
0
 public function testSaveEventsForAggregatePublishesEvents()
 {
     $id = Uuid::createNew();
     $events = new Events([new FirstEvent(), new SecondEvent()]);
     $eventBus = $this->getEventBus();
     $storage = $this->getStorage();
     $serializer = $this->getSerializer();
     $classMap = $this->getEventClassMap();
     $eventBus->expects(self::exactly($events->getIterator()->count()))->method('publish')->with(self::logicalOr($events->getIterator()->offsetGet(0), $events->getIterator()->offsetGet(1)));
     $store = new EventStore($eventBus, $storage, $serializer, $classMap);
     $store->save($id, $events, -1);
 }