Author: Alexander Miertsch (contact@prooph.de)
コード例 #1
0
 /**
  * @test
  */
 public function an_invokable_plugin_is_loaded_by_plugin_manager_and_attached_to_event_store_by_configuration()
 {
     $pluginManager = new ServiceManager(new Config(["invokables" => ["eventlogger" => EventLoggerPlugin::class]]));
     $eventStore = new EventStore(new InMemoryAdapter(), new ProophActionEventEmitter());
     $logger = $pluginManager->get('eventlogger');
     $logger->setUp($eventStore);
     $repository = new AggregateRepository($eventStore, AggregateType::fromAggregateRootClass('ProophTest\\EventStore\\Mock\\User'), new ConfigurableAggregateTranslator(), null, null, true);
     $eventStore->beginTransaction();
     $user = User::create("Alex", "*****@*****.**");
     $repository->addAggregateRoot($user);
     $eventStore->commit();
     $loggedStreamEvents = $pluginManager->get("eventlogger")->getLoggedStreamEvents();
     $this->assertEquals(1, count($loggedStreamEvents));
 }
コード例 #2
0
 /**
  * @test
  */
 public function it_translates_aggregate_back_and_forth()
 {
     $this->eventStore->beginTransaction();
     $user = User::nameNew('John Doe');
     $this->repository->addAggregateRoot($user);
     $this->eventStore->commit();
     $this->eventStore->beginTransaction();
     //Simulate a normal program flow by fetching the AR before modifying it
     $user = $this->repository->getAggregateRoot($user->id());
     $user->changeName('Max Mustermann');
     $this->eventStore->commit();
     $this->resetRepository();
     $loadedUser = $this->repository->getAggregateRoot($user->id());
     $this->assertEquals('Max Mustermann', $loadedUser->name());
     return $loadedUser;
 }
コード例 #3
0
 /**
  * @test
  */
 public function it_uses_snapshot_store_and_applies_pending_events()
 {
     $this->prepareSnapshotStoreAggregateRepository();
     $this->eventStore->beginTransaction();
     $user = User::create('John Doe', '*****@*****.**');
     $this->repository->addAggregateRoot($user);
     $this->eventStore->commit();
     $snapshot = new Snapshot(AggregateType::fromAggregateRootClass('ProophTest\\EventStore\\Mock\\User'), $user->getId()->toString(), $user, 1, new \DateTimeImmutable('now', new \DateTimeZone('UTC')));
     $this->snapshotStore->save($snapshot);
     $this->eventStore->beginTransaction();
     $fetchedUser = $this->repository->getAggregateRoot($user->getId()->toString());
     $fetchedUser->changeName('Max Mustermann');
     $this->eventStore->commit();
     $loadedEvents = [];
     $this->eventStore->getActionEventEmitter()->attachListener('loadEventsByMetadataFrom.post', function (ActionEvent $event) use(&$loadedEvents) {
         foreach ($event->getParam('streamEvents', []) as $streamEvent) {
             $loadedEvents[] = $streamEvent;
         }
         $event->getParam('streamEvents')->rewind();
     });
     $this->repository->getAggregateRoot($user->getId()->toString());
     $this->assertCount(1, $loadedEvents);
     $this->assertInstanceOf(UsernameChanged::class, $loadedEvents[0]);
     $this->assertEquals(2, $this->repository->extractAggregateVersion($fetchedUser));
 }
コード例 #4
0
 /**
  * @test
  */
 public function it_publishes_take_snapshot_commands_for_all_known_aggregates()
 {
     $inMemoryAdapter = new InMemoryAdapter();
     $eventEmitter = new ProophActionEventEmitter();
     $eventStore = new EventStore($inMemoryAdapter, $eventEmitter);
     $repository = new AggregateRepository($eventStore, AggregateType::fromAggregateRootClass('ProophTest\\EventStore\\Mock\\User'), new ConfigurableAggregateTranslator());
     $result = [];
     $router = new CommandRouter();
     $router->route(TakeSnapshot::class)->to(function (TakeSnapshot $command) use(&$result) {
         $result[] = ['aggregate_type' => $command->aggregateType(), 'aggregate_id' => $command->aggregateId()];
     });
     $commandBus = new CommandBus();
     $commandBus->utilize($router);
     $plugin = new SnapshotPlugin($commandBus, 2);
     $plugin->setUp($eventStore);
     $eventStore->beginTransaction();
     $eventStore->create(new Stream(new StreamName('event_stream'), new \ArrayIterator()));
     $eventStore->commit();
     $eventStore->beginTransaction();
     $user = User::create('Alex', '*****@*****.**');
     $repository->addAggregateRoot($user);
     $eventStore->commit();
     $eventStore->beginTransaction();
     $user = $repository->getAggregateRoot($user->getId()->toString());
     $user->changeName('John');
     $user->changeName('Jane');
     $user->changeName('Jim');
     $eventStore->commit();
     $eventStore->beginTransaction();
     $eventWithoutMetadata1 = UsernameChanged::with(['new_name' => 'John Doe'], 5);
     $eventWithoutMetadata2 = UsernameChanged::with(['new_name' => 'Jane Doe'], 6);
     $eventStore->appendTo(new StreamName('event_stream'), new \ArrayIterator([$eventWithoutMetadata1, $eventWithoutMetadata2]));
     $eventStore->commit();
     $this->assertCount(2, $result);
     $this->assertArrayHasKey('aggregate_type', $result[0]);
     $this->assertArrayHasKey('aggregate_id', $result[0]);
     $this->assertArrayHasKey('aggregate_type', $result[1]);
     $this->assertArrayHasKey('aggregate_id', $result[1]);
     $this->assertEquals(User::class, $result[0]['aggregate_type']);
     $this->assertEquals(User::class, $result[1]['aggregate_type']);
 }
