9 Commits

Author SHA1 Message Date
EmanueleMinotto
2117eef3e3 Implement cassandra range query 2019-09-04 22:17:30 +02:00
EmanueleMinotto
ff58187a3b Upgrade doctrine/couchdb to include range query 2019-09-04 22:17:04 +02:00
EmanueleMinotto
e878a42d81 Add drivers to Travis 2019-09-04 22:16:08 +02:00
EmanueleMinotto
55f0840706 Use array as operation result 2019-09-04 22:15:56 +02:00
Emanuele Minotto
ac4c317a7e Merge pull request #92 from doctrine/fix-tests-for-maintainance
Fix storage tests for maintainance
2019-09-03 08:31:00 +02:00
EmanueleMinotto
705d5fc1d1 Add different versions support 2019-08-31 15:44:22 +02:00
EmanueleMinotto
465bd365f7 Remove HHVM support 2019-08-31 15:44:22 +02:00
EmanueleMinotto
9fb5e498ed Replace deprecated TestCase::getMock 2019-08-31 15:44:22 +02:00
EmanueleMinotto
573723ab3c Skip legacy Riak tests 2019-08-31 15:03:05 +02:00
9 changed files with 117 additions and 13 deletions

View File

@@ -1,17 +1,26 @@
language: php
services:
- cassandra
- couchdb
- mongodb
- redis-server
matrix:
include:
-
dist: precise
php: 5.5
php:
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2
- 7.3
before_install:
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TRAVIS_PHP_VERSION != "7.0" ]]; then sh ./tests/travis.sh; fi
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then sh ./tests/travis.sh; fi
- composer self-update
install:

View File

@@ -6,7 +6,7 @@
},
"require-dev": {
"datastax/php-driver": "^1.0",
"doctrine/couchdb": "^1.0.0-beta4",
"doctrine/couchdb": "^2.0@alpha",
"phpunit/phpunit": "^4.8|^5.0",
"aws/aws-sdk-php": "^3.8",
"riak/riak-client": "dev-master"

View File

@@ -202,7 +202,7 @@ class RangeQuery
/**
* Execute query and return a result iterator.
*
* @return ResultIterator
* @return array
*/
public function execute()
{

View File

@@ -29,14 +29,14 @@ namespace Doctrine\KeyValueStore\Query;
interface RangeQueryStorage
{
/**
* Execute the range query and return a ResultIterator
* Execute the range query and return an array
*
* @param RangeQuery $query
* @param string $storageName
* @param array $key
* @param Closure $hydrateRow
*
* @return ResultIterator
* @return array
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
}

View File

@@ -23,6 +23,8 @@ namespace Doctrine\KeyValueStore\Storage;
use Cassandra\ExecutionOptions;
use Cassandra\Session;
use Doctrine\KeyValueStore\NotFoundException;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
/**
* Cassandra Storage Engine for KeyValueStore.
@@ -31,7 +33,7 @@ use Doctrine\KeyValueStore\NotFoundException;
*
* @uses https://github.com/datastax/php-driver
*/
class CassandraStorage implements Storage
class CassandraStorage implements Storage, RangeQueryStorage
{
/**
* @var \Cassandra\Session
@@ -176,6 +178,13 @@ class CassandraStorage implements Storage
return $data;
}
/**
* {@inheritDoc}
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
{
}
/**
* {@inheritDoc}
*/

View File

@@ -21,6 +21,9 @@
namespace Doctrine\KeyValueStore\Storage;
use Doctrine\CouchDB\CouchDBClient;
use Doctrine\CouchDB\Mango\MangoQuery;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
/**
* Key-Value-Storage using a Doctrine CouchDB Client library as backend.
@@ -30,7 +33,7 @@ use Doctrine\CouchDB\CouchDBClient;
*
* @author Emanuele Minotto <minottoemanuele@gmail.com>
*/
final class CouchDbStorage implements Storage
final class CouchDbStorage implements Storage, RangeQueryStorage
{
/**
* @var CouchDBClient
@@ -116,7 +119,7 @@ final class CouchDbStorage implements Storage
/**
* @param string $storageName
* @param array|string $key
*
*
* @return string
*/
private function flattenKey($storageName, $key)
@@ -137,4 +140,72 @@ final class CouchDbStorage implements Storage
return $finalKey;
}
/**
* {@inheritDoc}
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
{
$mangoQuery = new MangoQuery();
$partitionKey = $query->getPartitionKey();
$conditions = [];
foreach ($query->getConditions() as $condition) {
switch ($condition[0]) {
case RangeQuery::CONDITION_LE:
$conditions[] = [
$partitionKey => [
'$lte' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_GE:
$conditions[] = [
$partitionKey => [
'$gte' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_NEQ:
$conditions[] = [
$partitionKey => [
'$ne' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_STARTSWITH:
$conditions[] = [
$partitionKey => [
'$regex' => '^'.$condition[1],
],
];
break;
default:
$conditions[] = [
$partitionKey => [
'$'.$condition[0] => $condition[1],
],
];
break;
}
}
$mangoQuery
->select(['_id', $key])
->where(['$and' => $conditions])
->limit($query->getLimit());
$results = [];
$mangoResults = $this->client->find($query);
foreach ($mangoResults as $mangoResult) {
$results[] = $hydrateRow($mangoResult);
}
return $results;
}
}

View File

@@ -33,7 +33,10 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->mongo = $this->getMock('\Mongo');
$this->mongo = $this
->getMockBuilder('\Mongo')
->disableOriginalConstructor()
->getMock();
$this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock();

View File

@@ -39,6 +39,10 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
protected function setup()
{
if (PHP_MAJOR_VERSION >= 7) {
$this->markTestSkipped('Riak extension is not available for PHP versions >= 7');
}
$this->riak = $this->getMockBuilder('Riak\\Client')
->disableOriginalConstructor()
->getMock();

View File

@@ -20,7 +20,9 @@
namespace Doctrine\Tests\KeyValueStore\Storage;
use Doctrine\KeyValueStore\Http\Client;
use Doctrine\KeyValueStore\Http\Response;
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage;
class WindowsAzureTableStorageTest extends AbstractStorageTestCase
@@ -29,8 +31,14 @@ class WindowsAzureTableStorageTest extends AbstractStorageTestCase
protected function createStorage()
{
$this->client = $this->getMock('Doctrine\KeyValueStore\Http\Client');
$auth = $this->getMock('Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema');
$this->client = $this
->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
$auth = $this
->getMockBuilder(AuthorizationSchema::class)
->disableOriginalConstructor()
->getMock();
$auth->expects($this->any())->method('signRequest')->will($this->returnValue('Authorization: SharedKeyLite testaccount1:uay+rilMVayH/SVI8X+a3fL8k/NxCnIePdyZSkqvydM='));
$storage = new WindowsAzureTableStorage(