public function testBuildIntIndex()
 {
     $builder = IntIndexQuery::builder($this->namespace, 'foobar', -1, -1)->withNamespace($this->namespace)->withIndexName('index-name')->withReturnTerms(true)->withMaxResults(20)->withTimeout(100)->withStart(0)->withEnd(10);
     $command = $builder->build();
     $query = $command->getQuery();
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakIndexQuery', $query);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\IntIndexQuery', $command);
     $this->assertEquals('index-name_int', $query->getIndexName());
     $this->assertSame($this->namespace, $query->getNamespace());
     $this->assertSame(20, $query->getMaxResults());
     $this->assertTrue($query->getReturnTerms());
     $this->assertSame(0, $query->getStart());
     $this->assertSame(10, $query->getEnd());
 }
 public function testSimpleIntIndexQueryRange()
 {
     $indexQuery = IntIndexQuery::builder()->withNamespace($this->namespace)->withIndexName('groups')->withReturnTerms(true)->withStart(2)->withEnd(3)->build();
     $result = $this->client->execute($indexQuery);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexQueryResponse', $result);
     $iterator = $result->getIterator();
     $values = iterator_to_array($iterator);
     $this->assertCount(4, $values);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values[0]);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values[1]);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values[2]);
     $this->assertInstanceOf('Riak\\Client\\Command\\Index\\Response\\IndexEntry', $values[3]);
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $values[0]->getLocation());
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $values[1]->getLocation());
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $values[2]->getLocation());
     $this->assertInstanceOf('Riak\\Client\\Core\\Query\\RiakLocation', $values[3]->getLocation());
     usort($values, function (IndexEntry $a, IndexEntry $b) {
         return strcmp($a->getLocation()->getKey(), $b->getLocation()->getKey());
     });
     $this->assertEquals('user1', $values[0]->getLocation()->getKey());
     $this->assertEquals('user2', $values[1]->getLocation()->getKey());
     $this->assertEquals('user2', $values[2]->getLocation()->getKey());
     $this->assertEquals('user3', $values[3]->getLocation()->getKey());
     usort($values, function (IndexEntry $a, IndexEntry $b) {
         return strcmp($a->getIndexKey(), $b->getIndexKey());
     });
     $this->assertEquals(2, $values[0]->getIndexKey());
     $this->assertEquals(2, $values[1]->getIndexKey());
     $this->assertEquals(3, $values[2]->getIndexKey());
     $this->assertEquals(3, $values[3]->getIndexKey());
 }