/** * {@inheritdoc} */ public function appendStream(EventStream $eventStream) { $id = $eventStream->aggregateId()->toString(); $type = $eventStream->aggregateType()->toString(); if (!isset($this->streamData[$type])) { $this->streamData[$type] = []; } if (!isset($this->streamData[$type][$id])) { $this->streamData[$type][$id] = new StreamData($id, $type); } if ($this->streamData[$type][$id]->getVersion() !== $eventStream->committed()) { $expected = $eventStream->committed(); $found = $this->streamData[$type][$id]->getVersion(); $message = sprintf('Expected v%s; found v%s in stream [%s]{%s}', $expected, $found, $type, $id); throw ConcurrencyException::create($message); } $events = []; foreach ($eventStream as $eventMessage) { $events[] = new StoredEvent($eventMessage); } $this->streamData[$type][$id]->addEvents($events); $this->streamData[$type][$id]->setVersion($eventStream->version()); }
public function test_that_create_returns_exception_instance() { $exception = ConcurrencyException::create('Concurrency violation'); $this->assertInstanceOf('Novuso\\Common\\Domain\\EventStore\\Exception\\ConcurrencyException', $exception); }