/**
  * @test
  */
 public function aSnapshotCanBeRetrievedById()
 {
     $id = AggregateId::generate();
     $expectedAggregate = AggregateRoot::create($id, 'testing');
     $snapshotMetadata = ['version' => '15', 'created_at' => '1468847497.332610', 'snapshot' => ['type' => AggregateRoot::class, 'payload' => 'aggregate_data']];
     $this->mockRedisHasAndGetData($id, $snapshotMetadata);
     $this->serializer->deserialize('aggregate_data', AggregateRoot::class, 'json')->willReturn($expectedAggregate);
     $adapter = $this->createAdapter();
     $result = $adapter->byId($id);
     $this->assertInstanceOf(Snapshot::class, $result);
     $this->assertSame($id, $result->getAggregateId());
     $this->assertSame($expectedAggregate, $result->getAggregate());
     $this->assertSame('15', $result->getVersion());
     $this->assertSame('1468847497.332610', $result->getCreatedAt()->format('U.u'));
     $this->assertEquals(new \DateTimeZone('UTC'), $result->getCreatedAt()->getTimezone());
 }
 /**
  * @test
  * @dataProvider eventStoreProvider
  * @param $eventStoreAdapter
  * @param $snapshotAdapter
  */
 public function isShouldStoreEvents($eventStoreAdapter, $snapshotAdapter)
 {
     $locator = new InMemoryLocator();
     $commandBus = new SimpleCommandBus($locator);
     $eventBus = new SimpleEventBus();
     $eventStore = new EventStore($eventStoreAdapter);
     $snapshotStore = new SnapshotStore($snapshotAdapter);
     $snapshotter = new Snapshotter($snapshotStore, new CountSnapshotStrategy($eventStore, 5));
     $aggregateRepo = new AggregateRepository($eventStore, $eventBus, $snapshotter);
     $locator->addHandler(AssignNameCommand::class, new AssignNameHandler($aggregateRepo));
     $aggregateRoot = AggregateRoot::create(AggregateId::generate(), 'test1');
     $aggregateRepo->save($aggregateRoot);
     $command = new AssignNameCommand($aggregateRoot->getAggregateRootId(), 'test2');
     $commandBus->execute($command);
     $commandBus->execute($command);
     $commandBus->execute($command);
     $commandBus->execute($command);
     $this->assertEquals(6, $eventStore->countEventsFor(new StreamName('event_stream'), $aggregateRoot->getAggregateRootId()));
 }
 public function aggregateRootProvider()
 {
     return [[AggregateRoot::create(AggregateId::generate(), 'test1')]];
 }
示例#4
0
 public function messageProvider()
 {
     return [[AggregateId::generate(), AggregateRoot::create(AggregateId::generate(), 'v1000'), '1000', new \DateTimeImmutable()], [AggregateId::generate(), AggregateRoot::create(AggregateId::generate(), 'v1'), '1', \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)))]];
 }