public function testSiblingsWithIndexes()
 {
     $key = uniqid();
     $object1 = new RiakObject();
     $object2 = new RiakObject();
     $location = new RiakLocation(new RiakNamespace('default', 'bucket'), $key);
     $object1->addIndex(new RiakIndexBin('group', ['guest']));
     $object1->setContentType('application/json');
     $object1->setValue('{"name": "fabio"}');
     $object2->addIndex(new RiakIndexBin('group', ['admin']));
     $object2->setContentType('application/json');
     $object2->setValue('{"name": "fabio"}');
     $this->client->execute(StoreValue::builder($location, $object1)->withW(3)->build());
     $this->client->execute(StoreValue::builder($location, $object2)->withW(3)->build());
     $result = $this->client->execute(FetchValue::builder($location)->withNotFoundOk(true)->withR(1)->build());
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result);
     $this->assertCount(2, $result->getValues());
     $riakObject1 = $result->getValues()->offsetGet(0);
     $riakObject2 = $result->getValues()->offsetGet(1);
     $riakIndexes1 = $riakObject1->getIndexes();
     $riakIndexes2 = $riakObject2->getIndexes();
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexList', $riakIndexes1);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexList', $riakIndexes2);
     $this->assertCount(1, $riakIndexes1);
     $this->assertTrue(isset($riakIndexes1['group']));
     $this->assertTrue(isset($riakIndexes2['group']));
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexBin', $riakIndexes1['group']);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Index\\RiakIndexBin', $riakIndexes2['group']);
     $this->assertEquals('group', $riakIndexes1['group']->getName());
     $this->assertEquals('group', $riakIndexes2['group']->getName());
     $this->assertEquals(['guest'], $riakIndexes1['group']->getValues());
     $this->assertEquals(['admin'], $riakIndexes2['group']->getValues());
     $this->client->execute(DeleteValue::builder($location)->build());
 }
 /**
  * {@inheritdoc}
  */
 public function fromDomain(DomainObjectReference $reference)
 {
     $riakObject = new RiakObject();
     $location = $reference->getLocation();
     $domainObject = $reference->getDomainObject();
     $riakObjectValue = $this->fromDomainObject($domainObject);
     $riakObject->setValue($riakObjectValue);
     $this->domainHydrator->setRiakObjectValues($riakObject, $domainObject, $location);
     return $riakObject;
 }
 public function testToDomain()
 {
     $riakObject = new RiakObject();
     $domainObject = new SimpleObject('[1,2,3]');
     $namespace = new RiakNamespace('type', 'bucket');
     $location = new RiakLocation($namespace, 'riak-key');
     $reference = new RiakObjectReference($riakObject, $location, SimpleObject::CLASS_NAME);
     $riakObject->setValue('{"value":[1,2,3]}');
     $this->instance->expects($this->once())->method('toDomainObject')->with($this->equalTo('{"value":[1,2,3]}'), $this->equalTo(SimpleObject::CLASS_NAME))->willReturn($domainObject);
     $this->hydrator->expects($this->once())->method('setDomainObjectValues')->with($this->equalTo($domainObject), $this->equalTo($riakObject), $this->equalTo($location));
     $this->assertSame($domainObject, $this->instance->toDomain($reference));
 }
 /**
  * @param \Riak\Client\Core\Query\RiakObject   $riakObject
  * @param object                               $domainObject
  * @param \Riak\Client\Core\Query\RiakLocation $location
  */
 public function setRiakObjectValues(RiakObject $riakObject, $domainObject, RiakLocation $location)
 {
     $className = get_class($domainObject);
     $metadata = $this->metadataReader->getMetadataFor($className);
     if ($vClockField = $metadata->getRiakVClockField()) {
         $riakObject->setVClock($this->getDomainObjectProperty($domainObject, $vClockField));
     }
     if ($lastModifiedField = $metadata->getRiakLastModifiedField()) {
         $riakObject->setLastModified($this->getDomainObjectProperty($domainObject, $lastModifiedField));
     }
     if ($contentTypeField = $metadata->getRiakContentTypeField()) {
         $riakObject->setContentType($this->getDomainObjectProperty($domainObject, $contentTypeField));
     }
 }
 public function testHidrateDomainObject()
 {
     $riakObject = new RiakObject();
     $domainObject = new SimpleObject();
     $vClock = new VClock('vclock-hash');
     $namespace = new RiakNamespace('type', 'bucket');
     $location = new RiakLocation($namespace, 'riak-key');
     $riakObject->setVClock($vClock);
     $riakObject->setContentType('application/json');
     $riakObject->setLastModified('Sat, 01 Jan 2015 01:01:01 GMT');
     $this->instance->setDomainObjectValues($domainObject, $riakObject, $location);
     $this->assertEquals('Sat, 01 Jan 2015 01:01:01 GMT', $domainObject->getRiakLastModified());
     $this->assertEquals('application/json', $domainObject->getRiakContentType());
     $this->assertEquals('bucket', $domainObject->getRiakBucketName());
     $this->assertEquals('type', $domainObject->getRiakBucketType());
     $this->assertEquals('riak-key', $domainObject->getRiakKey());
     $this->assertEquals($vClock, $domainObject->getRiakVClock());
 }
 public function testResponseConverter()
 {
     $object = new RiakObject();
     $vClock = new VClock('vclock-hash');
     $list = new RiakObjectList([$object]);
     $instance = $this->getMockForAbstractClass('Riak\\Client\\Command\\Kv\\Response\\ObjectResponse', [$this->converterFactory, $this->resolverFactory, $this->location, $list]);
     $object->setVClock($vClock);
     $object->setVClock('{"value":[1,1,1]}');
     $object->setContentType('application/json');
     $riakObjectList = $instance->getValues();
     $domainObjectList = $instance->getValues(SimpleObject::CLASS_NAME);
     $riakObject = $instance->getValue();
     $domainObject = $instance->getValue(SimpleObject::CLASS_NAME);
     $this->assertCount(1, $riakObjectList);
     $this->assertCount(1, $domainObjectList);
     $this->assertInstanceOf(SimpleObject::CLASS_NAME, $domainObject);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $riakObject);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObjectList', $riakObjectList);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\DomainObjectList', $domainObjectList);
 }
 /**
  * @param \Riak\Client\Core\Query\RiakObject $riakObject
  *
  * @return array
  */
 public function convertToRiakContent(RiakObject $riakObject)
 {
     $content = new Content();
     $metas = $riakObject->getUserMeta();
     $indexes = $riakObject->getIndexes();
     $links = $riakObject->getLinks();
     $content->contentType = $riakObject->getContentType() ?: RiakObject::DEFAULT_CONTENT_TYPE;
     $content->lastModified = $riakObject->getLastModified();
     $content->isDeleted = $riakObject->getIsDeleted();
     $content->value = $riakObject->getValue();
     $content->vtag = $riakObject->getVtag();
     $content->indexes = [];
     $content->metas = [];
     if ($indexes != null) {
         $content->indexes = $indexes->toFullNameArray();
     }
     if ($metas != null) {
         $content->metas = $metas->toArray();
     }
     if ($links != null) {
         $content->links = $links->toArray();
     }
     return $content;
 }
 public function testObjectWithLinks()
 {
     $object = new RiakObject();
     $object->setValue('{"name": "fabio"}');
     $object->setContentType('application/json');
     $object->addLink(new RiakLink(null, null, null));
     $object->addLink(new RiakLink(null, null, null));
     $object->getLinks()->get(0)->setBucket('bucket');
     $object->getLinks()->get(0)->setKey('first');
     $object->getLinks()->get(0)->setTag('foo');
     $object->getLinks()->get(1)->setBucket('bucket');
     $object->getLinks()->get(1)->setKey('second');
     $object->getLinks()->get(1)->setTag('bar');
     $store = StoreValue::builder($this->location, $object)->withPw(1)->withW(1)->build();
     $fetch = FetchValue::builder($this->location)->withR(1)->build();
     $this->client->execute($store);
     $result = $this->client->execute($fetch);
     $riakObject = $result->getValue();
     $riakLinks = $riakObject->getLinks();
     $this->assertFalse($result->getNotFound());
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\FetchValueResponse', $result);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLinkList', $riakLinks);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakObject', $riakObject);
     $this->assertEquals('{"name": "fabio"}', $riakObject->getValue());
     $this->assertCount(2, $riakLinks);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLink', $riakLinks[0]);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\Link\\RiakLink', $riakLinks[1]);
     $this->assertEquals('bucket', $riakLinks[0]->getBucket());
     $this->assertEquals('bucket', $riakLinks[1]->getBucket());
     $this->assertEquals('first', $riakLinks[0]->getKey());
     $this->assertEquals('second', $riakLinks[1]->getKey());
     $this->assertEquals('foo', $riakLinks[0]->getTag());
     $this->assertEquals('bar', $riakLinks[1]->getTag());
     $this->client->execute(DeleteValue::builder($this->location)->build());
 }
 public function testListKeys()
 {
     $key = uniqid();
     $object = new RiakObject();
     $namespace = new RiakNamespace('default', 'bucket');
     $location = new RiakLocation($namespace, $key);
     $object->setValue('[1,1,1]');
     $object->setContentType('application/json');
     $this->client->execute(StoreValue::builder($location, $object)->withPw(RiakOption::ALL)->withW(RiakOption::ALL)->withReturnBody(true)->build());
     $command = ListKeys::builder($namespace)->withNamespace($namespace)->build();
     $result = $this->client->execute($command);
     $iterator = $result->getIterator();
     $locations = [];
     $this->assertInternalType('array', $locations);
     $this->assertInstanceOf('Iterator', $iterator);
     $this->assertInstanceOf('Riak\\Client\\Command\\Kv\\Response\\ListKeysResponse', $result);
     foreach ($result->getLocations() as $location) {
         $locations[$location->getKey()] = $location;
     }
     $this->assertArrayHasKey($key, $locations);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $locations[$key]);
     $this->assertEquals($namespace, $locations[$key]->getNamespace());
     $this->assertEquals($key, $locations[$key]->getKey());
 }