public function testCreateHeaders()
 {
     $indexes = ['foo_bin' => ['bar', 'baz'], 'foo_int' => [42, 50]];
     $translator = new Api\Translators\SecondaryIndexHeaderTranslator();
     $headers = $translator->createHeadersFromIndexes($indexes);
     // Check that 4 different header key/value pairs are created, with the correct values.
     $this->assertEquals(4, count($headers));
     $this->assertEquals(['x-riak-index-foo_bin', 'bar'], $headers[0]);
     $this->assertEquals(['x-riak-index-foo_bin', 'baz'], $headers[1]);
     $this->assertEquals(['x-riak-index-foo_int', '42'], $headers[2]);
     $this->assertEquals(['x-riak-index-foo_int', '50'], $headers[3]);
 }
示例#2
0
 private function validateIndexNameAndValue($indexName, $value)
 {
     if (!is_scalar($value)) {
         throw new \InvalidArgumentException("Invalid index type for '" . $indexName . "'index. Expecting '*_int' for an integer index, or '*_bin' for a string index.");
     }
     $isIntIndex = SecondaryIndexHeaderTranslator::isIntIndex($indexName);
     $isStringIndex = SecondaryIndexHeaderTranslator::isStringIndex($indexName);
     if (!$isIntIndex && !$isStringIndex) {
         throw new \InvalidArgumentException("Invalid index type for '" . $indexName . "'index. Expecting '*_int' for an integer index, or '*_bin' for a string index.");
     }
     if ($isIntIndex && !is_int($value)) {
         throw new \InvalidArgumentException("Invalid type for '" . $indexName . "'index. Expecting 'integer', value was '" . gettype($value) . "''");
     }
     if ($isStringIndex && !is_string($value)) {
         throw new \InvalidArgumentException("Invalid type for '" . $indexName . "'index. Expecting 'string', value was '" . gettype($value) . "''");
     }
 }