/**
* @test
*/
public function it_saves_and_reads()
{
$schema = new Schema();
SnapshotStoreSchema::create($schema, 'foo_snapshot');
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeQuery($sql);
}
$adapter = new DoctrineSnapshotAdapter($this->connection);
$aggregateType = AggregateType::fromString('foo');
$aggregateRoot = new \stdClass();
$aggregateRoot->foo = 'bar';
$time = microtime(true);
if (false === strpos($time, '.')) {
$time .= '.0000';
}
$now = \DateTimeImmutable::createFromFormat('U.u', $time);
$snapshot = new Snapshot($aggregateType, 'id', $aggregateRoot, 1, $now);
$adapter->save($snapshot);
$snapshot = new Snapshot($aggregateType, 'id', $aggregateRoot, 2, $now);
$adapter->save($snapshot);
$this->assertNull($adapter->get($aggregateType, 'invalid'));
$readSnapshot = $adapter->get($aggregateType, 'id');
$this->assertEquals($snapshot, $readSnapshot);
$statement = $this->connection->prepare('SELECT * FROM foo_snapshot');
$statement->execute();
$snapshots = $statement->fetchAll();
$this->assertCount(1, $snapshots);
}