コード例 #5
0
 /**
  * @test
  */
 public function it_publishes_take_snapshot_commands_by_event_name()
 {
     $this->eventStore->beginTransaction();
     $user = User::create('Alex', '*****@*****.**');
     $this->repository->addAggregateRoot($user);
     $this->eventStore->commit();
     $this->eventStore->beginTransaction();
     $user = $this->repository->getAggregateRoot($user->getId()->toString());
     $user->changeName('Jim');
     $this->eventStore->commit();
     $this->eventStore->beginTransaction();
     $eventWithoutMetadata1 = UsernameChanged::with(['new_name' => 'John Doe'], 5);
     $this->eventStore->appendTo(new StreamName('event_stream'), new \ArrayIterator([$eventWithoutMetadata1]));
     $this->eventStore->commit();
     $this->assertCount(1, $this->result);
     $this->assertArrayHasKey('aggregate_type', $this->result[0]);
     $this->assertArrayHasKey('aggregate_id', $this->result[0]);
     $this->assertEquals(User::class, $this->result[0]['aggregate_type']);
 }
コード例 #6
0
 /**
  * @test
  */
 public function it_returns_early_on_get_aggregate_root_when_there_are_no_stream_events()
 {
     $this->assertNull($this->repository->getAggregateRoot('something'));
 }
コード例 #7
0
 /**
  * @param EventStore $eventStore
  */
 public function __construct(EventStore $eventStore)
 {
     $aggregateType = AggregateType::fromAggregateRootClass('Prooph\\Processing\\Processor\\Process');
     parent::__construct($eventStore, new AggregateTranslator(), new SingleStreamStrategy($eventStore, 'prooph_processing_stream'), $aggregateType);
 }
コード例 #8
0
 /**
  * @param EventStore $eventStore
  */
 public function __construct(EventStore $eventStore)
 {
     parent::__construct($eventStore, new AggregateTranslator(), new SingleStreamStrategy($eventStore, 'link_process_manager_stream'), AggregateType::fromAggregateRootClass('Prooph\\Link\\ProcessManager\\Model\\MessageHandler'));
 }
コード例 #9
0
ファイル: EventStoreStoryLog.php プロジェクト: bweston92/done
 /**
  * @param EventStore $eventStore
  * @param string $storyLogStreamName
  * @param SnapshotStore $snapshotStore
  */
 public function __construct(EventStore $eventStore, $storyLogStreamName = 'prooph_story_stream', SnapshotStore $snapshotStore = null)
 {
     parent::__construct($eventStore, AggregateType::fromAggregateRootClass(Story::class), new AggregateTranslator(), new SingleStreamStrategy($eventStore, $storyLogStreamName), $snapshotStore);
 }
コード例 #10
0
ファイル: quickstart.php プロジェクト: prooph/event-sourcing
 public function __construct(EventStore $eventStore)
 {
     //We inject a Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator that can handle our AggregateRoots
     parent::__construct($eventStore, AggregateType::fromAggregateRootClass('My\\Model\\User'), new AggregateTranslator(), null, null, true);
 }
コード例 #11
0
 /**
  * @param EventStore $eventStore
  */
 public function __construct(EventStore $eventStore)
 {
     parent::__construct($eventStore, new AggregateTranslator(), new SingleStreamStrategy($eventStore, 'link_process_manager_stream'), AggregateType::fromAggregateRootClass(Task::class));
 }