5 Commits

Author SHA1 Message Date
Emanuele Minotto 6faf449755 Include code coverage (with coveralls) 2016-07-09 12:52:30 +02:00
Emanuele Minotto 5ecca2e0e2 Force coding style 2016-07-09 12:51:59 +02:00
Emanuele Minotto 22af505cac Remove notifications 2016-07-09 12:51:30 +02:00
Emanuele Minotto 16c1bc3d3d Use travis cache 2016-07-09 12:51:14 +02:00
Emanuele Minotto 5e6144a852 Fixed coding style 2016-07-09 12:50:45 +02:00
11 changed files with 36 additions and 126 deletions
+18 -13
View File
@@ -1,30 +1,35 @@
language: php language: php
services: services:
- cassandra
- couchdb
- mongodb - mongodb
- redis-server - redis-server
matrix: cache:
include: directories:
- - $HOME/.composer/cache
dist: precise
php: 5.5
php: php:
- 5.5
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1 - hhvm
- 7.2
- 7.3
before_install: before_install:
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then sh ./tests/travis.sh; fi - if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TRAVIS_PHP_VERSION != "7.0" ]]; then sh ./tests/travis.sh; fi
- composer self-update - composer self-update
install: install:
- composer --prefer-source install - composer require satooshi/php-coveralls:~0.6@stable --no-update
- composer install --prefer-dist --no-interaction --no-progress
before_script:
- vendor/bin/php-cs-fixer -v fix --diff --dry-run
script: script:
- vendor/bin/phpunit --verbose - vendor/bin/phpunit --verbose --coverage-text --coverage-clover=coverage.clover
after_script:
- if [[ $TRAVIS_PHP_VERSION != "5.6" && $TRAVIS_PULL_REQUEST == "false" ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
notifications:
email: false
+3 -2
View File
@@ -6,10 +6,11 @@
}, },
"require-dev": { "require-dev": {
"datastax/php-driver": "^1.0", "datastax/php-driver": "^1.0",
"doctrine/couchdb": "^2.0@alpha", "doctrine/couchdb": "^1.0.0-beta4",
"phpunit/phpunit": "^4.8|^5.0", "phpunit/phpunit": "^4.8|^5.0",
"aws/aws-sdk-php": "^3.8", "aws/aws-sdk-php": "^3.8",
"riak/riak-client": "dev-master" "riak/riak-client": "dev-master",
"friendsofphp/php-cs-fixer": "^1.11"
}, },
"suggest": { "suggest": {
"aws/aws-sdk-php": "to use the DynamoDB storage", "aws/aws-sdk-php": "to use the DynamoDB storage",
@@ -202,7 +202,7 @@ class RangeQuery
/** /**
* Execute query and return a result iterator. * Execute query and return a result iterator.
* *
* @return array * @return ResultIterator
*/ */
public function execute() public function execute()
{ {
@@ -29,14 +29,14 @@ namespace Doctrine\KeyValueStore\Query;
interface RangeQueryStorage interface RangeQueryStorage
{ {
/** /**
* Execute the range query and return an array * Execute the range query and return a ResultIterator
* *
* @param RangeQuery $query * @param RangeQuery $query
* @param string $storageName * @param string $storageName
* @param array $key * @param array $key
* @param Closure $hydrateRow * @param Closure $hydrateRow
* *
* @return array * @return ResultIterator
*/ */
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null); public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
} }
@@ -20,7 +20,6 @@
namespace Doctrine\KeyValueStore\Storage; namespace Doctrine\KeyValueStore\Storage;
use Doctrine\DBAL\Connection;
use Doctrine\KeyValueStore\NotFoundException; use Doctrine\KeyValueStore\NotFoundException;
/** /**
@@ -79,7 +78,7 @@ class ArrayStorage implements Storage
*/ */
public function update($storageName, $key, array $data) public function update($storageName, $key, array $data)
{ {
if (!isset($this->data[$storageName])) { if (! isset($this->data[$storageName])) {
$this->data[$storageName] = []; $this->data[$storageName] = [];
} }
@@ -93,11 +92,11 @@ class ArrayStorage implements Storage
*/ */
public function delete($storageName, $key) public function delete($storageName, $key)
{ {
if (!isset($this->data[$storageName])) { if (! isset($this->data[$storageName])) {
return; return;
} }
if (!isset($this->data[$storageName][serialize($key)])) { if (! isset($this->data[$storageName][serialize($key)])) {
return; return;
} }
@@ -113,11 +112,11 @@ class ArrayStorage implements Storage
*/ */
public function find($storageName, $key) public function find($storageName, $key)
{ {
if (!isset($this->data[$storageName])) { if (! isset($this->data[$storageName])) {
throw new NotFoundException(); throw new NotFoundException();
} }
if (!isset($this->data[$storageName][serialize($key)])) { if (! isset($this->data[$storageName][serialize($key)])) {
throw new NotFoundException(); throw new NotFoundException();
} }
@@ -23,8 +23,6 @@ namespace Doctrine\KeyValueStore\Storage;
use Cassandra\ExecutionOptions; use Cassandra\ExecutionOptions;
use Cassandra\Session; use Cassandra\Session;
use Doctrine\KeyValueStore\NotFoundException; use Doctrine\KeyValueStore\NotFoundException;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
/** /**
* Cassandra Storage Engine for KeyValueStore. * Cassandra Storage Engine for KeyValueStore.
@@ -33,7 +31,7 @@ use Doctrine\KeyValueStore\Query\RangeQueryStorage;
* *
* @uses https://github.com/datastax/php-driver * @uses https://github.com/datastax/php-driver
*/ */
class CassandraStorage implements Storage, RangeQueryStorage class CassandraStorage implements Storage
{ {
/** /**
* @var \Cassandra\Session * @var \Cassandra\Session
@@ -178,13 +176,6 @@ class CassandraStorage implements Storage, RangeQueryStorage
return $data; return $data;
} }
/**
* {@inheritDoc}
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
{
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@@ -21,9 +21,6 @@
namespace Doctrine\KeyValueStore\Storage; namespace Doctrine\KeyValueStore\Storage;
use Doctrine\CouchDB\CouchDBClient; 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. * Key-Value-Storage using a Doctrine CouchDB Client library as backend.
@@ -33,7 +30,7 @@ use Doctrine\KeyValueStore\Query\RangeQueryStorage;
* *
* @author Emanuele Minotto <minottoemanuele@gmail.com> * @author Emanuele Minotto <minottoemanuele@gmail.com>
*/ */
final class CouchDbStorage implements Storage, RangeQueryStorage final class CouchDbStorage implements Storage
{ {
/** /**
* @var CouchDBClient * @var CouchDBClient
@@ -119,7 +116,7 @@ final class CouchDbStorage implements Storage, RangeQueryStorage
/** /**
* @param string $storageName * @param string $storageName
* @param array|string $key * @param array|string $key
* *
* @return string * @return string
*/ */
private function flattenKey($storageName, $key) private function flattenKey($storageName, $key)
@@ -140,72 +137,4 @@ final class CouchDbStorage implements Storage, RangeQueryStorage
return $finalKey; 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;
}
} }
@@ -183,7 +183,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$tableNode->appendChild($dom->createTextNode($tableName)); $tableNode->appendChild($dom->createTextNode($tableName));
$xml = $dom->saveXML(); $xml = $dom->saveXML();
$url = $this->baseUrl . '/Tables'; $url = $this->baseUrl . '/Tables';
$response = $this->request('POST', $url, $xml, $headers); $response = $this->request('POST', $url, $xml, $headers);
if ($response->getStatusCode() != 201) { if ($response->getStatusCode() != 201) {
@@ -33,10 +33,7 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp() protected function setUp()
{ {
$this->mongo = $this $this->mongo = $this->getMock('\Mongo');
->getMockBuilder('\Mongo')
->disableOriginalConstructor()
->getMock();
$this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock(); $this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock();
@@ -39,10 +39,6 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
protected function setup() 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') $this->riak = $this->getMockBuilder('Riak\\Client')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -20,9 +20,7 @@
namespace Doctrine\Tests\KeyValueStore\Storage; namespace Doctrine\Tests\KeyValueStore\Storage;
use Doctrine\KeyValueStore\Http\Client;
use Doctrine\KeyValueStore\Http\Response; use Doctrine\KeyValueStore\Http\Response;
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage; use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage;
class WindowsAzureTableStorageTest extends AbstractStorageTestCase class WindowsAzureTableStorageTest extends AbstractStorageTestCase
@@ -31,14 +29,8 @@ class WindowsAzureTableStorageTest extends AbstractStorageTestCase
protected function createStorage() protected function createStorage()
{ {
$this->client = $this $this->client = $this->getMock('Doctrine\KeyValueStore\Http\Client');
->getMockBuilder(Client::class) $auth = $this->getMock('Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema');
->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=')); $auth->expects($this->any())->method('signRequest')->will($this->returnValue('Authorization: SharedKeyLite testaccount1:uay+rilMVayH/SVI8X+a3fL8k/NxCnIePdyZSkqvydM='));
$storage = new WindowsAzureTableStorage( $storage = new WindowsAzureTableStorage(