/**
  * @test
  */
 public function itCanSaveASnapshot()
 {
     $id = AggregateId::generate();
     $aggregate = AggregateRoot::create($id, 'test');
     $snapshot = Snapshot::take($id, $aggregate, '10');
     $expectedSerializedAggregate = sprintf('["serialized": "%s"]', spl_object_hash($snapshot));
     $expectedStorageArray = ['version' => '10', 'created_at' => $snapshot->getCreatedAt()->format('U.u'), 'snapshot' => ['type' => AggregateRoot::class, 'payload' => $expectedSerializedAggregate]];
     $expectedStoredData = '["version etc..."]';
     $this->serializer->serialize($aggregate, 'json')->willReturn($expectedSerializedAggregate)->shouldBeCalledTimes(1);
     $this->serializer->serialize($expectedStorageArray, 'json')->willReturn($expectedStoredData)->shouldBeCalledTimes(1);
     $this->client->hset(RedisSnapshotAdapter::KEY_NAMESPACE, (string) $id, $expectedStoredData)->shouldBeCalledTimes(1);
     $adapter = $this->createAdapter();
     $adapter->save($snapshot);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function save(Snapshot $snapshot)
 {
     $data = ['version' => $snapshot->getVersion(), 'created_at' => $snapshot->getCreatedAt()->format('U.u'), 'snapshot' => ['type' => $snapshot->getType(), 'payload' => $this->serializer->serialize($snapshot->getAggregate(), 'json')]];
     $this->redis->hset(static::KEY_NAMESPACE, (string) $snapshot->getAggregateId(), $this->serializer->serialize($data, 'json'));
 }
Esempio n. 3
0
 /**
  * @group redis-hashes
  */
 public function testHashExists()
 {
     $this->assertFalse($this->client->hexists('foo', 'hello'));
     $this->client->hset('foo', 'hello', 'world');
     $this->assertTrue($this->client->hexists('foo', 'hello'));
 }