mirror of
https://github.com/doctrine/KeyValueStore.git
synced 2026-03-24 08:42:12 +01:00
Compare commits
9 Commits
v0.4.0
...
tests/refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2b752033f | ||
|
|
eaa95e0e96 | ||
|
|
90d29ad6c7 | ||
|
|
66864cbbee | ||
|
|
02cb83edd1 | ||
|
|
8f17913f4b | ||
|
|
cf6bd490f4 | ||
|
|
18e9faf50d | ||
|
|
aeb6db5d98 |
26
.travis.yml
26
.travis.yml
@@ -1,37 +1,17 @@
|
||||
language: php
|
||||
|
||||
services:
|
||||
- docker
|
||||
- mongodb
|
||||
- redis-server
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
-
|
||||
key_url: 'https://packagecloud.io/gpg.key'
|
||||
sourceline: 'deb https://packagecloud.io/basho/riak/ubuntu/ trusty main'
|
||||
-
|
||||
key_url: 'https://packagecloud.io/gpg.key'
|
||||
sourceline: 'deb-src https://packagecloud.io/basho/riak/ubuntu/ trusty main'
|
||||
update: true
|
||||
|
||||
cache:
|
||||
apt: true
|
||||
- hhvm
|
||||
|
||||
before_install:
|
||||
- docker run -d -p 8000:8000 amazon/dynamodb-local
|
||||
- sudo apt-get install -y --allow-unauthenticated riak
|
||||
- sudo service riak start
|
||||
- pecl install --force mongodb
|
||||
- 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
|
||||
|
||||
install:
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# Upgrade to 0.3
|
||||
|
||||
## BC Break: Fixed MongoDB storage usage
|
||||
|
||||
Before v0.3 the storage name associated to a class wasn't used when the storage is `MongoDbStorage`.
|
||||
In order to be consistent with other storage drivers, the `storageName` is now used for the collection name when storing and data.
|
||||
To get the same behavior as in older versions, pass the collection name given in the constructor arguments as storage name.
|
||||
@@ -9,13 +9,13 @@
|
||||
"doctrine/couchdb": "^1.0.0-beta4",
|
||||
"phpunit/phpunit": "^4.8|^5.0",
|
||||
"aws/aws-sdk-php": "^3.8",
|
||||
"php-riak/riak-client": "^1.0@alpha",
|
||||
"mongodb/mongodb": "^1.4"
|
||||
"riak/riak-client": "dev-master"
|
||||
},
|
||||
"suggest": {
|
||||
"aws/aws-sdk-php": "to use the DynamoDB storage",
|
||||
"doctrine/couchdb": "to use the CouchDB storage",
|
||||
"ext-couchbase": "to use the Couchbase storage"
|
||||
"ext-couchbase": "to use the Couchbase storage",
|
||||
"riak/riak-client": "to use the Riak storage"
|
||||
},
|
||||
"description": "Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.",
|
||||
"license": "MIT",
|
||||
@@ -26,7 +26,8 @@
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Tests\\": "tests/Doctrine/Tests"
|
||||
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
|
||||
"Doctrine\\KeyValueStore\\": "tests/Doctrine/KeyValueStore"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ This guide covers getting started with the Doctrine Key Value Store.
|
||||
|
||||
To use the KeyValueStore you actually need:
|
||||
|
||||
- PHP 5.6 or above
|
||||
- PHP 5.5 or above
|
||||
- Composer Package Manager (`Install Composer
|
||||
<http://getcomposer.org/doc/00-intro.md>`_)
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ So far the following drivers exist (and are documented here):
|
||||
* Microsoft Windows Azure Table
|
||||
* Couchbase
|
||||
* CouchDB
|
||||
* DynamoDB
|
||||
* MongoDB
|
||||
* Riak
|
||||
|
||||
@@ -210,42 +209,51 @@ See the `AWS docs <http://docs.aws.amazon.com/amazondynamodb/latest/developergui
|
||||
|
||||
<?php
|
||||
|
||||
$client = DynamoDbClient::factory([...])
|
||||
$sdk = new \Aws\Sdk([...]);
|
||||
$client = $sdk->createDynamoDb();
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage = new DynamoDbStorage(
|
||||
$client,
|
||||
// Optional key name, defaults to Id.
|
||||
null,
|
||||
// Optional table name/ key name pairs.
|
||||
// This example uses a table called Awesome keyed by MyKey.
|
||||
['storage_keys' => ['Awesome' => 'MyKey']]
|
||||
);
|
||||
|
||||
MongoDB
|
||||
-------
|
||||
|
||||
MongoDB is based on `mongodb/mongodb <https://github.com/mongodb/mongo-php-library>`_:
|
||||
MongoDB support is provided using a `Database <https://docs.mongodb.com/php-library/current/reference/class/MongoDBDatabase/>`_
|
||||
instance.
|
||||
Mongo support is provided using a `Mongo <http://php.net/manual/en/class.mongo.php>`_
|
||||
instance, the collection name and the database name.
|
||||
|
||||
Both the options ``collection`` and ``database`` are required.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use MongoDB\Client;
|
||||
use Doctrine\KeyValueStore\Storage\MongoDbStorage;
|
||||
|
||||
$client = new Client(/* connection parameters and options */);
|
||||
$conn = new \Mongo(/* connection parameters and options */);
|
||||
|
||||
$storage = new MongoDbStorage($client->your_database);
|
||||
$storage = new MongoDbStorage($conn, array(
|
||||
'collection' => 'your_collection',
|
||||
'database' => 'your_database',
|
||||
));
|
||||
|
||||
Riak
|
||||
----
|
||||
|
||||
Riak support is provided through the library `php-riak/riak-client <https://github.com/php-riak/riak-client>`_ :
|
||||
Riak support is provided through the library `riak/riak-client <https://github.com/nacmartin/riak-client>`_ :
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\RiakStorage;
|
||||
use Riak\Client\RiakClientBuilder;
|
||||
use Riak\Client;
|
||||
|
||||
$conn = (new RiakClientBuilder())
|
||||
->withNodeUri(/* connection DNS */)
|
||||
->build();
|
||||
$conn = new Riak(/* connection parameters */);
|
||||
|
||||
$storage = new RiakStorage($conn);
|
||||
|
||||
@@ -34,88 +34,98 @@ use Doctrine\KeyValueStore\Id\NullIdConverter;
|
||||
class Configuration
|
||||
{
|
||||
/**
|
||||
* @param array
|
||||
* @var null|MappingDriver
|
||||
*/
|
||||
private $config;
|
||||
private $mappingDriver;
|
||||
|
||||
/**
|
||||
* @var null|Cache
|
||||
*/
|
||||
private $metadataCache;
|
||||
|
||||
/**
|
||||
* @var null|IdConverterStrategy
|
||||
*/
|
||||
private $idConverter;
|
||||
|
||||
/**
|
||||
* Get mapping driver implementation used with this configuration.
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
|
||||
* @return MappingDriver
|
||||
*/
|
||||
public function getMappingDriverImpl()
|
||||
{
|
||||
if (! isset($this->config['mappingDriver'])) {
|
||||
if (! isset($this->mappingDriver)) {
|
||||
throw KeyValueStoreException::mappingDriverMissing();
|
||||
}
|
||||
|
||||
return $this->config['mappingDriver'];
|
||||
return $this->mappingDriver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mapping driver implementation.
|
||||
*
|
||||
* @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver
|
||||
* @param MappingDriver $driver
|
||||
*
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setMappingDriverImpl(MappingDriver $driver)
|
||||
{
|
||||
$this->config['mappingDriver'] = $driver;
|
||||
$this->mappingDriver = $driver;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Metadata Mapping cache used with this configuration.
|
||||
*
|
||||
* @param \Doctrine\Common\Cache\Cache $cache
|
||||
* @param Cache $cache
|
||||
*
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setMetadataCache(Cache $cache)
|
||||
{
|
||||
$this->config['metadataCache'] = $cache;
|
||||
$this->metadataCache = $cache;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata mapping cache used with this configuration.
|
||||
*
|
||||
* @return \Doctrine\Common\Cache\Cache $cache
|
||||
* @return Cache
|
||||
*/
|
||||
public function getMetadataCache()
|
||||
{
|
||||
if (! isset($this->config['metadataCache'])) {
|
||||
$this->config['metadataCache'] = new ArrayCache();
|
||||
if (! isset($this->metadataCache)) {
|
||||
$this->metadataCache = new ArrayCache();
|
||||
}
|
||||
|
||||
return $this->config['metadataCache'];
|
||||
return $this->metadataCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ID Converter Strategy
|
||||
*
|
||||
* @param \Doctrine\KeyValueStore\Id\IdConverterStrategy
|
||||
* @param IdConverterStrategy $strategy
|
||||
*
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setIdConverterStrategy(IdConverterStrategy $strategy)
|
||||
{
|
||||
$this->config['idConverter'] = $strategy;
|
||||
$this->idConverter = $strategy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Id Converter strategy
|
||||
*
|
||||
* @return \Doctrine\KeyValueStore\Id\IdConverterStrategy
|
||||
* @return IdConverterStrategy
|
||||
*/
|
||||
public function getIdConverterStrategy()
|
||||
{
|
||||
if (! isset($this->config['idConverter'])) {
|
||||
$this->config['idConverter'] = new NullIdConverter();
|
||||
if (! isset($this->idConverter)) {
|
||||
$this->idConverter = new NullIdConverter();
|
||||
}
|
||||
|
||||
return $this->config['idConverter'];
|
||||
return $this->idConverter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,14 +45,14 @@ class EntityManager
|
||||
* Create a new EntityManager
|
||||
*
|
||||
* @param Storage $storageDriver
|
||||
* @param Configuration $config
|
||||
* @param Configuration $configuration
|
||||
*/
|
||||
public function __construct(Storage $storageDriver, Configuration $config)
|
||||
public function __construct(Storage $storageDriver, Configuration $configuration)
|
||||
{
|
||||
$cmf = new ClassMetadataFactory($config->getMappingDriverImpl());
|
||||
$cmf->setCacheDriver($config->getMetadataCache());
|
||||
$classMetadataFactory = new ClassMetadataFactory($configuration->getMappingDriverImpl());
|
||||
$classMetadataFactory->setCacheDriver($configuration->getMetadataCache());
|
||||
|
||||
$this->unitOfWork = new UnitOfWork($cmf, $storageDriver, $config);
|
||||
$this->unitOfWork = new UnitOfWork($classMetadataFactory, $storageDriver, $configuration);
|
||||
$this->storageDriver = $storageDriver;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class EntityManager
|
||||
* @param string $className
|
||||
* @param string $partitionKey
|
||||
*
|
||||
* @return \Doctrine\KeyValueStore\Query\RangeQuery
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function createRangeQuery($className, $partitionKey)
|
||||
{
|
||||
@@ -124,13 +124,16 @@ class EntityManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\KeyValueStore\UnitOfWork
|
||||
* @return UnitOfWork
|
||||
*/
|
||||
public function getUnitOfWork()
|
||||
{
|
||||
return $this->unitOfWork;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UnitOfWork::clear()
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return $this->unitOfWork->clear();
|
||||
|
||||
@@ -21,35 +21,50 @@
|
||||
namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class CompositeIdHandler implements IdHandlingStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function normalizeId(ClassMetadata $metadata, $key)
|
||||
{
|
||||
if (! $metadata->isCompositeKey && ! is_array($key)) {
|
||||
$id = [$metadata->identifier[0] => $key];
|
||||
} elseif (! is_array($key)) {
|
||||
throw new \InvalidArgumentException('Array of identifier key-value pairs is expected!');
|
||||
} else {
|
||||
$id = [];
|
||||
foreach ($metadata->identifier as $field) {
|
||||
if (! isset($key[$field])) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Missing identifier field $field in request for the primary key."
|
||||
);
|
||||
}
|
||||
$id[$field] = $key[$field];
|
||||
return [
|
||||
$metadata->identifier[0] => $key,
|
||||
];
|
||||
}
|
||||
|
||||
if (! is_array($key)) {
|
||||
throw new InvalidArgumentException('Array of identifier key-value pairs is expected!');
|
||||
}
|
||||
|
||||
$id = [];
|
||||
|
||||
foreach ($metadata->identifier as $field) {
|
||||
if (! isset($key[$field])) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Missing identifier field %s in request for the primary key.', $field)
|
||||
);
|
||||
}
|
||||
$id[$field] = $key[$field];
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getIdentifier(ClassMetadata $metadata, $object)
|
||||
{
|
||||
return $metadata->getIdentifierValues($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hash($key)
|
||||
{
|
||||
return implode('__##__', (array) $key);
|
||||
|
||||
@@ -31,6 +31,23 @@ namespace Doctrine\KeyValueStore\Id;
|
||||
*/
|
||||
interface IdConverterStrategy
|
||||
{
|
||||
/**
|
||||
* Serialize data for the persistence.
|
||||
*
|
||||
* @param string $class
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize($class, $data);
|
||||
|
||||
/**
|
||||
* Unserialize data from the persistence system.
|
||||
*
|
||||
* @param string $class
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function unserialize($class, $data);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,17 @@ namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
class NullIdConverter implements IdConverterStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function serialize($class, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function unserialize($class, $data)
|
||||
{
|
||||
return $data;
|
||||
|
||||
@@ -24,6 +24,9 @@ use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
|
||||
class SingleIdHandler implements IdHandlingStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function normalizeId(ClassMetadata $metadata, $key)
|
||||
{
|
||||
if (is_scalar($key)) {
|
||||
@@ -34,12 +37,18 @@ class SingleIdHandler implements IdHandlingStrategy
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getIdentifier(ClassMetadata $metadata, $object)
|
||||
{
|
||||
$values = $metadata->getIdentifierValues($object);
|
||||
return $values[$metadata->identifier[0]];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hash($key)
|
||||
{
|
||||
return $key;
|
||||
|
||||
@@ -21,8 +21,12 @@
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations\Entity;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations\Id;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations\Transient;
|
||||
use ReflectionClass;
|
||||
|
||||
class AnnotationDriver implements MappingDriver
|
||||
{
|
||||
@@ -46,19 +50,19 @@ class AnnotationDriver implements MappingDriver
|
||||
/**
|
||||
* Loads the metadata for the specified class into the provided container.
|
||||
*
|
||||
* @param string $className
|
||||
* @param ClassMetadata $metadata
|
||||
* @param string $className
|
||||
* @param CommonClassMetadata $metadata
|
||||
*/
|
||||
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
|
||||
{
|
||||
$class = $metadata->getReflectionClass();
|
||||
if (! $class) {
|
||||
// this happens when running annotation driver in combination with
|
||||
// static reflection services. This is not the nicest fix
|
||||
$class = new \ReflectionClass($metadata->name);
|
||||
$class = new ReflectionClass($metadata->name);
|
||||
}
|
||||
|
||||
$entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\KeyValueStore\Mapping\Annotations\Entity');
|
||||
$entityAnnot = $this->reader->getClassAnnotation($class, Entity::class);
|
||||
if (! $entityAnnot) {
|
||||
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
}
|
||||
@@ -66,21 +70,26 @@ class AnnotationDriver implements MappingDriver
|
||||
|
||||
// Evaluate annotations on properties/fields
|
||||
foreach ($class->getProperties() as $property) {
|
||||
$idAnnot = $this->reader->getPropertyAnnotation(
|
||||
$property,
|
||||
'Doctrine\KeyValueStore\Mapping\Annotations\Id'
|
||||
);
|
||||
$transientAnnot = $this->reader->getPropertyAnnotation(
|
||||
$property,
|
||||
'Doctrine\KeyValueStore\Mapping\Annotations\Transient'
|
||||
);
|
||||
$idAnnot = $this->reader->getPropertyAnnotation($property, Id::class);
|
||||
if ($idAnnot) {
|
||||
$metadata->mapIdentifier($property->getName());
|
||||
} elseif ($transientAnnot) {
|
||||
$metadata->skipTransientField($property->getName());
|
||||
} else {
|
||||
$metadata->mapField(['fieldName' => $property->getName()]);
|
||||
|
||||
// if it's an identifier, can't be also a transient
|
||||
// nor a mapped field
|
||||
continue;
|
||||
}
|
||||
|
||||
$transientAnnot = $this->reader->getPropertyAnnotation($property, Transient::class);
|
||||
if ($transientAnnot) {
|
||||
$metadata->skipTransientField($property->getName());
|
||||
|
||||
// if it's a transiend, can't be also a mapped field
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata->mapField([
|
||||
'fieldName' => $property->getName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +100,7 @@ class AnnotationDriver implements MappingDriver
|
||||
*/
|
||||
public function getAllClassNames()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,37 +25,91 @@ use ReflectionClass;
|
||||
|
||||
class ClassMetadata implements BaseClassMetadata
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
public $storageName;
|
||||
public $rootClassName;
|
||||
public $fields = [];
|
||||
public $identifier = [];
|
||||
public $isCompositeKey = false;
|
||||
public $transientFields = [];
|
||||
public $reflFields = [];
|
||||
public $reflClass;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $storageName;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fields = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $identifier = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $isCompositeKey = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $transientFields = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $reflFields = [];
|
||||
|
||||
/**
|
||||
* @var null|mixed
|
||||
*/
|
||||
private $prototype;
|
||||
|
||||
public function __construct($className)
|
||||
/**
|
||||
* @param string|object $class
|
||||
*/
|
||||
public function __construct($class)
|
||||
{
|
||||
$this->name = $className;
|
||||
if (is_object($class)) {
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
$class = $reflectionClass->getName();
|
||||
}
|
||||
|
||||
$this->name = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a mapped identifier.
|
||||
*
|
||||
* @param string $fieldName
|
||||
*/
|
||||
public function mapIdentifier($fieldName)
|
||||
{
|
||||
$this->identifier[] = $fieldName;
|
||||
$this->isCompositeKey = count($this->identifier) > 1;
|
||||
$this->mapField(['fieldName' => $fieldName, 'id' => true]);
|
||||
$this->mapField([
|
||||
'fieldName' => $fieldName,
|
||||
'id' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function mapField($mapping)
|
||||
/**
|
||||
* Add a mapped field.
|
||||
*
|
||||
* @param array $mapping
|
||||
*/
|
||||
public function mapField(array $mapping)
|
||||
{
|
||||
if (! isset($this->transientFields[$mapping['fieldName']])) {
|
||||
$this->fields[$mapping['fieldName']] = $mapping;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a transient field.
|
||||
*
|
||||
* @param string $fieldName
|
||||
*/
|
||||
public function skipTransientField($fieldName)
|
||||
{
|
||||
// it's necessary to unset because ClassMetadataFactory::initializeReflection has already run
|
||||
@@ -78,21 +132,29 @@ class ClassMetadata implements BaseClassMetadata
|
||||
return clone $this->prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return ['fields', 'isCompositeKey', 'identifier', 'name', 'storageName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identifiers values.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIdentifierValues($object)
|
||||
{
|
||||
$id = [];
|
||||
foreach ($this->identifier as $field) {
|
||||
$value = $this->reflFields[$field]->getValue($object);
|
||||
if ($value !== null) {
|
||||
$id[$field] = $value;
|
||||
}
|
||||
}
|
||||
return $id;
|
||||
$instance = $object ?: $this->newInstance();
|
||||
|
||||
return array_intersect_key(
|
||||
get_object_vars($instance),
|
||||
array_flip($this->identifier)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata as KeyValueMetadata;
|
||||
|
||||
/**
|
||||
* Load Metadata of an entity.
|
||||
@@ -33,17 +32,29 @@ use Doctrine\KeyValueStore\Mapping\ClassMetadata as KeyValueMetadata;
|
||||
*/
|
||||
class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
{
|
||||
/**
|
||||
* @var MappingDriver
|
||||
*/
|
||||
private $mappingDriver;
|
||||
|
||||
/**
|
||||
* @param MappingDriver $driver
|
||||
*/
|
||||
public function __construct(MappingDriver $driver)
|
||||
{
|
||||
$this->mappingDriver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
|
||||
{
|
||||
throw new \InvalidArgumentException('aliasing is not supported.');
|
||||
@@ -68,17 +79,26 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function newClassMetadataInstance($className)
|
||||
{
|
||||
return new KeyValueMetadata($className);
|
||||
return new ClassMetadata($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getDriver()
|
||||
{
|
||||
return $this->mappingDriver;
|
||||
}
|
||||
|
||||
protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function wakeupReflection(CommonClassMetadata $class, ReflectionService $reflService)
|
||||
{
|
||||
$class->reflClass = $reflService->getClass($class->name);
|
||||
foreach ($class->fields as $fieldName => $mapping) {
|
||||
@@ -86,20 +106,28 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
}
|
||||
}
|
||||
|
||||
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function initializeReflection(CommonClassMetadata $class, ReflectionService $reflService)
|
||||
{
|
||||
$class->reflClass = $reflService->getClass($class->name);
|
||||
if ($class->reflClass) {
|
||||
foreach ($class->reflClass->getProperties() as $property) {
|
||||
$class->mapField(['fieldName' => $property->getName()]);
|
||||
}
|
||||
|
||||
if (! $class->reflClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($class->reflClass->getProperties() as $property) {
|
||||
$class->mapField([
|
||||
'fieldName' => $property->getName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* copied from doctrine/common - tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function isEntity(ClassMetadata $class)
|
||||
protected function isEntity(CommonClassMetadata $class)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Doctrine\KeyValueStore\Mapping;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
|
||||
use Doctrine\Common\Persistence\Mapping\MappingException;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
class XmlDriver extends FileDriver
|
||||
{
|
||||
@@ -70,14 +72,14 @@ class XmlDriver extends FileDriver
|
||||
try {
|
||||
$xmlRoot = $this->getElement($className);
|
||||
} catch (MappingException $exception) {
|
||||
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
throw new InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
}
|
||||
|
||||
if ($xmlRoot->getName() != 'entity') {
|
||||
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
throw new InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($className);
|
||||
$class = new ReflectionClass($className);
|
||||
|
||||
if (isset($xmlRoot['storage-name'])) {
|
||||
$metadata->storageName = $xmlRoot['storage-name'];
|
||||
|
||||
@@ -73,6 +73,11 @@ class RangeQuery
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param string $className
|
||||
* @param string $partitionKey
|
||||
*/
|
||||
public function __construct(EntityManager $em, $className, $partitionKey)
|
||||
{
|
||||
$this->em = $em;
|
||||
@@ -80,21 +85,33 @@ class RangeQuery
|
||||
$this->partitionKey = $partitionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set query limit.
|
||||
*
|
||||
* @param int $limit
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function setLimit($limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query results limit.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLimit()
|
||||
{
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get className.
|
||||
* Get class name.
|
||||
*
|
||||
* @return className.
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
@@ -102,9 +119,9 @@ class RangeQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* Get partitionKey.
|
||||
* Get partition key.
|
||||
*
|
||||
* @return partitionKey.
|
||||
* @return string
|
||||
*/
|
||||
public function getPartitionKey()
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
@@ -79,7 +78,7 @@ class ArrayStorage implements Storage
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
if (!isset($this->data[$storageName])) {
|
||||
if (! isset($this->data[$storageName])) {
|
||||
$this->data[$storageName] = [];
|
||||
}
|
||||
|
||||
@@ -93,11 +92,11 @@ class ArrayStorage implements Storage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
if (!isset($this->data[$storageName])) {
|
||||
if (! isset($this->data[$storageName])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->data[$storageName][serialize($key)])) {
|
||||
if (! isset($this->data[$storageName][serialize($key)])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,11 +112,11 @@ class ArrayStorage implements Storage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
if (!isset($this->data[$storageName])) {
|
||||
if (! isset($this->data[$storageName])) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!isset($this->data[$storageName][serialize($key)])) {
|
||||
if (! isset($this->data[$storageName][serialize($key)])) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,13 @@ use WindowsAzure\Table\TableRestProxy;
|
||||
class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
/**
|
||||
* @var \WindowsAzure\Table\TableRestProxy
|
||||
* @var TableRestProxy
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @param TableRestProxy $client
|
||||
*/
|
||||
public function __construct(TableRestProxy $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
@@ -151,6 +154,11 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
return $this->getProperties($result->getEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getProperties(Entity $entity)
|
||||
{
|
||||
$properties = [];
|
||||
@@ -205,6 +213,11 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function quoteFilterValue($value)
|
||||
{
|
||||
return "'" . str_replace("'", '', $value) . "'";
|
||||
@@ -216,7 +229,7 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
* @param array $key
|
||||
* @param array $data
|
||||
*
|
||||
* @return \WindowsAzure\Table\Model\Entity
|
||||
* @return Entity
|
||||
*/
|
||||
private function createEntity(array $key, array $data)
|
||||
{
|
||||
@@ -236,6 +249,10 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
/**
|
||||
* Infer the property type of variables.
|
||||
*
|
||||
* @param mixed $propertyValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getPropertyType($propertyValue)
|
||||
{
|
||||
|
||||
@@ -34,10 +34,13 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
class CassandraStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Cassandra\Session
|
||||
* @var Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param Session $session
|
||||
*/
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Couchbase;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
@@ -28,16 +29,16 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
class CouchbaseStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Couchbase
|
||||
* @var Couchbase
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Couchbase $couchbase
|
||||
* @param Couchbase $couchbase
|
||||
*/
|
||||
public function __construct(\Couchbase $couchbase)
|
||||
public function __construct(Couchbase $couchbase)
|
||||
{
|
||||
$this->client = $couchbase;
|
||||
}
|
||||
|
||||
@@ -32,11 +32,32 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
*/
|
||||
class DBALStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $keyColumn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dataColumn;
|
||||
|
||||
/**
|
||||
* @param Connection $conn
|
||||
* @param string $table
|
||||
* @param string $keyColumn
|
||||
* @param string $dataColumn
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $conn,
|
||||
$table = 'storage',
|
||||
@@ -49,15 +70,16 @@ class DBALStorage implements Storage
|
||||
$this->dataColumn = $dataColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage support composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
@@ -65,9 +87,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage require composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
@@ -75,10 +95,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the storage key specified.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
@@ -92,10 +109,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data into the given key.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
@@ -110,9 +124,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
@@ -123,11 +135,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Find data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
*
|
||||
* @return array
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
@@ -150,9 +158,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
|
||||
@@ -33,33 +33,55 @@ use Doctrine\Common\Cache\Cache;
|
||||
class DoctrineCacheStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var Doctrine\Common\Cache\Cache
|
||||
* @var Cache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsCompositeKeys;
|
||||
|
||||
/**
|
||||
* @param Cache $cache
|
||||
* @param bool $supportsCompositeKeys
|
||||
*/
|
||||
public function __construct(Cache $cache, $supportsCompositeKeys = true)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->supportsCompositeKeys = $supportsCompositeKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
return $this->supportsCompositeKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function flattenKey($storageName, $key)
|
||||
{
|
||||
if (! $this->supportsCompositeKeys) {
|
||||
@@ -74,30 +96,45 @@ class DoctrineCacheStorage implements Storage
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->cache->save($key, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->cache->save($key, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->cache->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
return $this->cache->fetch($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'doctrine_cache';
|
||||
|
||||
@@ -22,21 +22,40 @@ namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use Aws\DynamoDb\Marshaler;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\KeyValueStore\InvalidArgumentException;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* DynamoDb storage.
|
||||
* DyanmoDb storage
|
||||
*
|
||||
* @author Stan Lemon <stosh1985@gmail.com>
|
||||
*/
|
||||
class DynamoDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var DynamoDbClient
|
||||
* The key that DynamoDb uses to indicate the name of the table.
|
||||
*/
|
||||
private $client;
|
||||
const TABLE_NAME_KEY = 'TableName';
|
||||
|
||||
/**
|
||||
* The key that DynamoDb uses to indicate whether or not to do a consistent read.
|
||||
*/
|
||||
const CONSISTENT_READ_KEY = 'ConsistentRead';
|
||||
|
||||
/**
|
||||
* The key that is used to refer to the DynamoDb table key.
|
||||
*/
|
||||
const TABLE_KEY = 'Key';
|
||||
|
||||
/**
|
||||
* The key that is used to refer to the marshaled item for DynamoDb table.
|
||||
*/
|
||||
const TABLE_ITEM_KEY = 'Item';
|
||||
|
||||
/**
|
||||
* @var \Aws\DynamoDb\DynamoDbClient
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var Marshaler
|
||||
@@ -44,27 +63,158 @@ class DynamoDbStorage implements Storage
|
||||
private $marshaler;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
* @var string
|
||||
*/
|
||||
private $descriptionCache;
|
||||
private $defaultKeyName = 'Id';
|
||||
|
||||
/**
|
||||
* @param DynamoDbClient $client The client for connecting to AWS DynamoDB
|
||||
* @param Marshaler|null $marshaler (optional) Marshaller for converting data to/from DynamoDB format
|
||||
* @param Cache|null $descriptionCache Cache used to store tables description
|
||||
* A associative array where the key is the table name and the value is the name of the key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tableKeys = [];
|
||||
|
||||
/**
|
||||
* @param DynamoDbClient $client The client for connecting to AWS DynamoDB.
|
||||
* @param Marshaler|null $marshaler (optional) Marshaller for converting data to/from DynamoDB format.
|
||||
* @param string $defaultKeyName (optional) Default name to use for keys.
|
||||
* @param array $tableKeys $tableKeys (optional) An associative array for keys representing table names and values
|
||||
* representing key names for those tables.
|
||||
*/
|
||||
public function __construct(
|
||||
DynamoDbClient $client,
|
||||
Marshaler $marshaler = null,
|
||||
Cache $descriptionCache = null
|
||||
DynamoDbClient $client,
|
||||
Marshaler $marshaler = null,
|
||||
$defaultKeyName = null,
|
||||
array $tableKeys = []
|
||||
) {
|
||||
$this->client = $client;
|
||||
$this->client = $client;
|
||||
$this->marshaler = $marshaler ?: new Marshaler();
|
||||
$this->descriptionCache = $descriptionCache ?: new ArrayCache();
|
||||
|
||||
if ($defaultKeyName !== null) {
|
||||
$this->setDefaultKeyName($defaultKeyName);
|
||||
}
|
||||
|
||||
foreach ($tableKeys as $table => $keyName) {
|
||||
$this->setKeyForTable($table, $keyName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Validates a DynamoDB key name.
|
||||
*
|
||||
* @param $name mixed The name to validate.
|
||||
*
|
||||
* @throws InvalidArgumentException When the key name is invalid.
|
||||
*/
|
||||
private function validateKeyName($name)
|
||||
{
|
||||
if (! is_string($name)) {
|
||||
throw InvalidArgumentException::invalidType('key', 'string', $name);
|
||||
}
|
||||
|
||||
$len = strlen($name);
|
||||
if ($len > 255 || $len < 1) {
|
||||
throw InvalidArgumentException::invalidLength('name', 1, 255);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a DynamoDB table name.
|
||||
*
|
||||
* @see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html
|
||||
*
|
||||
* @param $name string The table name to validate.
|
||||
*
|
||||
* @throws InvalidArgumentException When the name is invalid.
|
||||
*/
|
||||
private function validateTableName($name)
|
||||
{
|
||||
if (! is_string($name)) {
|
||||
throw InvalidArgumentException::invalidType('key', 'string', $name);
|
||||
}
|
||||
|
||||
if (! preg_match('/^[a-z0-9_.-]{3,255}$/i', $name)) {
|
||||
throw InvalidArgumentException::invalidTableName($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default key name for storage tables.
|
||||
*
|
||||
* @param $name string The default name to use for the key.
|
||||
*
|
||||
* @throws InvalidArgumentException When the key name is invalid.
|
||||
*/
|
||||
private function setDefaultKeyName($name)
|
||||
{
|
||||
$this->validateKeyName($name);
|
||||
$this->defaultKeyName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default key name.
|
||||
*
|
||||
* @return string The default key name.
|
||||
*/
|
||||
public function getDefaultKeyName()
|
||||
{
|
||||
return $this->defaultKeyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a key name for a specific table.
|
||||
*
|
||||
* @param $table string The name of the table.
|
||||
* @param $key string The name of the string.
|
||||
*
|
||||
* @throws InvalidArgumentException When the key or table name is invalid.
|
||||
*/
|
||||
private function setKeyForTable($table, $key)
|
||||
{
|
||||
$this->validateTableName($table);
|
||||
$this->validateKeyName($key);
|
||||
$this->tableKeys[$table] = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a specific name for a key for a given table. The default is returned if this table does not have
|
||||
* an actual override.
|
||||
*
|
||||
* @param string $tableName The name of the table.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getKeyNameForTable($tableName)
|
||||
{
|
||||
return isset($this->tableKeys[$tableName]) ?
|
||||
$this->tableKeys[$tableName] :
|
||||
$this->defaultKeyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a key to be in a valid format for lookups for DynamoDB. If passing an array, that means that the key
|
||||
* is the name of the key and the value is the actual value for the lookup.
|
||||
*
|
||||
* @param string $storageName Table name.
|
||||
* @param string $key Key name.
|
||||
*
|
||||
* @return array The key in DynamoDB format.
|
||||
*/
|
||||
private function prepareKey($storageName, $key)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
$keyValue = reset($key);
|
||||
$keyName = key($key);
|
||||
} else {
|
||||
$keyValue = $key;
|
||||
$keyName = $this->getKeyNameForTable($storageName);
|
||||
}
|
||||
|
||||
return $this->marshaler->marshalItem([$keyName => $keyValue]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
@@ -72,7 +222,7 @@ class DynamoDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
@@ -80,7 +230,7 @@ class DynamoDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
@@ -88,107 +238,83 @@ class DynamoDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a key to be in a valid format for lookups for DynamoDB. If passing an array, that means that the key
|
||||
* is the name of the key and the value is the actual value for the lookup.
|
||||
*
|
||||
* @param string $storageName Table name
|
||||
* @param array|string $key Key name
|
||||
*
|
||||
* @return array The key in DynamoDB format
|
||||
*/
|
||||
private function prepareKey($storageName, $key)
|
||||
{
|
||||
if (! $this->descriptionCache->contains($storageName)) {
|
||||
$result = $this->client->describeTable([
|
||||
'TableName' => $storageName,
|
||||
]);
|
||||
|
||||
$keys = isset($result['Table']['KeySchema'])
|
||||
? $result['Table']['KeySchema']
|
||||
: [];
|
||||
$keys = array_column($keys, 'AttributeName') ?: [];
|
||||
|
||||
$this->descriptionCache->save($storageName, $keys);
|
||||
}
|
||||
|
||||
$keys = isset($keys) ? $keys : $this->descriptionCache->fetch($storageName);
|
||||
$keys = array_combine($keys, array_fill(0, (count($keys) - 1) ?: 1, $key));
|
||||
|
||||
if (!is_array($key)) {
|
||||
$key = [
|
||||
$storageName => $key,
|
||||
];
|
||||
}
|
||||
|
||||
$keys = array_intersect_assoc($keys, $key) ?: $keys;
|
||||
|
||||
return $this->marshaler->marshalItem($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$this->client->putItem([
|
||||
'TableName' => $storageName,
|
||||
'Item' => $this->prepareKey($storageName, $key) + $this->marshaler->marshalItem($data),
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::TABLE_ITEM_KEY => $this->prepareKey($storageName, $key) + $this->marshaler->marshalItem($this->prepareData($data)),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
// we are using PUT so we just replace the original item, if the key
|
||||
// does not exist, it will be created.
|
||||
$this->insert($storageName, $key, $data);
|
||||
//We are using PUT so we just replace the original item, if the key
|
||||
//does not exist, it will be created.
|
||||
$this->insert($storageName, $key, $this->prepareData($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$this->client->deleteItem([
|
||||
'Key' => $this->prepareKey($storageName, $key),
|
||||
'TableName' => $storageName,
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::TABLE_KEY => $this->prepareKey($storageName, $key),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$keys = $this->prepareKey($storageName, $key);
|
||||
|
||||
$item = $this->client->getItem([
|
||||
'ConsistentRead' => true,
|
||||
'Key' => $keys,
|
||||
'TableName' => $storageName,
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::CONSISTENT_READ_KEY => true,
|
||||
self::TABLE_KEY => $this->prepareKey($storageName, $key),
|
||||
]);
|
||||
|
||||
if (! $item->hasKey('Item')) {
|
||||
if (! $item) {
|
||||
throw NotFoundException::notFoundByKey($key);
|
||||
}
|
||||
|
||||
$item = $item->get('Item');
|
||||
$item = $item->get(self::TABLE_ITEM_KEY);
|
||||
|
||||
$result = $this->marshaler->unmarshalItem($item);
|
||||
$result = array_diff_key($result, $keys);
|
||||
|
||||
return $result;
|
||||
return $this->marshaler->unmarshalItem($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'dynamodb';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data by removing empty item attributes.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareData($data)
|
||||
{
|
||||
$callback = function ($value) {
|
||||
return $value !== null && $value !== [] && $value !== '';
|
||||
};
|
||||
|
||||
foreach ($data as &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->prepareData($value);
|
||||
}
|
||||
}
|
||||
return array_filter($data, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use MongoDB\Database;
|
||||
use Mongo;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* MongoDb storage
|
||||
@@ -31,16 +32,57 @@ use MongoDB\Database;
|
||||
class MongoDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var Database
|
||||
* @var Mongo
|
||||
*/
|
||||
private $database;
|
||||
protected $mongo;
|
||||
|
||||
/**
|
||||
* @param Database $database
|
||||
* @var array
|
||||
*/
|
||||
public function __construct(Database $database)
|
||||
protected $dbOptions;
|
||||
|
||||
/**
|
||||
* @var \MongoCollection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Mongo $mongo
|
||||
* @param array $dbOptions
|
||||
*/
|
||||
public function __construct(Mongo $mongo, array $dbOptions = [])
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->mongo = $mongo;
|
||||
$this->dbOptions = array_merge([
|
||||
'database' => '',
|
||||
'collection' => '',
|
||||
], $dbOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the mongodb collection
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
if (null !== $this->collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($this->dbOptions['database'])) {
|
||||
throw new RuntimeException('The option "database" must be set');
|
||||
}
|
||||
if (empty($this->dbOptions['collection'])) {
|
||||
throw new RuntimeException('The option "collection" must be set');
|
||||
}
|
||||
|
||||
$this->collection = $this
|
||||
->mongo
|
||||
->selectDB($this->dbOptions['database'])
|
||||
->selectCollection($this->dbOptions['collection']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,12 +114,14 @@ class MongoDbStorage implements Storage
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$this->database
|
||||
->selectCollection($storageName)
|
||||
->insertOne([
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
]);
|
||||
$this->initialize();
|
||||
|
||||
$value = [
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
];
|
||||
|
||||
$this->collection->insert($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,14 +129,14 @@ class MongoDbStorage implements Storage
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$this->database
|
||||
->selectCollection($storageName)
|
||||
->replaceOne([
|
||||
'key' => $key,
|
||||
], [
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
]);
|
||||
$this->initialize();
|
||||
|
||||
$value = [
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
];
|
||||
|
||||
$this->collection->update(['key' => $key], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,11 +144,9 @@ class MongoDbStorage implements Storage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$this->database
|
||||
->selectCollection($storageName)
|
||||
->deleteOne([
|
||||
'key' => $key,
|
||||
]);
|
||||
$this->initialize();
|
||||
|
||||
$this->collection->remove(['key' => $key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,29 +154,19 @@ class MongoDbStorage implements Storage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$result = $this->database
|
||||
->selectCollection($storageName, [
|
||||
'typeMap' => [
|
||||
'array' => 'array',
|
||||
'document' => 'array',
|
||||
'root' => 'array',
|
||||
],
|
||||
])
|
||||
->findOne([
|
||||
'key' => $key,
|
||||
]);
|
||||
$this->initialize();
|
||||
|
||||
if (! $result || ! $result['value']) {
|
||||
throw new NotFoundException();
|
||||
$value = $this->collection->findOne(['key' => $key], ['value']);
|
||||
|
||||
if ($value) {
|
||||
return $value['value'];
|
||||
}
|
||||
|
||||
return $result['value'];
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Redis;
|
||||
|
||||
/**
|
||||
* @author Marcel Araujo <admin@marcelaraujo.me>
|
||||
@@ -28,7 +29,7 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
class RedisStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Redis
|
||||
* @var Redis
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
@@ -47,10 +48,10 @@ class RedisStorage implements Storage
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Redis $redis
|
||||
* @param array $dbOptions
|
||||
* @param Redis $redis
|
||||
* @param array $dbOptions
|
||||
*/
|
||||
public function __construct($redis, $dbOptions = [])
|
||||
public function __construct(Redis $redis, $dbOptions = [])
|
||||
{
|
||||
$this->client = $redis;
|
||||
|
||||
@@ -126,9 +127,7 @@ class RedisStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
|
||||
@@ -21,14 +21,7 @@
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Riak\Client\Command\Kv\DeleteValue;
|
||||
use Riak\Client\Command\Kv\FetchValue;
|
||||
use Riak\Client\Command\Kv\StoreValue;
|
||||
use Riak\Client\Core\Query\RiakLocation;
|
||||
use Riak\Client\Core\Query\RiakNamespace;
|
||||
use Riak\Client\Core\Query\RiakObject;
|
||||
use Riak\Client\RiakClient;
|
||||
use Riak\Client\RiakException;
|
||||
use Riak\Client;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
@@ -36,11 +29,14 @@ use Riak\Client\RiakException;
|
||||
class RiakStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var RiakClient
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
protected $client;
|
||||
|
||||
public function __construct(RiakClient $riak)
|
||||
/**
|
||||
* @param Client $riak
|
||||
*/
|
||||
public function __construct(Client $riak)
|
||||
{
|
||||
$this->client = $riak;
|
||||
}
|
||||
@@ -69,25 +65,14 @@ class RiakStorage implements Storage
|
||||
return false;
|
||||
}
|
||||
|
||||
private function store($storageName, $key, array $data)
|
||||
{
|
||||
$location = $this->getRiakLocation($storageName, $key);
|
||||
|
||||
$riakObject = new RiakObject();
|
||||
$riakObject->setContentType('application/json');
|
||||
$riakObject->setValue(json_encode($data));
|
||||
|
||||
$store = StoreValue::builder($location, $riakObject)->build();
|
||||
|
||||
$this->client->execute($store);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$this->store($storageName, $key, $data);
|
||||
$bucket = $this->client->bucket($storageName);
|
||||
$object = $bucket->newObject($key, $data);
|
||||
$object->store();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +80,12 @@ class RiakStorage implements Storage
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$this->store($storageName, $key, $data);
|
||||
$bucket = $this->client->bucket($storageName);
|
||||
/** @var $object \Riak\Object */
|
||||
$object = $bucket->get($key);
|
||||
|
||||
$object->setData($data);
|
||||
$object->store();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,15 +93,17 @@ class RiakStorage implements Storage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$location = $this->getRiakLocation($storageName, $key);
|
||||
$bucket = $this->client->bucket($storageName);
|
||||
|
||||
$delete = DeleteValue::builder($location)->build();
|
||||
/** @var $object \Riak\Object */
|
||||
$object = $bucket->get($key);
|
||||
|
||||
try {
|
||||
$this->client->execute($delete);
|
||||
} catch (RiakException $exception) {
|
||||
// deletion can fail silent
|
||||
if (! $object->exists()) {
|
||||
// object does not exist, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
$object->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,29 +111,16 @@ class RiakStorage implements Storage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$location = $this->getRiakLocation($storageName, $key);
|
||||
$bucket = $this->client->bucket($storageName);
|
||||
|
||||
// fetch object
|
||||
$fetch = FetchValue::builder($location)->build();
|
||||
/** @var $object \Riak\Object */
|
||||
$object = $bucket->get($key);
|
||||
|
||||
try {
|
||||
$result = $this->client->execute($fetch);
|
||||
} catch (RiakException $exception) {
|
||||
throw new NotFoundException();
|
||||
if (! $object->exists()) {
|
||||
throw new NotFoundException;
|
||||
}
|
||||
|
||||
$json = (string) $result
|
||||
->getValue()
|
||||
->getValue();
|
||||
|
||||
return json_decode($json, true);
|
||||
}
|
||||
|
||||
private function getRiakLocation($storageName, $key)
|
||||
{
|
||||
$namespace = new RiakNamespace('default', $storageName);
|
||||
|
||||
return new RiakLocation($namespace, $key);
|
||||
return $object->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,14 +34,12 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
class SimpleDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Aws\SimpleDb\SimpleDbClient
|
||||
* @var SimpleDbClient
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Aws\SimpleDb\SimpleDbClient $client
|
||||
* @param SimpleDbClient $client
|
||||
*/
|
||||
public function __construct(SimpleDbClient $client)
|
||||
{
|
||||
@@ -134,9 +132,7 @@ class SimpleDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@@ -145,6 +141,8 @@ class SimpleDbStorage implements Storage
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createDomain($domainName)
|
||||
{
|
||||
@@ -162,8 +160,9 @@ class SimpleDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function makeAttributes($data)
|
||||
{
|
||||
|
||||
@@ -36,10 +36,12 @@ class UnitOfWork
|
||||
* @var ClassMetadataFactory
|
||||
*/
|
||||
private $cmf;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
private $storageDriver;
|
||||
|
||||
/**
|
||||
* @var IdHandlingStrategy
|
||||
*/
|
||||
@@ -53,14 +55,38 @@ class UnitOfWork
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $identifiers;
|
||||
private $identifiers = [];
|
||||
|
||||
private $originalData;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $originalData = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scheduledInsertions = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scheduledDeletions = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $identityMap = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\KeyValueStore\Id\IdConverterStrategy
|
||||
*/
|
||||
private $idConverter;
|
||||
|
||||
/**
|
||||
* @param ClassMetadataFactory $cmf
|
||||
* @param Storage $storageDriver
|
||||
* @param Configuration|null $config
|
||||
*/
|
||||
public function __construct(ClassMetadataFactory $cmf, Storage $storageDriver, Configuration $config = null)
|
||||
{
|
||||
$this->cmf = $cmf;
|
||||
@@ -71,11 +97,22 @@ class UnitOfWork
|
||||
new Id\SingleIdHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata($className)
|
||||
{
|
||||
return $this->cmf->getMetadataFor($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null|string|array
|
||||
*/
|
||||
private function tryGetById($className, $id)
|
||||
{
|
||||
$idHash = $this->idHandler->hash($id);
|
||||
@@ -85,6 +122,14 @@ class UnitOfWork
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string|array $key
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function reconstititute($className, $key)
|
||||
{
|
||||
$class = $this->cmf->getMetadataFor($className);
|
||||
@@ -284,6 +329,9 @@ class UnitOfWork
|
||||
$this->scheduledDeletions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the unit of work.
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->scheduledInsertions = [];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<phpunit bootstrap="tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine KeyValueStore">
|
||||
<directory suffix="Test.php">tests/Doctrine/Tests/KeyValueStore</directory>
|
||||
<directory suffix="Test.php">tests/Doctrine</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
@@ -16,7 +16,5 @@
|
||||
<var name="DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA" value="sharedlite" />
|
||||
<var name="DOCTRINE_KEYVALUE_AZURE_NAME" value="" />
|
||||
<var name="DOCTRINE_KEYVALUE_AZURE_KEY" value="" />
|
||||
<env name="RIAK_DNS" value="" />
|
||||
<env name="DYNAMODB_DNS" value="" />
|
||||
</php>
|
||||
</phpunit>
|
||||
|
||||
123
tests/Doctrine/KeyValueStore/ConfigurationTest.php
Normal file
123
tests/Doctrine/KeyValueStore/ConfigurationTest.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\KeyValueStore\Id\IdConverterStrategy;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Configuration
|
||||
*/
|
||||
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Configuration
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new Configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getMappingDriverImpl
|
||||
* @expectedException \Doctrine\KeyValueStore\KeyValueStoreException
|
||||
*/
|
||||
public function testGetMappingDriverImpl()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
MappingDriver::class,
|
||||
$this->object->getMappingDriverImpl()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getMappingDriverImpl
|
||||
* @covers ::setMappingDriverImpl
|
||||
* @depends testGetMappingDriverImpl
|
||||
*/
|
||||
public function testSetMappingDriverImpl()
|
||||
{
|
||||
$mappingDriver = $this->getMock(MappingDriver::class);
|
||||
|
||||
$setterOutput = $this->object->setMappingDriverImpl($mappingDriver);
|
||||
|
||||
$this->assertInstanceOf(Configuration::class, $setterOutput);
|
||||
$this->assertInstanceOf(MappingDriver::class, $this->object->getMappingDriverImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getMetadataCache
|
||||
*/
|
||||
public function testGetMetadataCache()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Cache::class,
|
||||
$this->object->getMetadataCache()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setMetadataCache
|
||||
* @depends testGetMetadataCache
|
||||
*/
|
||||
public function testSetMetadataCache()
|
||||
{
|
||||
$cache = $this->getMock(Cache::class);
|
||||
|
||||
$setterOutput = $this->object->setMetadataCache($cache);
|
||||
|
||||
$this->assertInstanceOf(Configuration::class, $setterOutput);
|
||||
$this->assertSame($cache, $this->object->getMetadataCache());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdConverterStrategy
|
||||
*/
|
||||
public function testGetIdConverterStrategy()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
IdConverterStrategy::class,
|
||||
$this->object->getIdConverterStrategy()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setIdConverterStrategy
|
||||
* @depends testGetIdConverterStrategy
|
||||
*/
|
||||
public function testSetIdConverterStrategy()
|
||||
{
|
||||
$idConverterStrategy = $this->getMock(IdConverterStrategy::class);
|
||||
|
||||
$setterOutput = $this->object->setIdConverterStrategy($idConverterStrategy);
|
||||
|
||||
$this->assertInstanceOf(Configuration::class, $setterOutput);
|
||||
$this->assertSame($idConverterStrategy, $this->object->getIdConverterStrategy());
|
||||
}
|
||||
}
|
||||
175
tests/Doctrine/KeyValueStore/EntityManagerTest.php
Normal file
175
tests/Doctrine/KeyValueStore/EntityManagerTest.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\KeyValueStore\Storage\Storage;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\EntityManager
|
||||
*/
|
||||
class EntityManagerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->storage = $this->getMock(Storage::class);
|
||||
$configuration = $this->getMock(Configuration::class);
|
||||
|
||||
$configuration
|
||||
->method('getMappingDriverImpl')
|
||||
->willReturn($this->getMock(MappingDriver::class));
|
||||
|
||||
$this->object = new EntityManager($this->storage, $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::createRangeQuery
|
||||
*
|
||||
* @todo Implement testCreateRangeQuery().
|
||||
*/
|
||||
public function testCreateRangeQuery()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::persist
|
||||
*
|
||||
* @todo Implement testPersist().
|
||||
*/
|
||||
public function testPersist()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::remove
|
||||
*
|
||||
* @todo Implement testRemove().
|
||||
*/
|
||||
public function testRemove()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::flush
|
||||
*
|
||||
* @todo Implement testFlush().
|
||||
*/
|
||||
public function testFlush()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::unwrap
|
||||
*/
|
||||
public function testUnwrap()
|
||||
{
|
||||
$this->assertSame(
|
||||
$this->storage,
|
||||
$this->object->unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getUnitOfWork
|
||||
*/
|
||||
public function testGetUnitOfWork()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
UnitOfWork::class,
|
||||
$this->object->getUnitOfWork()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::clear
|
||||
*/
|
||||
public function testClear()
|
||||
{
|
||||
$this->object->clear();
|
||||
|
||||
$clearedKeys = [
|
||||
'scheduledInsertions',
|
||||
'scheduledDeletions',
|
||||
'identifiers',
|
||||
'originalData',
|
||||
'identityMap',
|
||||
];
|
||||
|
||||
$unitOfWork = $this->object->getUnitOfWork();
|
||||
$reflectionClass = new ReflectionClass($unitOfWork);
|
||||
|
||||
foreach ($clearedKeys as $clearedKey) {
|
||||
$property = $reflectionClass->getProperty($clearedKey);
|
||||
$property->setAccessible(true);
|
||||
|
||||
$value = $property->getValue($unitOfWork);
|
||||
|
||||
$this->assertInternalType('array', $value);
|
||||
$this->assertEmpty($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getClassMetadata
|
||||
*
|
||||
* @todo Implement testGetClassMetadata().
|
||||
*/
|
||||
public function testGetClassMetadata()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
148
tests/Doctrine/KeyValueStore/Id/CompositeIdHandlerTest.php
Normal file
148
tests/Doctrine/KeyValueStore/Id/CompositeIdHandlerTest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Id\CompositeIdHandler
|
||||
*/
|
||||
class CompositeIdHandlerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var CompositeIdHandler
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new CompositeIdHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeId
|
||||
*/
|
||||
public function testNormalizeId()
|
||||
{
|
||||
$classMetadata = $this
|
||||
->getMockBuilder(ClassMetadata::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$classMetadata->isCompositeKey = false;
|
||||
$classMetadata->identifier = ['id'];
|
||||
|
||||
$key = 'test';
|
||||
|
||||
$normalizedId = $this->object->normalizeId($classMetadata, $key);
|
||||
$this->assertSame(['id' => $key], $normalizedId);
|
||||
|
||||
$key = ['id' => 'bar'];
|
||||
|
||||
$normalizedId = $this->object->normalizeId($classMetadata, $key);
|
||||
$this->assertSame($key, $normalizedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeId
|
||||
*/
|
||||
public function testWrongNormalizeId()
|
||||
{
|
||||
$classMetadata = $this
|
||||
->getMockBuilder(ClassMetadata::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$classMetadata->isCompositeKey = true;
|
||||
$classMetadata->identifier = ['id'];
|
||||
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$this->object->normalizeId($classMetadata, 'test');
|
||||
|
||||
$classMetadata->isCompositeKey = false;
|
||||
$classMetadata->identifier = ['id'];
|
||||
|
||||
$key = ['foo' => 'bar'];
|
||||
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$this->object->normalizeId($classMetadata, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testGetIdentifier()
|
||||
{
|
||||
$data = rand();
|
||||
|
||||
$metadata = $this
|
||||
->getMockBuilder(ClassMetadata::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$object = new stdClass;
|
||||
|
||||
$metadata->identifier = ['id'];
|
||||
$metadata
|
||||
->expects($this->once())
|
||||
->method('getIdentifierValues')
|
||||
->with($this->equalTo($object))
|
||||
->willReturn($data);
|
||||
|
||||
$identifier = $this->object->getIdentifier($metadata, $object);
|
||||
$this->assertSame($data, $identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hash
|
||||
* @dataProvider keysProvider
|
||||
*/
|
||||
public function testHash($key, $expected)
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->object->hash($key)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function keysProvider()
|
||||
{
|
||||
$stdClass = new stdClass;
|
||||
$stdClass->foo = 'bar';
|
||||
$stdClass->bar = 'foo';
|
||||
|
||||
return [
|
||||
[['foo', 'bar'], 'foo__##__bar'],
|
||||
[$stdClass, 'bar__##__foo'],
|
||||
['bar', 'bar'],
|
||||
];
|
||||
}
|
||||
}
|
||||
69
tests/Doctrine/KeyValueStore/Id/NullIdConverterTest.php
Normal file
69
tests/Doctrine/KeyValueStore/Id/NullIdConverterTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Id\NullIdConverter
|
||||
*/
|
||||
class NullIdConverterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var NullIdConverter
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new NullIdConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::serialize
|
||||
*/
|
||||
public function testSerialize()
|
||||
{
|
||||
$data = rand();
|
||||
|
||||
$this->assertSame(
|
||||
$data,
|
||||
$this->object->serialize(rand(), $data)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::unserialize
|
||||
*/
|
||||
public function testUnserialize()
|
||||
{
|
||||
$data = rand();
|
||||
|
||||
$this->assertSame(
|
||||
$data,
|
||||
$this->object->unserialize(rand(), $data)
|
||||
);
|
||||
}
|
||||
}
|
||||
109
tests/Doctrine/KeyValueStore/Id/SingleIdHandlerTest.php
Normal file
109
tests/Doctrine/KeyValueStore/Id/SingleIdHandlerTest.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Id\SingleIdHandler
|
||||
*/
|
||||
class SingleIdHandlerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var SingleIdHandler
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new SingleIdHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeId
|
||||
*/
|
||||
public function testNormalizeId()
|
||||
{
|
||||
$metadata = $this
|
||||
->getMockBuilder(ClassMetadata::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$key = rand();
|
||||
|
||||
$normalizedId = $this->object->normalizeId($metadata, $key);
|
||||
$this->assertSame($key, $normalizedId);
|
||||
|
||||
$metadata->identifier = ['id'];
|
||||
$key = [
|
||||
'id' => rand(),
|
||||
];
|
||||
|
||||
$normalizedId = $this->object->normalizeId($metadata, $key);
|
||||
$this->assertSame($key['id'], $normalizedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testGetIdentifier()
|
||||
{
|
||||
$data = rand();
|
||||
|
||||
$metadata = $this
|
||||
->getMockBuilder(ClassMetadata::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$object = new stdClass;
|
||||
|
||||
$metadata->identifier = ['id'];
|
||||
$metadata
|
||||
->expects($this->once())
|
||||
->method('getIdentifierValues')
|
||||
->with($this->equalTo($object))
|
||||
->willReturn([
|
||||
'id' => $data,
|
||||
]);
|
||||
|
||||
$identifier = $this->object->getIdentifier($metadata, $object);
|
||||
$this->assertSame($data, $identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hash
|
||||
*/
|
||||
public function testHash()
|
||||
{
|
||||
$key = rand();
|
||||
|
||||
$this->assertSame(
|
||||
$key,
|
||||
$this->object->hash($key)
|
||||
);
|
||||
}
|
||||
}
|
||||
115
tests/Doctrine/KeyValueStore/Mapping/AnnotationDriverTest.php
Normal file
115
tests/Doctrine/KeyValueStore/Mapping/AnnotationDriverTest.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Mapping\AnnotationDriver
|
||||
*/
|
||||
class AnnotationDriverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var AnnotationReader
|
||||
*/
|
||||
private $annotationReader;
|
||||
|
||||
/**
|
||||
* @var AnnotationDriver
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->annotationReader = $this->getMock(AnnotationReader::class);
|
||||
$this->object = new AnnotationDriver($this->annotationReader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadMetadataForClass
|
||||
*/
|
||||
public function testLoadMetadataForClass()
|
||||
{
|
||||
$storageName = sha1(rand());
|
||||
|
||||
$reflectionClass = $this
|
||||
->getMockBuilder(ReflectionClass::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$classAnnotation = $this->getMock(stdClass::class);
|
||||
$classAnnotation->storageName = $storageName;
|
||||
|
||||
$metadata = $this->getMock(CommonClassMetadata::class);
|
||||
$metadata
|
||||
->method('getReflectionClass')
|
||||
->willReturn($reflectionClass);
|
||||
|
||||
$this->annotationReader
|
||||
->method('getClassAnnotation')
|
||||
->willReturn($classAnnotation);
|
||||
|
||||
$reflectionClass
|
||||
->method('getProperties')
|
||||
->willReturn([]);
|
||||
|
||||
$this->object->loadMetadataForClass(sha1(rand()), $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadMetadataForClass
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testWrongLoadMetadataForClass()
|
||||
{
|
||||
$metadata = $this->getMock(CommonClassMetadata::class);
|
||||
$metadata->name = 'stdClass';
|
||||
|
||||
$this->object->loadMetadataForClass(sha1(rand()), $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAllClassNames
|
||||
*/
|
||||
public function testGetAllClassNames()
|
||||
{
|
||||
$allClassNames = $this->object->getAllClassNames();
|
||||
|
||||
$this->assertInternalType('array', $allClassNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isTransient
|
||||
*/
|
||||
public function testIsTransient()
|
||||
{
|
||||
$transient = $this->object->isTransient('stdClass');
|
||||
|
||||
$this->assertFalse($transient);
|
||||
}
|
||||
}
|
||||
320
tests/Doctrine/KeyValueStore/Mapping/ClassMetadataTest.php
Normal file
320
tests/Doctrine/KeyValueStore/Mapping/ClassMetadataTest.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use PHPUnit_Framework_Assert;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Mapping\ClassMetadata
|
||||
*/
|
||||
class ClassMetadataTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$class = rand(0, 1) ? stdClass::class : new stdClass;
|
||||
|
||||
$this->object = new ClassMetadata($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::skipTransientField
|
||||
*/
|
||||
public function testSkipTransientField()
|
||||
{
|
||||
$field = 'foo';
|
||||
|
||||
$this->object->skipTransientField($field);
|
||||
|
||||
$this->assertArrayNotHasKey($field, $this->object->fields);
|
||||
$this->assertArrayHasKey($field, $this->object->transientFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::mapField
|
||||
* @depends testSkipTransientField
|
||||
*/
|
||||
public function testMapField()
|
||||
{
|
||||
$field = [
|
||||
'fieldName' => 'foo',
|
||||
];
|
||||
|
||||
$this->object->mapField($field);
|
||||
|
||||
$this->assertArraySubset(['foo' => $field], $this->object->fields);
|
||||
|
||||
$transientField = [
|
||||
'fieldName' => 'bar',
|
||||
];
|
||||
|
||||
$this->object->skipTransientField('bar');
|
||||
$this->object->mapField($transientField);
|
||||
|
||||
$this->assertArrayNotHasKey('bar', $this->object->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::mapIdentifier
|
||||
* @depends testMapField
|
||||
*/
|
||||
public function testMapIdentifier()
|
||||
{
|
||||
$this->object->mapIdentifier('id');
|
||||
|
||||
$this->assertFalse($this->object->isCompositeKey);
|
||||
$this->assertContains('id', $this->object->identifier);
|
||||
|
||||
$this->assertArraySubset([
|
||||
'id' => ['fieldName' => 'id', 'id' => true],
|
||||
], $this->object->fields);
|
||||
|
||||
$this->object->mapIdentifier('pk');
|
||||
|
||||
$this->assertTrue($this->object->isCompositeKey);
|
||||
$this->assertContains('id', $this->object->identifier);
|
||||
$this->assertContains('pk', $this->object->identifier);
|
||||
|
||||
$this->assertArraySubset([
|
||||
'id' => ['fieldName' => 'id', 'id' => true],
|
||||
'pk' => ['fieldName' => 'pk', 'id' => true],
|
||||
], $this->object->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::newInstance
|
||||
*/
|
||||
public function testNewInstance()
|
||||
{
|
||||
$prototype = PHPUnit_Framework_Assert::readAttribute($this->object, 'prototype');
|
||||
$this->assertNull($prototype);
|
||||
|
||||
$instance = $this->object->newInstance();
|
||||
|
||||
$prototype = PHPUnit_Framework_Assert::readAttribute($this->object, 'prototype');
|
||||
$this->assertNotNull($prototype);
|
||||
|
||||
$this->assertInstanceOf('stdClass', $prototype);
|
||||
$this->assertInstanceOf('stdClass', $instance);
|
||||
|
||||
$this->assertNotSame($prototype, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__sleep
|
||||
*/
|
||||
public function testSleep()
|
||||
{
|
||||
$attributes = $this->object->__sleep();
|
||||
|
||||
foreach ($attributes as $attribute) {
|
||||
$this->assertClassHasAttribute($attribute, ClassMetadata::class);
|
||||
}
|
||||
|
||||
$this->assertInternalType('string', serialize($this->object));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifierValues
|
||||
*/
|
||||
public function testGetIdentifierValues()
|
||||
{
|
||||
$identifierValues = $this->object->getIdentifierValues(new stdClass);
|
||||
|
||||
$this->assertInternalType('array', $identifierValues);
|
||||
$this->assertEmpty($identifierValues);
|
||||
|
||||
$object = new stdClass;
|
||||
$object->id = rand();
|
||||
|
||||
$this->object->mapIdentifier('id');
|
||||
|
||||
$identifierValues = $this->object->getIdentifierValues($object);
|
||||
|
||||
$this->assertInternalType('array', $identifierValues);
|
||||
$this->assertNotEmpty($identifierValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testGetIdentifier()
|
||||
{
|
||||
$identifier = $this->object->getIdentifier();
|
||||
|
||||
$this->assertInternalType('array', $identifier);
|
||||
|
||||
foreach ($identifier as $key => $value) {
|
||||
$this->assertInternalType('integer', $key);
|
||||
$this->assertInternalType('string', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getReflectionClass
|
||||
*/
|
||||
public function testGetReflectionClass()
|
||||
{
|
||||
$reflectionClass = $this->object->getReflectionClass();
|
||||
|
||||
$this->assertInstanceOf(ReflectionClass::class, $reflectionClass);
|
||||
$this->assertSame('stdClass', $reflectionClass->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isIdentifier
|
||||
*/
|
||||
public function testIsIdentifier()
|
||||
{
|
||||
$this->object->mapIdentifier('id');
|
||||
|
||||
$this->assertTrue($this->object->isIdentifier('id'));
|
||||
$this->assertFalse($this->object->isIdentifier('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hasField
|
||||
*/
|
||||
public function testHasField()
|
||||
{
|
||||
$this->object->mapField(['fieldName' => 'foo']);
|
||||
|
||||
$this->assertTrue($this->object->hasField('foo'));
|
||||
$this->assertFalse($this->object->hasField('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hasAssociation
|
||||
*/
|
||||
public function testHasAssociation()
|
||||
{
|
||||
$this->assertFalse($this->object->hasAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isSingleValuedAssociation
|
||||
*/
|
||||
public function testIsSingleValuedAssociation()
|
||||
{
|
||||
$this->assertFalse($this->object->isSingleValuedAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isCollectionValuedAssociation
|
||||
*/
|
||||
public function testIsCollectionValuedAssociation()
|
||||
{
|
||||
$this->assertFalse($this->object->isCollectionValuedAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldNames
|
||||
*/
|
||||
public function testGetFieldNames()
|
||||
{
|
||||
$this->object->mapField(['fieldName' => 'foo']);
|
||||
|
||||
$fieldNames = $this->object->getFieldNames();
|
||||
|
||||
$this->assertInternalType('array', $fieldNames);
|
||||
|
||||
foreach ($fieldNames as $key => $value) {
|
||||
$this->assertInternalType('integer', $key);
|
||||
$this->assertInternalType('string', $value);
|
||||
}
|
||||
|
||||
$this->assertSame(['foo'], $fieldNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifierFieldNames
|
||||
*/
|
||||
public function testGetIdentifierFieldNames()
|
||||
{
|
||||
$identifierFieldNames = $this->object->getIdentifierFieldNames();
|
||||
|
||||
$this->assertInternalType('array', $identifierFieldNames);
|
||||
|
||||
foreach ($identifierFieldNames as $key => $value) {
|
||||
$this->assertInternalType('integer', $key);
|
||||
$this->assertInternalType('string', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAssociationNames
|
||||
*/
|
||||
public function testGetAssociationNames()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTypeOfField
|
||||
*/
|
||||
public function testGetTypeOfField()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAssociationTargetClass
|
||||
*/
|
||||
public function testGetAssociationTargetClass()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isAssociationInverseSide
|
||||
*/
|
||||
public function testIsAssociationInverseSide()
|
||||
{
|
||||
$this->assertFalse($this->object->isAssociationInverseSide(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAssociationMappedByTargetField
|
||||
*/
|
||||
public function testGetAssociationMappedByTargetField()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
54
tests/Doctrine/KeyValueStore/Mapping/XmlDriverTest.php
Normal file
54
tests/Doctrine/KeyValueStore/Mapping/XmlDriverTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Mapping\XmlDriver
|
||||
*/
|
||||
class XmlDriverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var XmlDriver
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new XmlDriver(__DIR__ . '/Fixtures/xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadMetadataForClass
|
||||
*
|
||||
* @todo Implement testLoadMetadataForClass().
|
||||
*/
|
||||
public function testLoadMetadataForClass()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
54
tests/Doctrine/KeyValueStore/Mapping/YamlDriverTest.php
Normal file
54
tests/Doctrine/KeyValueStore/Mapping/YamlDriverTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Mapping\YamlDriver
|
||||
*/
|
||||
class YamlDriverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var YamlDriver
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new YamlDriver(__DIR__ . '/Fixtures/yaml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadMetadataForClass
|
||||
*
|
||||
* @todo Implement testLoadMetadataForClass().
|
||||
*/
|
||||
public function testLoadMetadataForClass()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
260
tests/Doctrine/KeyValueStore/Query/RangeQueryTest.php
Normal file
260
tests/Doctrine/KeyValueStore/Query/RangeQueryTest.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Query;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\EntityManager;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Query\RangeQuery
|
||||
*/
|
||||
class RangeQueryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $className;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $partitionKey;
|
||||
|
||||
/**
|
||||
* @var RangeQuery
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->className = sha1(rand());
|
||||
$this->partitionKey = sha1(rand());
|
||||
|
||||
$this->object = new RangeQuery(
|
||||
$this->entityManager,
|
||||
$this->className,
|
||||
$this->partitionKey
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setLimit
|
||||
* @covers ::getLimit
|
||||
*/
|
||||
public function testLimit()
|
||||
{
|
||||
$limit = rand();
|
||||
|
||||
$setterOutput = $this->object->setLimit($limit);
|
||||
|
||||
$this->assertInstanceOf(RangeQuery::class, $setterOutput);
|
||||
$this->assertSame($limit, $this->object->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getClassName
|
||||
*/
|
||||
public function testGetClassName()
|
||||
{
|
||||
$this->assertSame(
|
||||
$this->className,
|
||||
$this->object->getClassName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPartitionKey
|
||||
*/
|
||||
public function testGetPartitionKey()
|
||||
{
|
||||
$this->assertSame(
|
||||
$this->partitionKey,
|
||||
$this->object->getPartitionKey()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testGetConditions()
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($this->object);
|
||||
$constants = $reflectionClass->getConstants();
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
|
||||
$this->assertInternalType('array', $conditions);
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$this->assertArrayHasKey($condition[0], $constants);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeEquals
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeEquals()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeEquals($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_EQ, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeNotEquals
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeNotEquals()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeNotEquals($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_NEQ, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeLessThan
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeLessThan()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeLessThan($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_LT, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeLessThanEquals
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeLessThanEquals()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeLessThanEquals($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_LE, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeGreaterThan
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeGreaterThan()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeGreaterThan($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_GT, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rangeGreaterThanEquals
|
||||
* @depends testGetConditions
|
||||
*/
|
||||
public function testRangeGreaterThanEquals()
|
||||
{
|
||||
$value = 'test';
|
||||
|
||||
$output = $this->object->rangeGreaterThanEquals($value);
|
||||
$this->assertInstanceOf(RangeQuery::class, $output);
|
||||
|
||||
$conditions = $this->object->getConditions();
|
||||
$this->assertArraySubset(
|
||||
[[RangeQuery::CONDITION_GE, $value]],
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::execute
|
||||
*
|
||||
* @todo Implement testExecute().
|
||||
*/
|
||||
public function testExecute()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function testWrongExecute()
|
||||
{
|
||||
$this->entityManager
|
||||
->method('unwrap')
|
||||
->willReturn(new DoctrineCacheStorage(new ArrayCache));
|
||||
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
$this->object->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use WindowsAzure\Common\ServicesBuilder;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\AzureSdkTableStorage
|
||||
*/
|
||||
class AzureSdkTableStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var AzureSdkTableStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
if (empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME']) || empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY'])) {
|
||||
$this->markTestSkipped('Missing Azure credentials.');
|
||||
}
|
||||
|
||||
$connectionString = sprintf(
|
||||
'DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s',
|
||||
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME'],
|
||||
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY']
|
||||
);
|
||||
$tableProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
|
||||
|
||||
$this->storage = new AzureSdkTableStorage($tableProxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('azure_table_sdk', $this->object->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::executeRangeQuery
|
||||
*
|
||||
* @todo Implement testExecuteRangeQuery().
|
||||
*/
|
||||
public function testExecuteRangeQuery()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
129
tests/Doctrine/KeyValueStore/Storage/CassandraStorageTest.php
Normal file
129
tests/Doctrine/KeyValueStore/Storage/CassandraStorageTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\CassandraStorage
|
||||
* @requires extension cassandra
|
||||
*/
|
||||
class CassandraStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var CassandraStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new CassandraStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('cassandra', $this->object->getName());
|
||||
}
|
||||
}
|
||||
140
tests/Doctrine/KeyValueStore/Storage/CouchDbStorageTest.php
Normal file
140
tests/Doctrine/KeyValueStore/Storage/CouchDbStorageTest.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\CouchDB\CouchDBClient;
|
||||
use Doctrine\CouchDB\HTTP\StreamClient;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\CouchDbStorage
|
||||
*/
|
||||
class CouchDbStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var CouchDbStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder(StreamClient::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->couchdb = $this
|
||||
->getMockBuilder(CouchDBClient::class)
|
||||
->setConstructorArgs([$client, 'test'])
|
||||
->getMock();
|
||||
|
||||
$this->object = new CouchDbStorage($this->couchdb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('couchdb', $this->object->getName());
|
||||
}
|
||||
}
|
||||
129
tests/Doctrine/KeyValueStore/Storage/CouchbaseStorageTest.php
Normal file
129
tests/Doctrine/KeyValueStore/Storage/CouchbaseStorageTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\CouchbaseStorage
|
||||
* @requires extension couchbase
|
||||
*/
|
||||
class CouchbaseStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var CouchbaseStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new CouchbaseStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('couchbase', $this->object->getName());
|
||||
}
|
||||
}
|
||||
129
tests/Doctrine/KeyValueStore/Storage/DBALStorageTest.php
Normal file
129
tests/Doctrine/KeyValueStore/Storage/DBALStorageTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\DBALStorage
|
||||
*/
|
||||
class DBALStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var DBALStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new DBALStorage($this->getMock(Connection::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('dbal', $this->object->getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\DoctrineCacheStorage
|
||||
*/
|
||||
class DoctrineCacheStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var DoctrineCacheStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new DoctrineCacheStorage(new ArrayCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('doctrine_cache', $this->object->getName());
|
||||
}
|
||||
}
|
||||
134
tests/Doctrine/KeyValueStore/Storage/DynamoDbStorageTest.php
Normal file
134
tests/Doctrine/KeyValueStore/Storage/DynamoDbStorageTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\DynamoDbStorage
|
||||
*/
|
||||
class DynamoDbStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var DynamoDbStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$dynamoDbClient = $this
|
||||
->getMockBuilder(DynamoDbClient::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->object = new DynamoDbStorage($dynamoDbClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('dynamodb', $this->object->getName());
|
||||
}
|
||||
}
|
||||
140
tests/Doctrine/KeyValueStore/Storage/MongoDbStorageTest.php
Normal file
140
tests/Doctrine/KeyValueStore/Storage/MongoDbStorageTest.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\MongoDbStorage
|
||||
* @requires extension mongo
|
||||
*/
|
||||
class MongoDbStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MongoDbStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new MongoDbStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::initialize
|
||||
*
|
||||
* @todo Implement testInitialize().
|
||||
*/
|
||||
public function testInitialize()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('mongodb', $this->object->getName());
|
||||
}
|
||||
}
|
||||
140
tests/Doctrine/KeyValueStore/Storage/RedisStorageTest.php
Normal file
140
tests/Doctrine/KeyValueStore/Storage/RedisStorageTest.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\RedisStorage
|
||||
* @requires extension redis
|
||||
*/
|
||||
class RedisStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var RedisStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new RedisStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('redis', $this->object->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getKeyName
|
||||
*
|
||||
* @todo Implement testGetKeyName().
|
||||
*/
|
||||
public function testGetKeyName()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
318
tests/Doctrine/KeyValueStore/Storage/RiakStorageTest.php
Normal file
318
tests/Doctrine/KeyValueStore/Storage/RiakStorageTest.php
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Riak\Bucket;
|
||||
use Riak\Client;
|
||||
use Riak\Object;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\RiakStorage
|
||||
*/
|
||||
class RiakStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var RiakStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->client = $this
|
||||
->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->object = new RiakStorage($this->client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
$this->assertFalse($this->object->supportsPartialUpdates());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->object->supportsCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->object->requiresCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('newObject')
|
||||
->will($this->returnCallback(function ($key, $data) use ($objectMock) {
|
||||
$this->assertEquals('foobar', $key);
|
||||
$this->assertEquals(['title' => 'Riak test'], $data);
|
||||
|
||||
return $objectMock;
|
||||
}));
|
||||
|
||||
$this->object->insert('riak-test', 'foobar', ['title' => 'Riak test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn($objectMock);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('setData')
|
||||
->will($this->returnCallback(function ($data) {
|
||||
$this->assertEquals(['title' => 'Riak cookbook'], $data);
|
||||
}));
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
$this->object->update('riak-test', 'foobar', ['title' => 'Riak cookbook']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->willReturn($objectMock);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('exists')
|
||||
->willReturn(true);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$this->object->delete('riak-test', 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDeleteWithNotExistKey()
|
||||
{
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->willReturn($objectMock);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('exists')
|
||||
->willReturn(false);
|
||||
|
||||
$objectMock
|
||||
->expects($this->never())
|
||||
->method('delete');
|
||||
|
||||
$this->object->delete('riak-test', 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->willReturn($objectMock);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('exists')
|
||||
->willReturn(true);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('getData')
|
||||
->willReturn(['title' => 'Riak Test']);
|
||||
|
||||
$this->assertEquals(['title' => 'Riak Test'], $this->object->find('riaktest', 'foobar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
* @expectedException Doctrine\KeyValueStore\NotFoundException
|
||||
*/
|
||||
public function testFindWithNotExistKey()
|
||||
{
|
||||
$objectMock = $this
|
||||
->getMockBuilder(Object::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this
|
||||
->getMockBuilder(Bucket::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('bucket')
|
||||
->willReturn($bucket);
|
||||
|
||||
$bucket
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->willReturn($objectMock);
|
||||
|
||||
$objectMock
|
||||
->expects($this->once())
|
||||
->method('exists')
|
||||
->willReturn(false);
|
||||
|
||||
$objectMock
|
||||
->expects($this->never())
|
||||
->method('getData');
|
||||
|
||||
$this->object->find('riak-test', 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('riak', $this->object->getName());
|
||||
}
|
||||
}
|
||||
134
tests/Doctrine/KeyValueStore/Storage/SimpleDbStorageTest.php
Normal file
134
tests/Doctrine/KeyValueStore/Storage/SimpleDbStorageTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Aws\SimpleDb\SimpleDbClient;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\Storage\SimpleDbStorage
|
||||
*/
|
||||
class SimpleDbStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var SimpleDbStorage
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$simpleDbClient = $this
|
||||
->getMockBuilder(SimpleDbClient::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->object = new SimpleDbStorage($simpleDbClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsPartialUpdates
|
||||
*
|
||||
* @todo Implement testSupportsPartialUpdates().
|
||||
*/
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::supportsCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testSupportsCompositePrimaryKeys().
|
||||
*/
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::requiresCompositePrimaryKeys
|
||||
*
|
||||
* @todo Implement testRequiresCompositePrimaryKeys().
|
||||
*/
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::insert
|
||||
*
|
||||
* @todo Implement testInsert().
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
*
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*
|
||||
* @todo Implement testDelete().
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::find
|
||||
*
|
||||
* @todo Implement testFind().
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getName
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('simpledb', $this->object->getName());
|
||||
}
|
||||
}
|
||||
148
tests/Doctrine/KeyValueStore/UnitOfWorkTest.php
Normal file
148
tests/Doctrine/KeyValueStore/UnitOfWorkTest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore;
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\KeyValueStore\Storage\Storage;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Doctrine\KeyValueStore\UnitOfWork
|
||||
*/
|
||||
class UnitOfWorkTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var UnitOfWork
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$classMetadataFactory = $this
|
||||
->getMockBuilder(ClassMetadataFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$storage = $this->getMock(Storage::class);
|
||||
$configuration = $this->getMock(Configuration::class);
|
||||
|
||||
$this->object = new UnitOfWork($classMetadataFactory, $storage, $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getClassMetadata
|
||||
*
|
||||
* @todo Implement testGetClassMetadata().
|
||||
*/
|
||||
public function testGetClassMetadata()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::reconstititute
|
||||
*
|
||||
* @todo Implement testReconstititute().
|
||||
*/
|
||||
public function testReconstititute()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::createEntity
|
||||
*
|
||||
* @todo Implement testCreateEntity().
|
||||
*/
|
||||
public function testCreateEntity()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::scheduleForInsert
|
||||
*
|
||||
* @todo Implement testScheduleForInsert().
|
||||
*/
|
||||
public function testScheduleForInsert()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::scheduleForDelete
|
||||
*
|
||||
* @todo Implement testScheduleForDelete().
|
||||
*/
|
||||
public function testScheduleForDelete()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::commit
|
||||
*
|
||||
* @todo Implement testCommit().
|
||||
*/
|
||||
public function testCommit()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::clear
|
||||
*/
|
||||
public function testClear()
|
||||
{
|
||||
$clearedKeys = [
|
||||
'scheduledInsertions',
|
||||
'scheduledDeletions',
|
||||
'identifiers',
|
||||
'originalData',
|
||||
'identityMap',
|
||||
];
|
||||
|
||||
$this->object->clear();
|
||||
|
||||
$reflectionClass = new ReflectionClass($this->object);
|
||||
$defaultProperties = $reflectionClass->getDefaultProperties();
|
||||
|
||||
foreach ($clearedKeys as $clearedKey) {
|
||||
$property = $reflectionClass->getProperty($clearedKey);
|
||||
$property->setAccessible(true);
|
||||
|
||||
$this->assertSame(
|
||||
$defaultProperties[$clearedKey],
|
||||
$property->getValue($this->object)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ namespace Doctrine\Tests\KeyValueStore;
|
||||
|
||||
use Doctrine\KeyValueStore\Configuration;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNoMappingDriver()
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Doctrine\Tests\KeyValueStore\Functional;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations as KVS;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
{
|
||||
private $manager;
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Doctrine\Tests\KeyValueStore\Functional;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class CompositeBasicCrudTest extends BasicCrudTestCase
|
||||
{
|
||||
private $cache;
|
||||
|
||||
@@ -25,6 +25,9 @@ use Doctrine\KeyValueStore\Mapping\Annotations as KVS;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class InheritanceTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $manager;
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Doctrine\Tests\KeyValueStore\Functional;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations as KVS;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class PersistTest extends KeyValueStoreTestCase
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Doctrine\Tests\KeyValueStore\Functional;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SingleBasicCrudTest extends BasicCrudTestCase
|
||||
{
|
||||
private $cache;
|
||||
|
||||
@@ -25,6 +25,9 @@ use Doctrine\KeyValueStore\Storage\AzureSdkTableStorage;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
use WindowsAzure\Common\ServicesBuilder;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AzureSdkTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $storage;
|
||||
|
||||
@@ -24,6 +24,7 @@ use Cassandra;
|
||||
use Doctrine\KeyValueStore\Storage\CassandraStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @requires extension cassandra
|
||||
*/
|
||||
class CassandraTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
@@ -26,6 +26,9 @@ use Doctrine\KeyValueStore\Storage\WindowsAzureTable\SharedKeyLiteAuthorization;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class WindowsAzureTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $storage;
|
||||
|
||||
@@ -25,6 +25,7 @@ use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Doctrine\KeyValueStore\Mapping\ClassMetadata
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Storage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ use Doctrine\KeyValueStore\Storage\CouchDbStorage;
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*
|
||||
* @covers \Doctrine\KeyValueStore\Storage\CouchDbStorage
|
||||
* @group legacy
|
||||
*/
|
||||
class CouchDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -27,6 +27,7 @@ use Doctrine\KeyValueStore\Storage\CouchbaseStorage;
|
||||
*
|
||||
* @author Simon Schick <simonsimcity@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
* @requires extension couchbase
|
||||
*/
|
||||
class CouchbaseStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\DynamoDbStorage;
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* @covers \Doctrine\KeyValueStore\Storage\DynamoDbStorage
|
||||
*/
|
||||
class DynamoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const DATA = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var DynamoDbClient|null
|
||||
*/
|
||||
private static $client;
|
||||
|
||||
/**
|
||||
* @var DynamoDbStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$dns = getenv('DYNAMODB_DNS');
|
||||
|
||||
if (empty($dns)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static::$client = DynamoDbClient::factory(array(
|
||||
'credentials' => [
|
||||
'key' => 'YOUR_KEY',
|
||||
'secret' => 'YOUR_SECRET',
|
||||
],
|
||||
'region' => 'us-west-2',
|
||||
'endpoint' => $dns,
|
||||
'version' => 'latest',
|
||||
'retries' => 1,
|
||||
));
|
||||
|
||||
try {
|
||||
static::$client->deleteTable([
|
||||
'TableName' => 'dynamodb',
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
// table does not exist
|
||||
}
|
||||
|
||||
try {
|
||||
static::$client->createTable(array(
|
||||
'TableName' => 'dynamodb',
|
||||
'AttributeDefinitions' => array(
|
||||
array(
|
||||
'AttributeName' => 'id',
|
||||
'AttributeType' => 'S',
|
||||
),
|
||||
),
|
||||
'KeySchema' => array(
|
||||
array(
|
||||
'AttributeName' => 'id',
|
||||
'KeyType' => 'HASH',
|
||||
),
|
||||
),
|
||||
'ProvisionedThroughput' => array(
|
||||
'ReadCapacityUnits' => 10,
|
||||
'WriteCapacityUnits' => 20,
|
||||
),
|
||||
));
|
||||
} catch (\Exception $exception) {
|
||||
static::$client = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (! static::$client) {
|
||||
$this->markTestSkipped('DynamoDB is required.');
|
||||
}
|
||||
|
||||
$this->storage = new DynamoDbStorage(static::$client);
|
||||
}
|
||||
|
||||
public function testInsertAndFind()
|
||||
{
|
||||
$this->storage->insert('dynamodb', 'testInsertAndFind', self::DATA);
|
||||
|
||||
$data = $this->storage->find('dynamodb', 'testInsertAndFind');
|
||||
|
||||
$this->assertEquals(self::DATA, $data);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->storage->insert('dynamodb', 'testUpdate', self::DATA);
|
||||
|
||||
$newData = [
|
||||
'foo' => 'bar',
|
||||
];
|
||||
|
||||
$this->storage->update('dynamodb', 'testUpdate', $newData);
|
||||
|
||||
$data = $this->storage->find('dynamodb', 'testUpdate');
|
||||
$this->assertEquals($newData, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsertAndFind
|
||||
*/
|
||||
public function testFindWithNotExistKey()
|
||||
{
|
||||
$this->setExpectedException(NotFoundException::class);
|
||||
$this->storage->find('dynamodb', 'not-existing-key');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsertAndFind
|
||||
* @depends testFindWithNotExistKey
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->storage->insert('dynamodb', 'testDelete', self::DATA);
|
||||
$this->storage->delete('dynamodb', 'testDelete');
|
||||
|
||||
$this->setExpectedException(NotFoundException::class);
|
||||
$this->storage->find('dynamodb', 'testDelete');
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('dynamodb', $this->storage->getName());
|
||||
}
|
||||
}
|
||||
346
tests/Doctrine/Tests/KeyValueStore/Storage/DynamoDbTest.php
Normal file
346
tests/Doctrine/Tests/KeyValueStore/Storage/DynamoDbTest.php
Normal file
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\DynamoDbStorage;
|
||||
|
||||
/**
|
||||
* @covers \Doctrine\KeyValueStore\Storage\DynamoDbStorage
|
||||
*/
|
||||
class DynamoDbTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function getDynamoDbMock($methods = [])
|
||||
{
|
||||
$client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')->disableOriginalConstructor();
|
||||
|
||||
if (count($methods)) {
|
||||
$client->setMethods($methods);
|
||||
}
|
||||
|
||||
return $client->getMock();
|
||||
}
|
||||
|
||||
private function getDynamoDbResultMock($methods = [])
|
||||
{
|
||||
$result = $this->getMockBuilder('Aws\Result')->disableOriginalConstructor();
|
||||
|
||||
if (count($methods)) {
|
||||
$result->setMethods($methods);
|
||||
}
|
||||
|
||||
return $result->getMock();
|
||||
}
|
||||
|
||||
public function testTheStorageName()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->assertSame('dynamodb', $storage->getName());
|
||||
}
|
||||
|
||||
public function testDefaultKeyName()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->assertAttributeSame('Id', 'defaultKeyName', $storage);
|
||||
}
|
||||
|
||||
public function testThatTableKeysInitiallyEmpty()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->assertAttributeSame([], 'tableKeys', $storage);
|
||||
}
|
||||
|
||||
public function testDefaultKeyCannotBeSomethingOtherThanString()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$this->setExpectedException(
|
||||
'\Doctrine\KeyValueStore\KeyValueStoreException',
|
||||
'The key must be a string, got "array" instead.'
|
||||
);
|
||||
new DynamoDbStorage($client, null, []);
|
||||
}
|
||||
|
||||
public function testTableKeysMustAllBeStringsOrElse()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$this->setExpectedException(
|
||||
'\Doctrine\KeyValueStore\KeyValueStoreException',
|
||||
'The key must be a string, got "object" instead.'
|
||||
);
|
||||
new DynamoDbStorage($client, null, null, ['mytable' => 'hello', 'yourtable' => new \stdClass()]);
|
||||
}
|
||||
|
||||
public function testKeyNameMustBeUnder255Bytes()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$this->setExpectedException(
|
||||
'\Doctrine\KeyValueStore\KeyValueStoreException',
|
||||
'The name must be at least 1 but no more than 255 chars.'
|
||||
);
|
||||
new DynamoDbStorage($client, null, str_repeat('a', 256));
|
||||
}
|
||||
|
||||
public function invalidTableNames()
|
||||
{
|
||||
return [
|
||||
['a2'],
|
||||
['yo%'],
|
||||
['что'],
|
||||
['h@llo'],
|
||||
];
|
||||
}
|
||||
|
||||
public function validTableNames()
|
||||
{
|
||||
return [
|
||||
['MyTable'],
|
||||
['This_is0k-...'],
|
||||
['hello_world'],
|
||||
['...........00....'],
|
||||
];
|
||||
}
|
||||
|
||||
private function invokeMethod($methodName, $obj, array $args = null)
|
||||
{
|
||||
$relf = new \ReflectionObject($obj);
|
||||
$method = $relf->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
if ($args) {
|
||||
return $method->invokeArgs($obj, $args);
|
||||
}
|
||||
|
||||
return $method->invoke($obj);
|
||||
}
|
||||
|
||||
public function testTableNameMustBeAString()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->setExpectedException('\Doctrine\KeyValueStore\InvalidArgumentException');
|
||||
$this->invokeMethod('setKeyForTable', $storage, [[], 'Id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidTableNames
|
||||
*/
|
||||
public function testTableNameValidatesAgainstInvalidTableNames($tableName)
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->setExpectedException('\Doctrine\KeyValueStore\KeyValueStoreException');
|
||||
$this->invokeMethod('setKeyForTable', $storage, [$tableName, 'Id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validTableNames
|
||||
*/
|
||||
public function testTableNameValidatesAgainstValidTableNames($tableName)
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->invokeMethod('setKeyForTable', $storage, [$tableName, 'Id']);
|
||||
|
||||
$this->assertAttributeSame([$tableName => 'Id'], 'tableKeys', $storage);
|
||||
}
|
||||
|
||||
public function testThatYouCanHaveMultipleTablesWithOverrides()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->invokeMethod('setKeyForTable', $storage, ['Aaa', '2']);
|
||||
$this->invokeMethod('setKeyForTable', $storage, ['Bbb', '1']);
|
||||
|
||||
$this->assertAttributeSame(['Aaa' => '2', 'Bbb' => '1'], 'tableKeys', $storage);
|
||||
}
|
||||
|
||||
public function testGetterForDefaultKeyName()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client, null, 'CustomKey');
|
||||
$this->assertSame('CustomKey', $storage->getDefaultKeyName());
|
||||
}
|
||||
|
||||
public function testGetWillReturnDefaultKeyForUnrecognizedTableName()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client, null, 'CustomKey');
|
||||
$this->assertSame('CustomKey', $this->invokeMethod('getKeyNameForTable', $storage, ['whatever_this_is']));
|
||||
}
|
||||
|
||||
public function testGetWillReturnCorrectKeyForRecognizedTableName()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
$storage = new DynamoDbStorage($client, null, 'CustomKey', ['MyTable' => 'Yesss']);
|
||||
$this->assertSame('Yesss', $this->invokeMethod('getKeyNameForTable', $storage, ['MyTable']));
|
||||
}
|
||||
|
||||
public function testThatSomeStorageHasDifferentKey()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
|
||||
$storage = new DynamoDbStorage($client, null, 'sauce', ['this' => 'that', 'yolo' => 'now']);
|
||||
|
||||
$this->assertSame(['that' => ['N' => '111']], $this->invokeMethod('prepareKey', $storage, ['this', 111]));
|
||||
}
|
||||
|
||||
public function testThatSomeStorageUsesDefaultKey()
|
||||
{
|
||||
$client = $this->getDynamoDbMock();
|
||||
|
||||
$storage = new DynamoDbStorage($client, null, 'sauce', ['this' => 'that', 'yolo' => 'now']);
|
||||
|
||||
$this->assertSame(['sauce' => ['S' => 'hello']], $this->invokeMethod('prepareKey', $storage, ['MyTable', 'hello']));
|
||||
}
|
||||
|
||||
public function testInsertingCallsAPutItem()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['putItem']);
|
||||
|
||||
$client->expects($this->once())->method('putItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Item' => [
|
||||
'Id' => ['S' => 'stuff'],
|
||||
'hi' => ['S' => 'there'],
|
||||
'yo' => ['BOOL' => false],
|
||||
],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->insert('MyTable', 'stuff', ['hi' => 'there', 'yo' => false]);
|
||||
}
|
||||
|
||||
public function testInsertingPreparesNestedAttributes()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['putItem']);
|
||||
|
||||
$client->expects($this->once())->method('putItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Item' => [
|
||||
'Id' => ['S' => 'stuff'],
|
||||
'hi' => ['S' => 'there'],
|
||||
'what' => ['L' => [
|
||||
['S' => 'Yep'],
|
||||
]],
|
||||
'yo' => ['BOOL' => false],
|
||||
],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->insert('MyTable', 'stuff', ['hi' => 'there', 'yo' => false, 'what' => ['Yep', '']]);
|
||||
}
|
||||
|
||||
public function testUpdateActuallyAlsoCallsInsert()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['putItem']);
|
||||
|
||||
$client->expects($this->once())->method('putItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Item' => [
|
||||
'Id' => ['S' => 'stuff'],
|
||||
'hi' => ['S' => 'there'],
|
||||
'yo' => ['BOOL' => false],
|
||||
],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->update('MyTable', 'stuff', ['hi' => 'there', 'yo' => false]);
|
||||
}
|
||||
|
||||
public function testDeleteItem()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['deleteItem']);
|
||||
|
||||
$client->expects($this->once())->method('deleteItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Key' => ['Id' => ['S' => 'abc123']],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->delete('MyTable', 'abc123');
|
||||
}
|
||||
|
||||
public function testDeleteItemWithKeyValuePair()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['deleteItem']);
|
||||
|
||||
$client->expects($this->once())->method('deleteItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Key' => ['Id' => ['S' => 'abc123']],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->delete('MyTable', ['Id' => 'abc123']);
|
||||
}
|
||||
|
||||
public function testPassingArrayAsKeyIsAPassthruToInsert()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['deleteItem']);
|
||||
|
||||
$client->expects($this->once())->method('deleteItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'Key' => ['Id' => ['S' => 'abc123']],
|
||||
]));
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$storage->delete('MyTable', 'abc123');
|
||||
}
|
||||
|
||||
public function testTryingToFindAnItemThatDoesNotExist()
|
||||
{
|
||||
$client = $this->getDynamoDbMock(['getItem']);
|
||||
$client->expects($this->once())->method('getItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'ConsistentRead' => true,
|
||||
'Key' => ['Id' => ['N' => '1000']],
|
||||
]))->willReturn(null);
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$this->setExpectedException(
|
||||
'\Doctrine\KeyValueStore\NotFoundException',
|
||||
'Could not find an item with key: 1000'
|
||||
);
|
||||
$storage->find('MyTable', 1000);
|
||||
}
|
||||
|
||||
public function testFindAnItemThatExists()
|
||||
{
|
||||
$result = $this->getDynamoDbResultMock(['get']);
|
||||
$result->expects($this->once())->method('get')->with('Item')->willReturn([
|
||||
'hello' => ['S' => 'world'],
|
||||
]);
|
||||
|
||||
$client = $this->getDynamoDbMock(['getItem']);
|
||||
$client->expects($this->once())->method('getItem')->with($this->equalTo([
|
||||
'TableName' => 'MyTable',
|
||||
'ConsistentRead' => true,
|
||||
'Key' => ['Id' => ['N' => '1000']],
|
||||
]))->willReturn($result);
|
||||
|
||||
$storage = new DynamoDbStorage($client);
|
||||
$actualResult = $storage->find('MyTable', 1000);
|
||||
|
||||
$this->assertSame(['hello' => 'world'], $actualResult);
|
||||
}
|
||||
}
|
||||
@@ -20,34 +20,38 @@
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Storage\MongoDbStorage;
|
||||
use MongoDB\Client;
|
||||
|
||||
/**
|
||||
* MongoDb storage testcase
|
||||
*
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
*
|
||||
* @covers \Doctrine\KeyValueStore\Storage\MongoDbStorage
|
||||
* @requires extension mongodb
|
||||
* @group legacy
|
||||
* @requires extension mongo
|
||||
*/
|
||||
class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var MongoDbStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->client = new Client();
|
||||
$this->storage = new MongoDbStorage($this->client->test);
|
||||
$this->mongo = $this->getMock('\Mongo');
|
||||
|
||||
$this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$this->mongo->expects($this->any())
|
||||
->method('selectDB')
|
||||
->will($this->returnValue($this->mongodb));
|
||||
|
||||
$this->collection = $this->getMockBuilder('MongoCollection')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$this->mongodb->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->will($this->returnValue($this->collection));
|
||||
|
||||
$this->storage = new MongoDbStorage($this->mongo, [
|
||||
'collection' => 'test',
|
||||
'database' => 'test',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
@@ -57,21 +61,20 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('mongodb', 'testInsert', $data);
|
||||
$dbDataset = [];
|
||||
|
||||
$result = $this->client
|
||||
->test
|
||||
->mongodb
|
||||
->findOne([
|
||||
'key' => 'testInsert',
|
||||
]);
|
||||
$this->collection->expects($this->once())
|
||||
->method('insert')
|
||||
->will($this->returnCallback(function ($data) use (&$dbDataset) {
|
||||
$dbDataset[] = $data;
|
||||
}));
|
||||
|
||||
$this->assertSame($data, $result['value']->getArrayCopy());
|
||||
$this->storage->insert('mongodb', '1', $data);
|
||||
$this->assertCount(1, $dbDataset);
|
||||
|
||||
$this->assertEquals([['key' => '1', 'value' => $data]], $dbDataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = [
|
||||
@@ -79,67 +82,80 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('mongodb', 'testUpdate', [
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
$this->storage->update('mongodb', 'testUpdate', $data);
|
||||
$dbDataset = [];
|
||||
|
||||
$result = $this->client
|
||||
->test
|
||||
->mongodb
|
||||
->findOne([
|
||||
'key' => 'testUpdate',
|
||||
]);
|
||||
$this->collection->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->returnCallback(function ($citeria, $data) use (&$dbDataset) {
|
||||
$dbDataset = [$citeria, $data];
|
||||
}));
|
||||
|
||||
$this->assertSame($data, $result['value']->getArrayCopy());
|
||||
$this->storage->update('mongodb', '1', $data);
|
||||
|
||||
$this->assertEquals(['key' => '1'], $dbDataset[0]);
|
||||
$this->assertEquals(['key' => '1', 'value' => $data], $dbDataset[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->storage->insert('mongodb', 'testDelete', [
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
$dataset = [
|
||||
[
|
||||
'key' => 'foobar',
|
||||
'value' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->storage->delete('mongodb', 'testDelete');
|
||||
$this->collection->expects($this->once())
|
||||
->method('remove')
|
||||
->will($this->returnCallback(function ($citeria) use (&$dataset) {
|
||||
foreach ($dataset as $key => $row) {
|
||||
if ($row['key'] === $citeria['key']) {
|
||||
unset($dataset[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
$result = $this->client
|
||||
->test
|
||||
->mongodb
|
||||
->findOne([
|
||||
'key' => 'testDelete',
|
||||
]);
|
||||
$this->storage->delete('test', 'foobar');
|
||||
|
||||
$this->assertNull($result);
|
||||
$this->assertCount(0, $dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
$dataset = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
[
|
||||
'key' => 'foobar',
|
||||
'value' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->storage->insert('mongodb', 'testFind', $dataset);
|
||||
$this->collection->expects($this->once())
|
||||
->method('findOne')
|
||||
->will($this->returnCallback(function ($citeria, $fields) use (&$dataset) {
|
||||
foreach ($dataset as $key => $row) {
|
||||
if ($row['key'] === $citeria['key']) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
$data = $this->storage->find('mongodb', 'testFind');
|
||||
$data = $this->storage->find('test', 'foobar');
|
||||
|
||||
$this->assertEquals($dataset, $data);
|
||||
}
|
||||
|
||||
public function testFindWithNotExistKey()
|
||||
{
|
||||
$this->setExpectedException(NotFoundException::class);
|
||||
$this->storage->find('mongodb', 'not-existing-key');
|
||||
$this->assertEquals($dataset[0]['value'], $data);
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->storage->initialize();
|
||||
|
||||
$this->assertEquals('mongodb', $this->storage->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use Doctrine\KeyValueStore\Storage\RedisStorage;
|
||||
/**
|
||||
* @author Marcel Araujo <admin@marcelaraujo.me>
|
||||
*
|
||||
* @group legacy
|
||||
* @requires extension redis
|
||||
*/
|
||||
class RedisStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
@@ -20,46 +20,32 @@
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Storage\RiakStorage;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Riak\Client\Command\Kv\Builder\ListKeysBuilder;
|
||||
use Riak\Client\Command\Kv\FetchValue;
|
||||
use Riak\Client\Core\Query\RiakLocation;
|
||||
use Riak\Client\Core\Query\RiakNamespace;
|
||||
use Riak\Client\Core\Query\RiakObject;
|
||||
use Riak\Client\Core\Transport\RiakTransportException;
|
||||
use Riak\Client\RiakClient;
|
||||
use Riak\Client\RiakClientBuilder;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class RiakStorageTest extends PHPUnit_Framework_TestCase
|
||||
class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var RiakClient
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var RiakStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
protected function setUp()
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $riak;
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
$dns = getenv('RIAK_DNS');
|
||||
$this->riak = $this->getMockBuilder('Riak\\Client')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
if (empty($dns)) {
|
||||
$this->markTestSkipped('Missing Riak DNS');
|
||||
}
|
||||
|
||||
$this->client = (new RiakClientBuilder())
|
||||
->withNodeUri($dns)
|
||||
->build();
|
||||
|
||||
$this->storage = new RiakStorage($this->client);
|
||||
$this->storage = new RiakStorage($this->riak);
|
||||
}
|
||||
|
||||
public function testSupportsPartialUpdates()
|
||||
@@ -79,124 +65,186 @@ class RiakStorageTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Riak test',
|
||||
];
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->storage->insert('riak-test', 'foobar', $data);
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$location = $this->getRiakLocation();
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$fetch = FetchValue::builder($location)->build();
|
||||
$objectMock->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
$json = (string) $this->client
|
||||
->execute($fetch)
|
||||
->getValue()
|
||||
->getValue();
|
||||
$that = $this;
|
||||
$bucket->expects($this->once())
|
||||
->method('newObject')
|
||||
->will($this->returnCallback(function ($key, $data) use ($objectMock, $that) {
|
||||
$that->assertEquals('foobar', $key);
|
||||
$that->assertEquals(['title' => 'Riak test'], $data);
|
||||
return $objectMock;
|
||||
}));
|
||||
|
||||
$this->assertSame($data, json_decode($json, true));
|
||||
$this->storage->insert('riak-test', 'foobar', ['title' => 'Riak test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Riak update',
|
||||
];
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->storage->insert('riak-test', 'foobar', [
|
||||
'title' => 'Riak insert',
|
||||
]);
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$location = $this->getRiakLocation();
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$this->assertTotalBucketKeys(1, $location);
|
||||
$bucket->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
$this->storage->update('riak-test', 'foobar', $data);
|
||||
$that = $this;
|
||||
$objectMock->expects($this->once())
|
||||
->method('setData')
|
||||
->will($this->returnCallback(function ($data) use ($that) {
|
||||
$that->assertEquals(['title' => 'Riak cookbook'], $data);
|
||||
}));
|
||||
|
||||
$fetch = FetchValue::builder($location)->build();
|
||||
$objectMock->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
$json = (string) $this->client
|
||||
->execute($fetch)
|
||||
->getValue()
|
||||
->getValue();
|
||||
|
||||
$this->assertSame($data, json_decode($json, true));
|
||||
$this->assertTotalBucketKeys(1, $location);
|
||||
$this->storage->update('riak-test', 'foobar', ['title' => 'Riak cookbook']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->testInsert();
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$bucket->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$this->storage->delete('riak-test', 'foobar');
|
||||
|
||||
$location = $this->getRiakLocation();
|
||||
|
||||
$fetch = FetchValue::builder($location)->build();
|
||||
|
||||
$this->setExpectedException(RiakTransportException::class);
|
||||
$this->client->execute($fetch);
|
||||
|
||||
$this->assertTotalBucketKeys(0, $location);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDelete
|
||||
*/
|
||||
public function testDeleteWithNotExistKey()
|
||||
{
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$bucket->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$objectMock->expects($this->never())
|
||||
->method('delete');
|
||||
|
||||
$this->storage->delete('riak-test', 'foobar');
|
||||
$this->storage->delete('riak-test', 'foobar');
|
||||
}
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$bucket->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('getData')
|
||||
->will($this->returnValue(['title' => 'Riak Test']));
|
||||
|
||||
$this->assertEquals(['title' => 'Riak Test'], $this->storage->find('riaktest', 'foobar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testInsert
|
||||
* @expectedException Doctrine\KeyValueStore\NotFoundException
|
||||
*/
|
||||
public function testFind()
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Riak test',
|
||||
];
|
||||
|
||||
$this->storage->insert('riak-test', 'foobar', $data);
|
||||
|
||||
$result = $this->storage->find('riak-test', 'foobar');
|
||||
|
||||
$this->assertSame($data, $result);
|
||||
}
|
||||
|
||||
public function testFindWithNotExistKey()
|
||||
{
|
||||
$this->setExpectedException(NotFoundException::class);
|
||||
$this->storage->find('riak-test', 'foobar-1');
|
||||
$objectMock = $this->getMockBuilder('Riak\Object')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$bucket = $this->getMockBuilder('Riak\Bucket')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->riak->expects($this->once())
|
||||
->method('bucket')
|
||||
->will($this->returnValue($bucket));
|
||||
|
||||
$bucket->expects($this->once())
|
||||
->method('get')
|
||||
->with('foobar')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$objectMock->expects($this->never())
|
||||
->method('getData');
|
||||
|
||||
$this->storage->find('riak-test', 'foobar');
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('riak', $this->storage->getName());
|
||||
}
|
||||
|
||||
private function assertTotalBucketKeys($expectedTotal, $location)
|
||||
{
|
||||
$command = (new ListKeysBuilder($location->getNamespace()))->build();
|
||||
|
||||
$iterator = $this->client
|
||||
->execute($command)
|
||||
->getIterator();
|
||||
|
||||
$this->assertCount($expectedTotal, iterator_to_array($iterator));
|
||||
}
|
||||
|
||||
private function getRiakLocation()
|
||||
{
|
||||
$namespace = new RiakNamespace('default', 'riak-test');
|
||||
|
||||
return new RiakLocation($namespace, 'foobar');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace Doctrine\Tests\KeyValueStore\Storage\WindowsAzureTable;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\SharedKeyLiteAuthorization;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SharedKeyLiteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $auth;
|
||||
|
||||
@@ -20,25 +20,20 @@
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class WindowsAzureTableStorageTest extends AbstractStorageTestCase
|
||||
{
|
||||
private $client;
|
||||
|
||||
protected function createStorage()
|
||||
{
|
||||
$this->client = $this
|
||||
->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$auth = $this
|
||||
->getMockBuilder(AuthorizationSchema::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->client = $this->getMock('Doctrine\KeyValueStore\Http\Client');
|
||||
$auth = $this->getMock('Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema');
|
||||
$auth->expects($this->any())->method('signRequest')->will($this->returnValue('Authorization: SharedKeyLite testaccount1:uay+rilMVayH/SVI8X+a3fL8k/NxCnIePdyZSkqvydM='));
|
||||
|
||||
$storage = new WindowsAzureTableStorage(
|
||||
|
||||
@@ -26,6 +26,9 @@ use Doctrine\KeyValueStore\EntityManager;
|
||||
use Doctrine\KeyValueStore\Mapping;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
abstract class KeyValueStoreTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function createManager($storage = null, $driver = 'annotation')
|
||||
|
||||
@@ -7,5 +7,7 @@ sudo apt-get install -y libuv-dev libssl-dev
|
||||
cd /tmp && git clone https://github.com/datastax/php-driver.git && cd php-driver && git submodule update --init
|
||||
cd ext && ./install.sh && cd "$TRAVIS_BUILD_DIR"
|
||||
echo "extension=cassandra.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
|
||||
# PHP extensions
|
||||
yes | pecl install mongo
|
||||
# PECL extensions
|
||||
echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
|
||||
|
||||
Reference in New Issue
Block a user