Пример #1
0
 public function setUp()
 {
     $inMemoryAdapter = new InMemoryAdapter();
     $eventEmitter = new ProophActionEventEmitter();
     $this->eventStore = new EventStore($inMemoryAdapter, $eventEmitter);
     $this->repository = new AggregateRepository($this->eventStore, AggregateType::fromAggregateRootClass('ProophTest\\EventStore\\Mock\\User'), new ConfigurableAggregateTranslator());
     $this->result = [];
     $self = $this;
     $router = new CommandRouter();
     $router->route(TakeSnapshot::class)->to(function (TakeSnapshot $command) use($self) {
         $self->result[] = ['aggregate_type' => $command->aggregateType(), 'aggregate_id' => $command->aggregateId()];
     });
     $commandBus = new CommandBus();
     $commandBus->utilize($router);
     $plugin = new SnapshotPlugin($commandBus, 2);
     $plugin->setUp($this->eventStore);
     $this->eventStore->beginTransaction();
     $this->eventStore->create(new Stream(new StreamName('event_stream'), new \ArrayIterator()));
     $this->eventStore->commit();
 }
Пример #2
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']);
 }