/**
  * @test
  */
 public function it_appends_events_to_event_stream()
 {
     $this->eventStore->beginTransaction();
     $user = User::create("John Doe", "*****@*****.**");
     $aggregateType = AggregateType::fromString('SuperUser');
     $aggregateId = Uuid::uuid4()->toString();
     $streamEvents = [UserCreated::with(['user_id' => $aggregateId], 1)];
     $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId, $streamEvents, $user);
     $this->eventStore->commit();
     $this->eventStore->beginTransaction();
     $streamEvents = [UsernameChanged::with(['name' => 'John Doe'], 2)];
     $this->strategy->appendEvents($aggregateType, $aggregateId, $streamEvents, $user);
     $this->eventStore->commit();
     $stream = $this->eventStore->load(new StreamName('event_stream'));
     $this->assertEquals(2, count($stream->streamEvents()));
     //Create a second aggregate
     $this->eventStore->beginTransaction();
     $product = new Product();
     $aggregateType = AggregateType::fromString('Product');
     $aggregateId = Uuid::uuid4()->toString();
     $streamEvents = [UserCreated::with(['user_id' => $aggregateId], 1)];
     $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId, $streamEvents, $product);
     $this->eventStore->commit();
     $stream = $this->eventStore->load(new StreamName('event_stream'));
     $this->assertEquals(3, count($stream->streamEvents()));
 }
 /**
  * @test
  */
 public function it_loads_events_from_min_version_on()
 {
     $this->adapter->create($this->getTestStream());
     $streamEvent1 = UsernameChanged::with(array('name' => 'John Doe'), 2);
     DomainEventMetadataWriter::setMetadataKey($streamEvent1, 'tag', 'person');
     $streamEvent2 = UsernameChanged::with(array('name' => 'Jane Doe'), 2);
     DomainEventMetadataWriter::setMetadataKey($streamEvent2, 'tag', 'person');
     $this->adapter->appendTo(new StreamName('Prooph\\Model\\User'), array($streamEvent1, $streamEvent2));
     $stream = $this->adapter->load(new StreamName('Prooph\\Model\\User'), 2);
     $this->assertEquals('Prooph\\Model\\User', $stream->streamName()->toString());
     $this->assertEquals(2, count($stream->streamEvents()));
     $this->assertEquals('John Doe', $stream->streamEvents()[0]->payload()['name']);
     $this->assertEquals('Jane Doe', $stream->streamEvents()[1]->payload()['name']);
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function it_does_not_allow_to_add_stream_events_with_wrong_repository_aggregate_type()
 {
     $this->eventStore->beginTransaction();
     $user = User::create("John Doe", "*****@*****.**");
     $aggregateType = AggregateType::fromAggregateRoot($user);
     $aggregateId = Uuid::uuid4()->toString();
     $streamEvents = [UserCreated::with(['user_id' => $aggregateId], 1)];
     $this->strategy->addEventsForNewAggregateRoot($aggregateType, $aggregateId, $streamEvents, $user);
     $this->eventStore->commit();
     $this->eventStore->beginTransaction();
     $streamEvents = [UsernameChanged::with(['name' => 'John Doe'], 2)];
     $this->strategy->appendEvents(AggregateType::fromString("Product"), $aggregateId, $streamEvents, $user);
 }
Example #4
0
 /**
  * @test
  */
 public function it_returns_listener_events_when_listener_stops_loading_events_and_provide_loaded_events()
 {
     $stream = $this->getTestStream();
     $this->eventStore->beginTransaction();
     $this->eventStore->create($stream);
     $this->eventStore->commit();
     $streamEventWithMetadata = UsernameChanged::with(['new_name' => 'John Doe'], 2);
     $streamEventWithMetadata = $streamEventWithMetadata->withAddedMetadata('snapshot', true);
     $this->eventStore->beginTransaction();
     $this->eventStore->appendTo($stream->streamName(), [$streamEventWithMetadata]);
     $this->eventStore->commit();
     $this->eventStore->getActionEventEmitter()->attachListener('loadEventsByMetadataFrom.pre', function (ActionEvent $event) {
         $streamEventWithMetadataButOtherUuid = UsernameChanged::with(['new_name' => 'John Doe'], 1);
         $streamEventWithMetadataButOtherUuid = $streamEventWithMetadataButOtherUuid->withAddedMetadata('snapshot', true);
         $event->setParam('streamEvents', [$streamEventWithMetadataButOtherUuid]);
         $event->stopPropagation(true);
     });
     $loadedEvents = $this->eventStore->loadEventsByMetadataFrom($stream->streamName(), ['snapshot' => true]);
     $this->assertEquals(1, count($loadedEvents));
     $this->assertNotEquals($streamEventWithMetadata->uuid()->toString(), $loadedEvents[0]->uuid()->toString());
 }
 /**
  * @test
  */
 public function it_loads_events_from_min_version_on()
 {
     $this->adapter->create($this->getTestStream());
     $streamEvent1 = UsernameChanged::with(['name' => 'John Doe'], 2);
     $streamEvent1 = $streamEvent1->withAddedMetadata('tag', 'person');
     $streamEvent2 = UsernameChanged::with(['name' => 'Jane Doe'], 2);
     $streamEvent2 = $streamEvent2->withAddedMetadata('tag', 'person');
     $this->adapter->appendTo(new StreamName('Prooph\\Model\\User'), [$streamEvent1, $streamEvent2]);
     $stream = $this->adapter->load(new StreamName('Prooph\\Model\\User'), 2);
     $this->assertEquals('Prooph\\Model\\User', $stream->streamName()->toString());
     $this->assertEquals(2, count($stream->streamEvents()));
     $this->assertEquals('John Doe', $stream->streamEvents()[0]->payload()['name']);
     $this->assertEquals('Jane Doe', $stream->streamEvents()[1]->payload()['name']);
 }