Пример #1
0
 /**
  * @param Event $event
  * @param boolean $isNew
  */
 private function internalApplyChange(Event $event, $isNew)
 {
     $this->apply($event);
     if ((bool) $isNew) {
         $this->changes->add($event);
     }
 }
Пример #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());
 }
Пример #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);
     }
 }
Пример #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);
 }