/**
  * @expectedException \RayRutjes\DomainFoundation\Repository\ConflictingAggregateVersionException
  */
 public function testShouldEnsureTheLoadedAggregateRootMatchesTheExpectedVersion()
 {
     $identifier = new AggregateRootIdentifierStub('identifier');
     $event = new GenericEvent($identifier, 1, MessageIdentifier::generate(), new Created($identifier));
     $this->eventStore->method('read')->willReturn(new GenericEventStream([$event]));
     $this->repository->load($identifier, 0);
 }
 public function setUp()
 {
     $this->identifier = MessageIdentifier::generate();
     $this->payload = new PayloadStub();
     $this->metadata = new Metadata();
     $this->command = new GenericCommand($this->identifier, $this->payload, $this->metadata);
 }
 public function testExtractsMetadataOfACommand()
 {
     $data = ['somedata' => 'data'];
     $command = new GenericCommand(MessageIdentifier::generate(), new PayloadStub(), new Metadata($data));
     $metadataProvider = new MetadataDataProvider();
     $this->assertEquals($data, $metadataProvider->provideAuditDataFor($command));
 }
 /**
  * @return GenericEventStream
  */
 private function provideStubbedEventStream()
 {
     $identifier = new AggregateRootIdentifierStub();
     $payload = new PayloadStub();
     $event1 = new GenericEvent($identifier, 1, MessageIdentifier::generate(), $payload);
     $event2 = new GenericEvent($identifier, 2, MessageIdentifier::generate(), $payload);
     return new GenericEventStream([$event1, $event2]);
 }
 public function setUp()
 {
     $this->aggregateRootIdentifier = new AggregateRootIdentifierStub();
     $this->identifier = MessageIdentifier::generate();
     $this->payload = new PayloadStub();
     $this->metadata = new Metadata();
     $this->event = new GenericEvent($this->aggregateRootIdentifier, 1, $this->identifier, $this->payload, $this->metadata);
 }
 public function testCanBeLoadedFromAnEventStream()
 {
     $identifier = new AggregateRootIdentifierStub('identifier');
     $event = new GenericEvent($identifier, 1, MessageIdentifier::generate(), new Created($identifier));
     $stream = new GenericEventStream([$event]);
     $aggregateRoot = EventSourcedAggregateRootStub::loadFromHistory($stream);
     return $aggregateRoot;
 }
 public function setUp()
 {
     $this->command = new GenericCommand(MessageIdentifier::generate(), new PayloadStub());
     $this->auditDataProvider = $this->auditDataProviderMock();
     $this->auditLogger = $this->auditLoggerMock();
     $this->result = 'result';
     $this->listener = new AuditUnitOfWorkListener($this->command, $this->auditDataProvider, $this->auditLogger);
     $this->listener->setResult($this->result);
 }
 public function testExtractsCorrelationDataOutOfACommand()
 {
     $commandIdentifier = MessageIdentifier::generate();
     $payload = new PayloadStub();
     $data = ['command_name' => get_class($payload), 'command_identifier' => $commandIdentifier->toString()];
     $command = new GenericCommand($commandIdentifier, $payload);
     $correlationDataProvider = new CorrelationDataProvider();
     $this->assertEquals($data, $correlationDataProvider->provideAuditDataFor($command));
 }
 /**
  * @param $command
  *
  * @return Command
  */
 private function wrapCommandWithMessageEnvelope($command)
 {
     if ($command instanceof Command) {
         return $command;
     }
     if ($command instanceof Serializable) {
         return new GenericCommand(MessageIdentifier::generate(), $command);
     }
     throw new \InvalidArgumentException('Unsupported data type.');
 }
 public function testCanConfirmItsInequalityWithAnotherMessageIdentifier()
 {
     $messageIdentifier1 = MessageIdentifier::generate();
     $messageIdentifier2 = MessageIdentifier::generate();
     $this->assertFalse($messageIdentifier1->equals($messageIdentifier2));
 }
 /**
  * @param Serializable $payload
  */
 public function addEventFromPayload(Serializable $payload)
 {
     $event = new GenericEvent($this->aggregateRootIdentifier, $this->nextSequenceNumber(), MessageIdentifier::generate(), $payload);
     $this->addEvent($event);
 }
 private function commandMock()
 {
     return new GenericCommand(MessageIdentifier::generate(), new PayloadStub());
 }
 /**
  * @param MessageIdentifier $identifier
  *
  * @return bool
  */
 public function equals(MessageIdentifier $identifier)
 {
     return $this->uuid->toString() === $identifier->toString();
 }