mirror of
https://github.com/doctrine/KeyValueStore.git
synced 2026-03-24 16:52:17 +01:00
Compare commits
119 Commits
v0.2
...
tests/refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2b752033f | ||
|
|
eaa95e0e96 | ||
|
|
90d29ad6c7 | ||
|
|
66864cbbee | ||
|
|
02cb83edd1 | ||
|
|
8f17913f4b | ||
|
|
cf6bd490f4 | ||
|
|
18e9faf50d | ||
|
|
aeb6db5d98 | ||
|
|
8ba3db4ce7 | ||
|
|
bb1ba64453 | ||
|
|
903f6a8c97 | ||
|
|
0a5917a2a9 | ||
|
|
b7daeb0d19 | ||
|
|
06e11dae33 | ||
|
|
4584d99529 | ||
|
|
54e05f9acd | ||
|
|
4d4a17aca9 | ||
|
|
b2a4e320b0 | ||
|
|
b2906e209e | ||
|
|
f29622194e | ||
|
|
2517bb04c5 | ||
|
|
a0d85c1c27 | ||
|
|
0d9c10edf2 | ||
|
|
606ca8b29d | ||
|
|
1ffab2e77d | ||
|
|
e0878ca97a | ||
|
|
7877050062 | ||
|
|
cc3e478d10 | ||
|
|
79bee991a2 | ||
|
|
f61ce21d4b | ||
|
|
58f98f8a94 | ||
|
|
902da8f693 | ||
|
|
84d5db7073 | ||
|
|
ef425578fb | ||
|
|
518f4211b0 | ||
|
|
bad3b56f4b | ||
|
|
2836bc0cfd | ||
|
|
6000d76099 | ||
|
|
b095170bdc | ||
|
|
fe7195fc2d | ||
|
|
e282c1d9f6 | ||
|
|
e2f7ea54f7 | ||
|
|
03a2413e99 | ||
|
|
2c99b71d19 | ||
|
|
fe1e155e69 | ||
|
|
ec14ab554a | ||
|
|
3c7ba8415e | ||
|
|
69832f5423 | ||
|
|
709d464881 | ||
|
|
ba3ff63080 | ||
|
|
50de14012f | ||
|
|
a3827e94b6 | ||
|
|
82486729dd | ||
|
|
f2ef7d7445 | ||
|
|
dc4eca67e4 | ||
|
|
b5c77d93cf | ||
|
|
bb723cc9c7 | ||
|
|
3c3eaad3c9 | ||
|
|
23d6c6dc5d | ||
|
|
793fe5fd16 | ||
|
|
43a1a21670 | ||
|
|
1e9593c80d | ||
|
|
8b9f7317f9 | ||
|
|
f4d0647400 | ||
|
|
56222890f7 | ||
|
|
7b92465aab | ||
|
|
f1446ee0ff | ||
|
|
4e5c6832aa | ||
|
|
aa062f3c74 | ||
|
|
5da1efcd7c | ||
|
|
19d3e788b3 | ||
|
|
b058d0b1d5 | ||
|
|
a7659c3d33 | ||
|
|
643506cf18 | ||
|
|
17b7a2e729 | ||
|
|
eb3806273b | ||
|
|
ba9548ed41 | ||
|
|
1601d59831 | ||
|
|
762c8422f5 | ||
|
|
9a8c3a6a8b | ||
|
|
ac55f6db27 | ||
|
|
ca4ffbfeb6 | ||
|
|
3627014280 | ||
|
|
5de6e13d5b | ||
|
|
2e8ba39b41 | ||
|
|
63545c934c | ||
|
|
a9b34ac958 | ||
|
|
3dd1aa7c38 | ||
|
|
d61b7e0dea | ||
|
|
802cb1520e | ||
|
|
b15bbc62fd | ||
|
|
b94d29514d | ||
|
|
d32fe1fb9d | ||
|
|
add84a7116 | ||
|
|
b919fc70f9 | ||
|
|
6b26ceb284 | ||
|
|
dd3a9e6c9e | ||
|
|
32e017b58d | ||
|
|
67e44a7683 | ||
|
|
32d528d02a | ||
|
|
927fc52193 | ||
|
|
0f6efb76f9 | ||
|
|
00c8e1fa46 | ||
|
|
82b302dc58 | ||
|
|
bb408e2503 | ||
|
|
11747c4112 | ||
|
|
f3ed9bacae | ||
|
|
78e3abb0e5 | ||
|
|
1998fc5022 | ||
|
|
f331d4c994 | ||
|
|
e775ffbe8f | ||
|
|
d5690b4108 | ||
|
|
25d4376582 | ||
|
|
dff781a668 | ||
|
|
741a04e1d9 | ||
|
|
d9f49bef92 | ||
|
|
9de4cd1c85 | ||
|
|
296947bd24 |
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
||||
; This file is for unifying the coding style for different editors and IDEs.
|
||||
; More information at http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
vendor
|
||||
*phpunit.xml
|
||||
docs/_build
|
||||
/composer.lock
|
||||
|
||||
82
.php_cs
Normal file
82
.php_cs
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
$header = <<<EOF
|
||||
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>.
|
||||
EOF;
|
||||
|
||||
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
|
||||
|
||||
$config = Symfony\CS\Config\Config::create()
|
||||
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
|
||||
->fixers([
|
||||
'blankline_after_open_tag',
|
||||
'empty_return',
|
||||
'extra_empty_lines',
|
||||
'function_typehint_space',
|
||||
'join_function',
|
||||
'method_argument_default_value',
|
||||
'multiline_array_trailing_comma',
|
||||
'no_blank_lines_after_class_opening',
|
||||
'no_empty_lines_after_phpdocs',
|
||||
'phpdoc_indent',
|
||||
'phpdoc_no_access',
|
||||
'phpdoc_no_empty_return',
|
||||
'phpdoc_no_package',
|
||||
'phpdoc_params',
|
||||
'phpdoc_scalar',
|
||||
'phpdoc_separation',
|
||||
'phpdoc_trim',
|
||||
'phpdoc_type_to_var',
|
||||
'phpdoc_types',
|
||||
'phpdoc_var_without_name',
|
||||
'pre_increment',
|
||||
'remove_leading_slash_use',
|
||||
'remove_lines_between_uses',
|
||||
'short_bool_cast',
|
||||
'single_quote',
|
||||
'spaces_after_semicolon',
|
||||
'spaces_before_semicolon',
|
||||
'spaces_cast',
|
||||
'standardize_not_equal',
|
||||
'ternary_spaces',
|
||||
'trim_array_spaces',
|
||||
'unneeded_control_parentheses',
|
||||
'unused_use',
|
||||
'whitespacy_lines',
|
||||
'align_double_arrow',
|
||||
'align_equals',
|
||||
'concat_with_spaces',
|
||||
'header_comment',
|
||||
'logical_not_operators_with_successor_space',
|
||||
'multiline_spaces_before_semicolon',
|
||||
'newline_after_open_tag',
|
||||
'ordered_use',
|
||||
'php_unit_construct',
|
||||
'phpdoc_order',
|
||||
'short_array_syntax',
|
||||
]);
|
||||
|
||||
if (null === $input->getArgument('path')) {
|
||||
$config
|
||||
->finder(
|
||||
Symfony\CS\Finder\DefaultFinder::create()
|
||||
->in('lib/')
|
||||
->in('tests/')
|
||||
);
|
||||
}
|
||||
|
||||
return $config;
|
||||
21
.travis.yml
Normal file
21
.travis.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
language: php
|
||||
|
||||
services:
|
||||
- mongodb
|
||||
- redis-server
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
before_install:
|
||||
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TRAVIS_PHP_VERSION != "7.0" ]]; then sh ./tests/travis.sh; fi
|
||||
- composer self-update
|
||||
|
||||
install:
|
||||
- composer --prefer-source install
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit --verbose
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2015 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,5 +1,7 @@
|
||||
# Doctrine Key Value Stores
|
||||
|
||||
[](https://travis-ci.org/doctrine/KeyValueStore)
|
||||
|
||||
The Persistence interfaces are rather overkill for many implementations in the NoSQL world that are only key-value stores with some additional features on top. Doctrine Key Value Store to the rescue. This project offers a much simpler lightweight API that is centered on a key-value API to fetch/save objects.
|
||||
|
||||
* Single- or multi-value primary keys
|
||||
@@ -10,7 +12,7 @@ The Persistence interfaces are rather overkill for many implementations in the N
|
||||
* No support for references to other objects
|
||||
* EventListener for ODM/ORM that allows to manage key-value entities and collections of them as properties (postLoad, postUpdate, postPersist, postRemove)
|
||||
* Stripped down Object Manager Interface
|
||||
* Data-mapper as any other Doctrine library and persistence and data-objects are seperated.
|
||||
* Data-mapper as any other Doctrine library and persistence and data-objects are separated.
|
||||
* Inheritance (Single- or Multiple-Storage)
|
||||
|
||||
## Implementations
|
||||
@@ -21,8 +23,9 @@ Following vendors are targeted:
|
||||
* Doctrine\Common\Cache provider (Implemented)
|
||||
* RDBMS (Implemented)
|
||||
* Couchbase (Implemented)
|
||||
* Amazon DynamoDB
|
||||
* CouchDB
|
||||
* Amazon DynamoDB (Implemented)
|
||||
* CouchDB (Implemented)
|
||||
* Cassandra
|
||||
* MongoDB (Implemented)
|
||||
* Riak (Implemented)
|
||||
* Redis (Implemented)
|
||||
|
||||
@@ -1,28 +1,33 @@
|
||||
{
|
||||
"name": "doctrine/key-value-store",
|
||||
"require": {
|
||||
"doctrine/common": "*"
|
||||
"php": "^5.5|^7.0",
|
||||
"doctrine/common": "^2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"riak/riak-client": "dev-master",
|
||||
"microsoft/windowsazure": "dev-master"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "pear",
|
||||
"url": "http://pear.php.net"
|
||||
}
|
||||
],
|
||||
"datastax/php-driver": "^1.0",
|
||||
"doctrine/couchdb": "^1.0.0-beta4",
|
||||
"phpunit/phpunit": "^4.8|^5.0",
|
||||
"aws/aws-sdk-php": "^3.8",
|
||||
"riak/riak-client": "dev-master"
|
||||
},
|
||||
"suggest": {
|
||||
"riak/riak-client": "to use the Riak storage",
|
||||
"aws/aws-sdk-php": "to use the DynamoDB storage",
|
||||
"doctrine/couchdb": "to use the CouchDB storage",
|
||||
"ext-couchbase": "to use the Couchbase storage",
|
||||
"aws/aws-sdk-php": "to use the DynamoDB 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",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\KeyValueStore\\": "lib/"
|
||||
"psr-4": {
|
||||
"Doctrine\\KeyValueStore\\": "lib/Doctrine/KeyValueStore"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
|
||||
"Doctrine\\KeyValueStore\\": "tests/Doctrine/KeyValueStore"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
752
composer.lock
generated
752
composer.lock
generated
@@ -1,752 +0,0 @@
|
||||
{
|
||||
"hash": "bf53cb71537abb0dbed5002bbc4411f1",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
"version": "v1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/annotations.git",
|
||||
"reference": "v1.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/annotations/archive/v1.0.zip",
|
||||
"reference": "v1.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"doctrine/lexer": "1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "1.*"
|
||||
},
|
||||
"time": "2013-01-12 19:23:32",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\Annotations\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com",
|
||||
"homepage": "http://www.jwage.com/"
|
||||
},
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Docblock Annotations Parser",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"annotations",
|
||||
"parser",
|
||||
"docblock"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
"version": "v1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/cache.git",
|
||||
"reference": "v1.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/cache/archive/v1.0.zip",
|
||||
"reference": "v1.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"time": "2013-01-10 22:43:46",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\Cache\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com",
|
||||
"homepage": "http://www.jwage.com/"
|
||||
},
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Caching library offering an object-oriented API for many cache backends",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"caching"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "doctrine/collections",
|
||||
"version": "v1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/collections.git",
|
||||
"reference": "v1.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/collections/archive/v1.0.zip",
|
||||
"reference": "v1.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"time": "2013-01-12 16:36:50",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\Collections\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com",
|
||||
"homepage": "http://www.jwage.com/"
|
||||
},
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Collections Abstraction library",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"collections",
|
||||
"iterator",
|
||||
"array"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "doctrine/common",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/common",
|
||||
"reference": "f0b548aa55bb7dac36d79061270a085dd38635b4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/common/archive/a5482b347530bb8522e355b399e5ff4983433a40.zip",
|
||||
"reference": "a5482b347530bb8522e355b399e5ff4983433a40",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"doctrine/inflector": "1.*",
|
||||
"doctrine/cache": "1.*",
|
||||
"doctrine/collections": "1.*",
|
||||
"doctrine/lexer": "1.*",
|
||||
"doctrine/annotations": "1.*"
|
||||
},
|
||||
"time": "2012-06-18 14:14:07",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.4.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com",
|
||||
"homepage": "http://www.jwage.com/"
|
||||
},
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Common Library for Doctrine projects",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"collections",
|
||||
"spl",
|
||||
"eventmanager",
|
||||
"annotations",
|
||||
"persistence"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "doctrine/inflector",
|
||||
"version": "v1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/inflector.git",
|
||||
"reference": "v1.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/inflector/archive/v1.0.zip",
|
||||
"reference": "v1.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"time": "2013-01-10 21:49:15",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\Inflector\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com",
|
||||
"homepage": "http://www.jwage.com/"
|
||||
},
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Common String Manipulations with regard to casing and singular/plural rules.",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"string",
|
||||
"inflection",
|
||||
"singuarlize",
|
||||
"pluarlize"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
"version": "v1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/lexer.git",
|
||||
"reference": "v1.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/doctrine/lexer/archive/v1.0.zip",
|
||||
"reference": "v1.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"time": "2013-01-12 18:59:04",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Doctrine\\Common\\Lexer\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com",
|
||||
"homepage": "http://www.instaclick.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
"description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.",
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"lexer"
|
||||
]
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "microsoft/windowsazure",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/WindowsAzure/azure-sdk-for-php",
|
||||
"reference": "d8daa05ad1852e0c70a85d15a6db88f7e3b23405"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/WindowsAzure/azure-sdk-for-php/archive/d8daa05ad1852e0c70a85d15a6db88f7e3b23405.zip",
|
||||
"reference": "d8daa05ad1852e0c70a85d15a6db88f7e3b23405",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"pear-pear/http_request2": "*",
|
||||
"pear-pear/mail_mime": "*",
|
||||
"pear-pear/mail_mimedecode": "*"
|
||||
},
|
||||
"time": "2012-12-17 23:41:42",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"WindowsAzure\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Azure PHP SDK",
|
||||
"email": "azurephpsdk@microsoft.com"
|
||||
}
|
||||
],
|
||||
"description": "This project provides a set of PHP client libraries that make it easy to access Windows Azure tables, blobs, queues, service runtime and service management APIs.",
|
||||
"keywords": [
|
||||
"php",
|
||||
"sdk",
|
||||
"azure"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Archive_Tar",
|
||||
"version": "1.3.10",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Archive_Tar-1.3.10.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.3.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/archive_tar": "== 1.3.10.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "This class provides handling of tar files in PHP.\nIt supports creating, listing, extracting and adding to tar files.\nGzip support is available if PHP has the zlib extension built-in or\nloaded. Bz2 compression is also supported with the bz2 extension loaded."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Console_Getopt",
|
||||
"version": "1.3.1",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Console_Getopt-1.3.1.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.3.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/console_getopt": "== 1.3.1.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "This is a PHP implementation of "getopt" supporting both\nshort and long options."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/HTTP_Request2",
|
||||
"version": "2.1.1",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/HTTP_Request2-2.1.1.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.0.0",
|
||||
"pear-pear.php.net/net_url2": ">=2.0.0.0",
|
||||
"pear-pear.php.net/pear": ">=1.9.2.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/http_request2": "== 2.1.1.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "PHP5 rewrite of HTTP_Request package (with parts of HTTP_Client). Provides\ncleaner API and pluggable Adapters:\n * Socket adapter, based on old HTTP_Request code,\n * Curl adapter, wraps around PHP's cURL extension,\n * Mock adapter, to use for testing packages dependent on HTTP_Request2.\nSupports POST requests with data and file uploads, basic and digest\nauthentication, cookies, managing cookies across requests, proxies, gzip and\ndeflate encodings, redirects, monitoring the request progress with Observers..."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Mail_Mime",
|
||||
"version": "1.8.7",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Mail_Mime-1.8.7.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.3.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/mail_mime": "== 1.8.7.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "Mail_Mime provides classes to deal with the creation and manipulation of MIME messages.\nIt allows people to create e-mail messages consisting of:\n* Text Parts\n* HTML Parts\n* Inline HTML Images\n* Attachments\n* Attached messages\n\nIt supports big messages, base64 and quoted-printable encodings and\nnon-ASCII characters in filenames, subjects, recipients, etc. encoded\nusing RFC2047 and/or RFC2231."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Mail_mimeDecode",
|
||||
"version": "1.5.5",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Mail_mimeDecode-1.5.5.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.3.0.0",
|
||||
"pear-pear.php.net/mail_mime": ">1.4.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/mail_mimedecode": "== 1.5.5.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "Provides a class to deal with the decoding and interpreting of mime messages.\n This package used to be part of the Mail_Mime package, but has been split off."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Net_URL2",
|
||||
"version": "2.0.0",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Net_URL2-2.0.0.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.0.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/net_url2": "== 2.0.0.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "Provides parsing of URLs into their constituent parts (scheme, host, path etc.), URL generation, and resolving of relative URLs."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/PEAR",
|
||||
"version": "1.9.4",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/PEAR-1.9.4.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.4.0.0,!=5.0.0.0,!=5.1.0.0,!=5.1.1.0,!=5.1.2.0,!=5.1.3.0,!=5.1.4.0,!=5.1.5.0",
|
||||
"pear-pear.php.net/archive_tar": ">=1.3.7.0",
|
||||
"pear-pear.php.net/structures_graph": ">=1.0.2.0",
|
||||
"pear-pear.php.net/console_getopt": ">=1.2.0.0",
|
||||
"pear-pear.php.net/xml_util": ">=1.2.0.0",
|
||||
"ext-xml": "*",
|
||||
"ext-pcre": "*"
|
||||
},
|
||||
"conflict": {
|
||||
"pear-pear.php.net/pear_frontend_web": "<=0.4.0.0",
|
||||
"pear-pear.php.net/pear_frontend_gtk": "<0.4.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/pear": "== 1.9.4.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "The PEAR package contains:\n * the PEAR installer, for creating, distributing\n and installing packages\n * the PEAR_Exception PHP5 error handling mechanism\n * the PEAR_ErrorStack advanced error handling mechanism\n * the PEAR_Error error handling mechanism\n * the OS_Guess class for retrieving info about the OS\n where PHP is running on\n * the System class for quick handling of common operations\n with files and directories\n * the PEAR base class\n Features in a nutshell:\n * full support for channels\n * pre-download dependency validation\n * new package.xml 2.0 format allows tremendous flexibility while maintaining BC\n * support for optional dependency groups and limited support for sub-packaging\n * robust dependency support\n * full dependency validation on uninstall\n * remote install for hosts with only ftp access - no more problems with\n restricted host installation\n * full support for mirroring\n * support for bundling several packages into a single tarball\n * support for static dependencies on a url-based package\n * support for custom file roles and installation tasks"
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/Structures_Graph",
|
||||
"version": "1.0.4",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/Structures_Graph-1.0.4.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.2.0.0"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/structures_graph": "== 1.0.4.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "Structures_Graph is a package for creating and manipulating graph datastructures. It allows building of directed\nand undirected graphs, with data and metadata stored in nodes. The library provides functions for graph traversing\nas well as for characteristic extraction from the graph topology."
|
||||
},
|
||||
{
|
||||
"name": "pear-pear.php.net/XML_Util",
|
||||
"version": "1.2.1",
|
||||
"dist": {
|
||||
"type": "file",
|
||||
"url": "http://pear.php.net/get/XML_Util-1.2.1.tgz",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.3.0.0",
|
||||
"ext-pcre": "*"
|
||||
},
|
||||
"replace": {
|
||||
"pear-pear/xml_util": "== 1.2.1.0"
|
||||
},
|
||||
"type": "pear-library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"include-path": [
|
||||
"/"
|
||||
],
|
||||
"description": "Selection of methods that are often needed when working with XML documents. Functionality includes creating of attribute lists from arrays, creation of tags, validation of XML names and more."
|
||||
},
|
||||
{
|
||||
"name": "riak/riak-client",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nacmartin/riak-client",
|
||||
"reference": "cea446f04d759caaef44020a2064a38b41cbdfab"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/nacmartin/riak-client/archive/cea446f04d759caaef44020a2064a38b41cbdfab.zip",
|
||||
"reference": "cea446f04d759caaef44020a2064a38b41cbdfab",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"time": "2012-04-29 11:47:45",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Riak": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache 2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nacho Martín",
|
||||
"email": "nitram.ohcan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Kevin Burns"
|
||||
},
|
||||
{
|
||||
"name": "Jeffrey Massung"
|
||||
},
|
||||
{
|
||||
"name": "Mark Phillips"
|
||||
},
|
||||
{
|
||||
"name": "Bryank Fink"
|
||||
},
|
||||
{
|
||||
"name": "Abel Perez"
|
||||
},
|
||||
{
|
||||
"name": "Scoyy Lystig Fritchie"
|
||||
},
|
||||
{
|
||||
"name": "Jon Meredith"
|
||||
},
|
||||
{
|
||||
"name": "dreverri"
|
||||
},
|
||||
{
|
||||
"name": "fakepop"
|
||||
}
|
||||
],
|
||||
"description": "Riak client",
|
||||
"homepage": "http://wiki.basho.com/Riak.html",
|
||||
"keywords": [
|
||||
"persistence",
|
||||
"riak"
|
||||
]
|
||||
}
|
||||
],
|
||||
"aliases": [
|
||||
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"riak/riak-client": 20,
|
||||
"microsoft/windowsazure": 20
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,12 @@ databases are exchangeable, when working on a CRUD level.
|
||||
For some databases range queries are also supported that allow
|
||||
you to do range queries with parititioning.
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
reference/configuration
|
||||
Contents
|
||||
--------
|
||||
|
||||
* :doc:`Configuration <reference/configuration>`
|
||||
* :doc:`Basic Usage <reference/basic-usage>`
|
||||
* **Mapping Drivers**:
|
||||
:doc:`Docblock Annotations <reference/annotations-reference>` |
|
||||
:doc:`XML <reference/xml-mapping>` |
|
||||
:doc:`YAML <reference/yaml-mapping>`
|
||||
|
||||
86
docs/reference/annotations-reference.rst
Normal file
86
docs/reference/annotations-reference.rst
Normal file
@@ -0,0 +1,86 @@
|
||||
Annotations Reference
|
||||
=====================
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
- :ref:`@Entity <annref_entity>`
|
||||
- :ref:`@Id <annref_id>`
|
||||
- :ref:`@Transient <annref_transient>`
|
||||
|
||||
Reference
|
||||
---------
|
||||
|
||||
.. _annref_entity:
|
||||
|
||||
@Entity
|
||||
~~~~~~~
|
||||
|
||||
Required annotation to mark a PHP class as an entity. Doctrine manages
|
||||
the persistence of all classes marked as entities.
|
||||
|
||||
Optional attributes:
|
||||
|
||||
|
||||
- **storageName**: Specifies the storage name used to prevent conflicts.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
/**
|
||||
* @Entity(storageName="admin")
|
||||
*/
|
||||
class User
|
||||
{
|
||||
//...
|
||||
}
|
||||
|
||||
.. _annref_id:
|
||||
|
||||
@Id
|
||||
~~~~~~~
|
||||
|
||||
This annotation marks the identifier used to store the entity.
|
||||
More properties can be marked with this annotation, but at least one
|
||||
property has to be @Id.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
*/
|
||||
private $username;
|
||||
}
|
||||
|
||||
.. _annref_transient:
|
||||
|
||||
@Transient
|
||||
~~~~~~~
|
||||
|
||||
This annotation is used to prevent the property to be stored.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @Transient
|
||||
*/
|
||||
private $temporaryData;
|
||||
}
|
||||
127
docs/reference/basic-usage.rst
Normal file
127
docs/reference/basic-usage.rst
Normal file
@@ -0,0 +1,127 @@
|
||||
Basic Usage
|
||||
===========
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
This guide covers getting started with the Doctrine Key Value Store.
|
||||
|
||||
To use the KeyValueStore you actually need:
|
||||
|
||||
- PHP 5.5 or above
|
||||
- Composer Package Manager (`Install Composer
|
||||
<http://getcomposer.org/doc/00-intro.md>`_)
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
To install the KeyValueStore in your project just run the Composer command:
|
||||
|
||||
..
|
||||
|
||||
$ composer require doctrine/key-value-store
|
||||
|
||||
or add it to your composer.json file with:
|
||||
|
||||
..
|
||||
|
||||
{
|
||||
"require": {
|
||||
"doctrine/key-value-store": "^1.0"
|
||||
}
|
||||
}
|
||||
|
||||
Usage Examples
|
||||
--------------
|
||||
|
||||
In the guide examples we suppose to track e-mail campaigns
|
||||
based on campaign id and recipients.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations as KeyValue;
|
||||
|
||||
/**
|
||||
* @KeyValue\Entity(storageName="responses")
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
const RECEIVE = 0;
|
||||
const OPEN = 10;
|
||||
const CLICK = 20;
|
||||
const ACTION = 30;
|
||||
|
||||
/**
|
||||
* @KeyValue\Id
|
||||
*/
|
||||
private $campaign;
|
||||
|
||||
/**
|
||||
* @KeyValue\Id
|
||||
*/
|
||||
private $recipient;
|
||||
|
||||
private $status;
|
||||
private $date;
|
||||
|
||||
public function __construct($campaign, $recipient, $status)
|
||||
{
|
||||
$this->campaign = $campaign;
|
||||
$this->recipient = $recipient;
|
||||
$this->status = $status;
|
||||
}
|
||||
}
|
||||
|
||||
Create
|
||||
------
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$response = new Response(
|
||||
'1234',
|
||||
'kontakt@beberlei.de',
|
||||
Response::RECEIVE
|
||||
);
|
||||
|
||||
$entityManager->persist($response);
|
||||
// persists as much as you can
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
Read
|
||||
----
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$response = $entityManager->find(
|
||||
'Response',
|
||||
array(
|
||||
'campaign' => '1234',
|
||||
'recipient' => 'kontakt@beberlei.de',
|
||||
)
|
||||
);
|
||||
|
||||
Update
|
||||
------
|
||||
|
||||
Same as create, just reuse the same id.
|
||||
|
||||
Delete
|
||||
------
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$response = $entityManager->find(
|
||||
'Response',
|
||||
array(
|
||||
'1234',
|
||||
'kontakt@beberlei.de',
|
||||
)
|
||||
);
|
||||
$entityManager->remove($response);
|
||||
$entityManager->flush();
|
||||
@@ -12,10 +12,11 @@ Mapping Configuration
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Configuration;
|
||||
use Doctrine\KeyValueStore\Mapping\AnnotationDriver;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
|
||||
// 1. create Configuration instance
|
||||
$config = new Configuration();
|
||||
@@ -51,23 +52,38 @@ database backends, you have to configure the actual storage you want to use.
|
||||
This configuration is obviously specific to all the different storage drivers.
|
||||
So far the following drivers exist (and are documented here):
|
||||
|
||||
* PHP Array
|
||||
* Doctrine Cache Backend
|
||||
* SQL Backend with Doctrine DBAL
|
||||
* Microsoft Windows Azure Table
|
||||
* Couchbase
|
||||
* CouchDB
|
||||
* MongoDB
|
||||
* Riak
|
||||
|
||||
Also all those storage backends obviously have different dependencies in terms
|
||||
of PHP libraries or PHP PECL extensions.
|
||||
|
||||
PHP Array
|
||||
---------
|
||||
|
||||
PHP array is used mainly for development and teesting purposes.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\ArrayStorage;
|
||||
|
||||
$storage = new ArrayStorage();
|
||||
|
||||
Doctrine Cache Backend
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
----------------------
|
||||
|
||||
The Doctrine Cache Backend uses the `Caching Framework
|
||||
<https://github.com/doctrine/cache>`_ from Doctrine as a backend. Depending on
|
||||
the cache driver you get a persistent or in-memory key value store with this
|
||||
solution. See the `Doctrine Common documentation
|
||||
solution. See the `Doctrine Common documentation
|
||||
<http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/caching.html>`_
|
||||
for more details about the different supported drivers.
|
||||
|
||||
@@ -76,6 +92,7 @@ Here is an example of configurating the Cache Storage using Redis:
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Cache\RedisCache;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
use Redis;
|
||||
@@ -86,7 +103,7 @@ Here is an example of configurating the Cache Storage using Redis:
|
||||
$storage = new DoctrineCacheStorage($cache);
|
||||
|
||||
Doctrine DBAL Backend
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
---------------------
|
||||
|
||||
You can use a relational database as backend. It uses a very simple
|
||||
table as storage with one primary key and a blob field that stores
|
||||
@@ -95,8 +112,9 @@ the properties.
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
use Doctrine\KeyValueStore\Storage\DBALStorage;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\KeyValueStore\Storage\DBALStorage;
|
||||
|
||||
$tableName = 'storage';
|
||||
$keyColumn = 'id';
|
||||
@@ -108,7 +126,7 @@ the properties.
|
||||
$storage = new DBALStorage($conn, $tableName, $keyColumn, $dataColumn);
|
||||
|
||||
Microsoft Windows Azure Table
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
-----------------------------
|
||||
|
||||
Microsoft offers a NoSQL solution as part of their `Windows Azure
|
||||
<http://www.windowsazure.com/en-us/>`_ service. You can use that
|
||||
@@ -117,26 +135,125 @@ as a storage layer through the Windows Azure PHP SDK:
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\AzureSdkTableStorage;
|
||||
use WindowsAzure\Common\ServicesBuilder;
|
||||
|
||||
$connectionString = ""; // Windows Azure Connection string
|
||||
$connectionString = ''; // Windows Azure Connection string
|
||||
$builder = ServicesBuilder::getInstance();
|
||||
$client = $builder->createTableService($connectionString);
|
||||
|
||||
$storage = new AzureSdkTableStorage($client);
|
||||
|
||||
Couchbase
|
||||
^^^^^^^^^
|
||||
Cassandra
|
||||
---------
|
||||
|
||||
To be written
|
||||
Cassandra is supported through the `PECL extension <https://pecl.php.net/package/cassandra>`_
|
||||
and the `DataStax PHP driver <https://github.com/datastax/php-driver>`_:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Cassandra;
|
||||
use Cassandra\SimpleStatement;
|
||||
use Doctrine\KeyValueStore\Storage\CassandraStorage;
|
||||
|
||||
$cluster = Cassandra::cluster()->build();
|
||||
$session = $cluster->connect();
|
||||
$session->execute(new SimpleStatement('USE doctrine'));
|
||||
|
||||
$storage = new CassandraStorage($session);
|
||||
|
||||
Couchbase
|
||||
---------
|
||||
|
||||
Until the version 1.2 also Couchbase is supported:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\CouchbaseStorage;
|
||||
|
||||
$conn = new Couchbase(/* connection parameters */);
|
||||
|
||||
$storage = new CouchbaseStorage($conn);
|
||||
|
||||
CouchDB
|
||||
-------
|
||||
|
||||
CouchDB storage setup based on `doctrine/couchdb-client <https://github.com/doctrine/couchdb-client>`_:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\CouchDB\CouchDBClient;
|
||||
use Doctrine\KeyValueStore\Storage\CouchDbStorage;
|
||||
|
||||
$client = CouchDBClient::create(array(
|
||||
'dbname' => 'doctrine_example',
|
||||
));
|
||||
|
||||
$storage = new CouchDbStorage($client);
|
||||
|
||||
DynamoDb
|
||||
---------
|
||||
|
||||
DynamoDb is supported through the `AWS SDK for PHP <https://aws.amazon.com/sdk-for-php/>`_
|
||||
Create your tables via the AWS DynamoDb console or using the `PHP based API <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelPHPTableOperationsExample.html>`_
|
||||
See the `AWS docs <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/UsingPHP.html#PHPSDKCredentialsSet>`_ for more information on configuring credentials for the client.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
$sdk = new \Aws\Sdk([...]);
|
||||
$client = $sdk->createDynamoDb();
|
||||
|
||||
$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
|
||||
^^^^^^^
|
||||
-------
|
||||
|
||||
To be written
|
||||
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 Doctrine\KeyValueStore\Storage\MongoDbStorage;
|
||||
|
||||
$conn = new \Mongo(/* connection parameters and options */);
|
||||
|
||||
$storage = new MongoDbStorage($conn, array(
|
||||
'collection' => 'your_collection',
|
||||
'database' => 'your_database',
|
||||
));
|
||||
|
||||
Riak
|
||||
^^^^
|
||||
----
|
||||
|
||||
to be written
|
||||
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;
|
||||
|
||||
$conn = new Riak(/* connection parameters */);
|
||||
|
||||
$storage = new RiakStorage($conn);
|
||||
|
||||
40
docs/reference/xml-mapping.rst
Normal file
40
docs/reference/xml-mapping.rst
Normal file
@@ -0,0 +1,40 @@
|
||||
XML Mapping
|
||||
===========
|
||||
|
||||
To use the XML driver you must configure the directory where XML mappings are
|
||||
located:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Configuration;
|
||||
use Doctrine\KeyValueStore\EntityManager;
|
||||
use Doctrine\KeyValueStore\Mapping\XmlDriver;
|
||||
|
||||
$cache = new ArrayCache;
|
||||
$metadata = new XmlDriver('/path/to/xml/mappings');
|
||||
$storage = // your preferred storage
|
||||
|
||||
$config = new Configuration();
|
||||
$config->setMappingDriverImpl($metadata);
|
||||
$config->setMetadataCache($cache);
|
||||
|
||||
return new EntityManager($storage, $config);
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
// App.Doctrine.KeyValueStore.User.dcm.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<entity name="App\Doctrine\KeyValueStore\User" storage-name="users">
|
||||
<id>id</id>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
||||
35
docs/reference/yaml-mapping.rst
Normal file
35
docs/reference/yaml-mapping.rst
Normal file
@@ -0,0 +1,35 @@
|
||||
YAML Mapping
|
||||
============
|
||||
|
||||
To use the YAML driver you must configure the directory where YAML mappings are
|
||||
located:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Configuration;
|
||||
use Doctrine\KeyValueStore\EntityManager;
|
||||
use Doctrine\KeyValueStore\Mapping\YamlDriver;
|
||||
|
||||
$cache = new ArrayCache;
|
||||
$metadata = new YamlDriver('/path/to/yaml/mappings');
|
||||
$storage = // your preferred storage
|
||||
|
||||
$config = new Configuration();
|
||||
$config->setMappingDriverImpl($metadata);
|
||||
$config->setMetadataCache($cache);
|
||||
|
||||
return new EntityManager($storage, $config);
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# App.Doctrine.KeyValueStore.User.dcm.xml
|
||||
App\Doctrine\KeyValueStore\User:
|
||||
storageName: users
|
||||
id:
|
||||
- id
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,9 +20,9 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\KeyValueStore\Id\IdConverterStrategy;
|
||||
use Doctrine\KeyValueStore\Id\NullIdConverter;
|
||||
|
||||
@@ -33,86 +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
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @param MappingDriver $driver
|
||||
*
|
||||
* @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
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @param Cache $cache
|
||||
*
|
||||
* @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
|
||||
* @return \Doctrine\KeyValueStore\Configuration
|
||||
* @param IdConverterStrategy $strategy
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,9 +20,9 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\Storage;
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Storage\Storage;
|
||||
|
||||
/**
|
||||
* EntityManager for KeyValue stored objects.
|
||||
@@ -43,28 +44,29 @@ class EntityManager
|
||||
/**
|
||||
* Create a new EntityManager
|
||||
*
|
||||
* @param Storage $storageDriver
|
||||
* @param Configuration $config
|
||||
* @param Storage $storageDriver
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find objects by key
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $className
|
||||
* @param string|array $key
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function find($className, $key)
|
||||
{
|
||||
return $this->unitOfWork->reconsititute($className, $key);
|
||||
return $this->unitOfWork->reconstititute($className, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +78,8 @@ class EntityManager
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $partitionKey
|
||||
* @return \Doctrine\KeyValueStore\Query\RangeQuery
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function createRangeQuery($className, $partitionKey)
|
||||
{
|
||||
@@ -87,7 +90,6 @@ class EntityManager
|
||||
* Persist new object in key value storage.
|
||||
*
|
||||
* @param object $object
|
||||
* @return void
|
||||
*/
|
||||
public function persist($object)
|
||||
{
|
||||
@@ -98,7 +100,6 @@ class EntityManager
|
||||
* Remove object
|
||||
*
|
||||
* @param object $object
|
||||
* @return void
|
||||
*/
|
||||
public function remove($object)
|
||||
{
|
||||
@@ -108,8 +109,6 @@ class EntityManager
|
||||
/**
|
||||
* Flush all outstanding changes from the managed object-graph into the
|
||||
* key-value storage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
@@ -125,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();
|
||||
@@ -139,6 +141,7 @@ class EntityManager
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
*
|
||||
* @return Mapping\ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata($className)
|
||||
@@ -146,4 +149,3 @@ class EntityManager
|
||||
return $this->unitOfWork->getClassMetadata($className);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -23,18 +24,20 @@ namespace Doctrine\KeyValueStore\Http;
|
||||
* Yet another HTTP client
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
interface Client
|
||||
{
|
||||
/**
|
||||
* Send HTTP Request
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string|null $body
|
||||
* @param array $headers
|
||||
* @param array $headers
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
function request($method, $url, $body = null, array $headers = array());
|
||||
public function request($method, $url, $body = null, array $headers = []);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -16,12 +17,15 @@
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Http;
|
||||
|
||||
/**
|
||||
* HTTP Response
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
@@ -29,12 +33,12 @@ class Response
|
||||
|
||||
private $body;
|
||||
|
||||
private $headers = array();
|
||||
private $headers = [];
|
||||
|
||||
public function __construct($code, $body, array $headers)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->body = $body;
|
||||
$this->code = $code;
|
||||
$this->body = $body;
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
@@ -62,14 +66,14 @@ class Response
|
||||
* Get HTTP Response header
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return null|string|array
|
||||
*/
|
||||
public function getHeader($name)
|
||||
{
|
||||
if ( ! isset($this->headers[$name])) {
|
||||
return null;
|
||||
if (! isset($this->headers[$name])) {
|
||||
return;
|
||||
}
|
||||
return $this->headers[$name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -25,9 +26,13 @@ namespace Doctrine\KeyValueStore\Http;
|
||||
* extension dependencies.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
*
|
||||
* @link www.doctrine-project.com
|
||||
* @since 1.0
|
||||
*
|
||||
* @author Kore Nordmann <kore@arbitracker.org>
|
||||
*
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
class SocketClient implements Client
|
||||
{
|
||||
@@ -42,11 +47,11 @@ class SocketClient implements Client
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = array(
|
||||
private $options = [
|
||||
'keep-alive' => true,
|
||||
);
|
||||
];
|
||||
|
||||
public function __construct(array $options = array())
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = array_merge($this->options, $options);
|
||||
}
|
||||
@@ -56,21 +61,18 @@ class SocketClient implements Client
|
||||
*
|
||||
* Checks if the connection already has been established, or tries to
|
||||
* establish the connection, if not done yet.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function checkConnection($host, $port)
|
||||
{
|
||||
$host = ($port == 443) ? "ssl://" . $host : "tcp://" . $host;
|
||||
$host = ($port == 443) ? 'ssl://' . $host : 'tcp://' . $host;
|
||||
|
||||
// If the connection could not be established, fsockopen sadly does not
|
||||
// only return false (as documented), but also always issues a warning.
|
||||
if ( ( $this->connection === null ) &&
|
||||
( ( $this->connection = @stream_socket_client($host . ":" . $port, $errno, $errstr ) ) === false ) )
|
||||
{
|
||||
if (($this->connection === null) &&
|
||||
(($this->connection = @stream_socket_client($host . ':' . $port, $errno, $errstr)) === false)) {
|
||||
// This is a bit hackisch...
|
||||
$this->connection = null;
|
||||
throw new \RuntimeException("fail");
|
||||
throw new \RuntimeException('fail');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,13 +84,14 @@ class SocketClient implements Client
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildRequest($method, $url, $data, $headers )
|
||||
protected function buildRequest($method, $url, $data, $headers)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
$host = $parts['host'];
|
||||
$path = $parts['path'];
|
||||
$host = $parts['host'];
|
||||
$path = $parts['path'];
|
||||
|
||||
// Create basic request headers
|
||||
$request = "$method $path HTTP/1.1\r\nHost: {$host}\r\n";
|
||||
@@ -96,17 +99,17 @@ class SocketClient implements Client
|
||||
// Set keep-alive header, which helps to keep to connection
|
||||
// initilization costs low, especially when the database server is not
|
||||
// available in the locale net.
|
||||
$request .= "Connection: " . ( $this->options['keep-alive'] ? 'Keep-Alive' : 'Close' ) . "\r\n";
|
||||
$request .= 'Connection: ' . ($this->options['keep-alive'] ? 'Keep-Alive' : 'Close') . "\r\n";
|
||||
|
||||
// Also add headers and request body if data should be sent to the
|
||||
// server. Otherwise just add the closing mark for the header section
|
||||
// of the request.
|
||||
foreach ($headers as $name => $header) {
|
||||
$request .= $name . ": " . $header . "\r\n";
|
||||
$request .= $name . ': ' . $header . "\r\n";
|
||||
}
|
||||
$request = rtrim($request) . "\r\n\r\n";
|
||||
|
||||
if ( $data !== null ) {
|
||||
if ($data !== null) {
|
||||
$request .= $data;
|
||||
}
|
||||
|
||||
@@ -124,40 +127,44 @@ class SocketClient implements Client
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @param bool $raw
|
||||
* @param bool $raw
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function request($method, $url, $data = null, array $headers = array())
|
||||
public function request($method, $url, $data = null, array $headers = [])
|
||||
{
|
||||
// Try establishing the connection to the server
|
||||
$parts = parse_url($url);
|
||||
$host = $parts['host'];
|
||||
$host = $parts['host'];
|
||||
$this->checkConnection($host, $parts['scheme']=='https' ? 443 : 80);
|
||||
|
||||
// Send the build request to the server
|
||||
if ( fwrite( $this->connection, $request = $this->buildRequest( $method, $url, $data, $headers ) ) === false ) {
|
||||
if (fwrite($this->connection, $request = $this->buildRequest($method, $url, $data, $headers)) === false) {
|
||||
// Reestablish which seems to have been aborted
|
||||
//
|
||||
// The recursion in this method might be problematic if the
|
||||
// connection establishing mechanism does not correctly throw an
|
||||
// exception on failure.
|
||||
$this->connection = null;
|
||||
return $this->request( $method, $url, $data, $headers );
|
||||
return $this->request($method, $url, $data, $headers);
|
||||
}
|
||||
|
||||
// Read server response headers
|
||||
$rawHeaders = '';
|
||||
$headers = array(
|
||||
'connection' => ( $this->options['keep-alive'] ? 'Keep-Alive' : 'Close' ),
|
||||
);
|
||||
$headers = [
|
||||
'connection' => ($this->options['keep-alive'] ? 'Keep-Alive' : 'Close'),
|
||||
];
|
||||
|
||||
// Remove leading newlines, should not accur at all, actually.
|
||||
while ( ( ( $line = fgets( $this->connection ) ) !== false ) &&
|
||||
( ( $lineContent = rtrim( $line ) ) === '' ) );
|
||||
while (true) {
|
||||
if (! (($line = fgets($this->connection)) !== false) || ! (($lineContent = rtrim($line)) === '')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Throw exception, if connection has been aborted by the server, and
|
||||
// leave handling to the user for now.
|
||||
if ( $line === false ) {
|
||||
if ($line === false) {
|
||||
// Reestablish which seems to have been aborted
|
||||
//
|
||||
// The recursion in this method might be problematic if the
|
||||
@@ -167,7 +174,7 @@ class SocketClient implements Client
|
||||
// An aborted connection seems to happen here on long running
|
||||
// requests, which cause a connection timeout at server side.
|
||||
$this->connection = null;
|
||||
return $this->request( $method, $url, $data, $raw );
|
||||
return $this->request($method, $url, $data, $raw);
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -175,32 +182,29 @@ class SocketClient implements Client
|
||||
$rawHeaders .= $lineContent . "\n";
|
||||
|
||||
// Extract header values
|
||||
if ( preg_match( '(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $lineContent, $match ) )
|
||||
{
|
||||
if (preg_match('(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $lineContent, $match)) {
|
||||
$headers['version'] = $match['version'];
|
||||
$headers['status'] = (int) $match['status'];
|
||||
} else {
|
||||
list($key, $value) = explode(':', $lineContent, 2);
|
||||
$headers[strtolower($key)] = ltrim($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
list( $key, $value ) = explode( ':', $lineContent, 2 );
|
||||
$headers[strtolower( $key )] = ltrim( $value );
|
||||
}
|
||||
} while ( ( ( $line = fgets( $this->connection ) ) !== false ) &&
|
||||
( ( $lineContent = rtrim( $line ) ) !== '' ) );
|
||||
} while ((($line = fgets($this->connection)) !== false) &&
|
||||
(($lineContent = rtrim($line)) !== ''));
|
||||
|
||||
// Read response body
|
||||
$body = '';
|
||||
if ( !isset( $headers['transfer-encoding'] ) ||
|
||||
( $headers['transfer-encoding'] !== 'chunked' ) ) {
|
||||
if (! isset($headers['transfer-encoding']) ||
|
||||
($headers['transfer-encoding'] !== 'chunked')) {
|
||||
// HTTP 1.1 supports chunked transfer encoding, if the according
|
||||
// header is not set, just read the specified amount of bytes.
|
||||
$bytesToRead = (int) ( isset( $headers['content-length'] ) ? $headers['content-length'] : 0 );
|
||||
$bytesToRead = (int) (isset($headers['content-length']) ? $headers['content-length'] : 0);
|
||||
|
||||
// Read body only as specified by chunk sizes, everything else
|
||||
// are just footnotes, which are not relevant for us.
|
||||
while ( $bytesToRead > 0 ) {
|
||||
$body .= $read = fgets( $this->connection, $bytesToRead + 1 );
|
||||
$bytesToRead -= strlen( $read );
|
||||
while ($bytesToRead > 0) {
|
||||
$body .= $read = fgets($this->connection, $bytesToRead + 1);
|
||||
$bytesToRead -= strlen($read);
|
||||
}
|
||||
} else {
|
||||
// When transfer-encoding=chunked has been specified in the
|
||||
@@ -208,43 +212,41 @@ class SocketClient implements Client
|
||||
// until the server has finished. Ignore all additional HTTP
|
||||
// options after that.
|
||||
do {
|
||||
$line = rtrim( fgets( $this->connection ) );
|
||||
$line = rtrim(fgets($this->connection));
|
||||
|
||||
// Get bytes to read, with option appending comment
|
||||
if ( preg_match( '(^([0-9a-fA-F]+)(?:;.*)?$)', $line, $match ) ) {
|
||||
$bytesToRead = hexdec( $match[1] );
|
||||
if (preg_match('(^([0-9a-fA-F]+)(?:;.*)?$)', $line, $match)) {
|
||||
$bytesToRead = hexdec($match[1]);
|
||||
|
||||
// Read body only as specified by chunk sizes, everything else
|
||||
// are just footnotes, which are not relevant for us.
|
||||
$bytesLeft = $bytesToRead;
|
||||
while ( $bytesLeft > 0 )
|
||||
{
|
||||
$body .= $read = fread( $this->connection, $bytesLeft + 2 );
|
||||
$bytesLeft -= strlen( $read );
|
||||
while ($bytesLeft > 0) {
|
||||
$body .= $read = fread($this->connection, $bytesLeft + 2);
|
||||
$bytesLeft -= strlen($read);
|
||||
}
|
||||
}
|
||||
} while ( $bytesToRead > 0 );
|
||||
} while ($bytesToRead > 0);
|
||||
|
||||
// Chop off \r\n from the end.
|
||||
$body = substr( $body, 0, -2 );
|
||||
$body = substr($body, 0, -2);
|
||||
}
|
||||
|
||||
// Reset the connection if the server asks for it.
|
||||
if ( $headers['connection'] !== 'Keep-Alive' ) {
|
||||
fclose( $this->connection );
|
||||
if ($headers['connection'] !== 'Keep-Alive') {
|
||||
fclose($this->connection);
|
||||
$this->connection = null;
|
||||
}
|
||||
|
||||
// Handle some response state as special cases
|
||||
switch ( $headers['status'] ) {
|
||||
switch ($headers['status']) {
|
||||
case 301:
|
||||
case 302:
|
||||
case 303:
|
||||
case 307:
|
||||
return $this->request( $method, $headers['location'], $data, $raw );
|
||||
return $this->request($method, $headers['location'], $data, $raw);
|
||||
}
|
||||
|
||||
return new Response( $headers['status'], $body, $headers );
|
||||
return new Response($headers['status'], $body, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -20,36 +21,52 @@
|
||||
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 = array($metadata->identifier[0] => $key);
|
||||
} else if (!is_array($key)) {
|
||||
throw new \InvalidArgumentException("Array of identifier key-value pairs is expected!");
|
||||
} else {
|
||||
$id = array();
|
||||
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];
|
||||
if (! $metadata->isCompositeKey && ! is_array($key)) {
|
||||
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);
|
||||
return implode('__##__', (array) $key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -30,7 +31,23 @@ namespace Doctrine\KeyValueStore\Id;
|
||||
*/
|
||||
interface IdConverterStrategy
|
||||
{
|
||||
function serialize($class, $data);
|
||||
function unserialize($class, $data);
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -32,26 +33,28 @@ interface IdHandlingStrategy
|
||||
* Given an unstructured key format and a class metadata, generate a key.
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @param string|array $key
|
||||
* @param string|array $key
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
function normalizeId(ClassMetadata $metadata, $key);
|
||||
public function normalizeId(ClassMetadata $metadata, $key);
|
||||
|
||||
/**
|
||||
* Extract identifier from an object
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @param object $object
|
||||
* @param object $object
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
function getIdentifier(ClassMetadata $metadata, $object);
|
||||
public function getIdentifier(ClassMetadata $metadata, $object);
|
||||
|
||||
/**
|
||||
* Given a normalized key, generate a hash version for it.
|
||||
*
|
||||
* @param array|string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function hash($key);
|
||||
public function hash($key);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,14 +22,19 @@ namespace Doctrine\KeyValueStore\Id;
|
||||
|
||||
class NullIdConverter implements IdConverterStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function serialize($class, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function unserialize($class, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -23,6 +24,9 @@ use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
|
||||
class SingleIdHandler implements IdHandlingStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function normalizeId(ClassMetadata $metadata, $key)
|
||||
{
|
||||
if (is_scalar($key)) {
|
||||
@@ -33,15 +37,20 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
48
lib/Doctrine/KeyValueStore/InvalidArgumentException.php
Normal file
48
lib/Doctrine/KeyValueStore/InvalidArgumentException.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
|
||||
class InvalidArgumentException extends KeyValueStoreException
|
||||
{
|
||||
public static function invalidType($name, $expectedType, &$actual)
|
||||
{
|
||||
return new static(
|
||||
sprintf('The %s must be a %s, got "%s" instead.', $name, $expectedType, gettype($actual)),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
public static function invalidLength($name, $min, $max)
|
||||
{
|
||||
return new static(
|
||||
sprintf('The %s must be at least %d but no more than %d chars.', $name, $min, $max),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
public static function invalidTableName($name)
|
||||
{
|
||||
return new static(
|
||||
sprintf('Invalid table name: %s', $name),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,9 +22,8 @@ namespace Doctrine\KeyValueStore;
|
||||
|
||||
class KeyValueStoreException extends \Exception
|
||||
{
|
||||
static public function mappingDriverMissing()
|
||||
public static function mappingDriverMissing()
|
||||
{
|
||||
return new self("No mapping driver was assigned to the configuration. Use \$config->setMappingDriverImpl()");
|
||||
return new self('No mapping driver was assigned to the configuration. Use $config->setMappingDriverImpl()');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,14 +20,29 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Doctrine common annotations reader.
|
||||
*
|
||||
* @var AnnotationReader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
public function __construct($reader)
|
||||
/**
|
||||
* Constructor with required dependencies.
|
||||
*
|
||||
* @param $reader AnnotationReader Doctrine common annotations reader.
|
||||
*/
|
||||
public function __construct(AnnotationReader $reader)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
}
|
||||
@@ -34,35 +50,46 @@ 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
|
||||
*/
|
||||
function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
|
||||
{
|
||||
$class = $metadata->getReflectionClass();
|
||||
if (!$class) {
|
||||
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');
|
||||
if (!$entityAnnot) {
|
||||
throw new \InvalidArgumentException($metadata->name . " is not a valid key-value-store entity.");
|
||||
$entityAnnot = $this->reader->getClassAnnotation($class, Entity::class);
|
||||
if (! $entityAnnot) {
|
||||
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
}
|
||||
$metadata->storageName = $entityAnnot->storageName;
|
||||
|
||||
// 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());
|
||||
} else if ($transientAnnot) {
|
||||
$metadata->skipTransientField($property->getName());
|
||||
} else {
|
||||
$metadata->mapField(array('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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +98,9 @@ class AnnotationDriver implements MappingDriver
|
||||
*
|
||||
* @return array The names of all mapped classes known to this driver.
|
||||
*/
|
||||
function getAllClassNames()
|
||||
public function getAllClassNames()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,11 +109,11 @@ class AnnotationDriver implements MappingDriver
|
||||
* MappedSuperclass.
|
||||
*
|
||||
* @param string $className
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isTransient($className)
|
||||
public function isTransient($className)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,12 +22,12 @@ namespace Doctrine\KeyValueStore\Mapping\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
class Entity
|
||||
final class Entity
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $storageName;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,8 +22,8 @@ namespace Doctrine\KeyValueStore\Mapping\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("PROPERTY")
|
||||
*/
|
||||
class Id
|
||||
final class Id
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,8 +22,8 @@ namespace Doctrine\KeyValueStore\Mapping\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("PROPERTY")
|
||||
*/
|
||||
class Transient
|
||||
final class Transient
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -20,40 +21,95 @@
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as BaseClassMetadata;
|
||||
use ReflectionClass;
|
||||
|
||||
class ClassMetadata implements BaseClassMetadata
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $storageName;
|
||||
public $rootClassName;
|
||||
public $fields = array();
|
||||
public $identifier = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fields = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $identifier = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $isCompositeKey = false;
|
||||
public $transientFields = array();
|
||||
public $reflFields = array();
|
||||
public $reflClass;
|
||||
|
||||
private $_prototype;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $transientFields = [];
|
||||
|
||||
public function __construct($className)
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $reflFields = [];
|
||||
|
||||
/**
|
||||
* @var null|mixed
|
||||
*/
|
||||
private $prototype;
|
||||
|
||||
/**
|
||||
* @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->identifier[] = $fieldName;
|
||||
$this->isCompositeKey = count($this->identifier) > 1;
|
||||
$this->mapField(array('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']])) {
|
||||
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
|
||||
@@ -69,35 +125,47 @@ class ClassMetadata implements BaseClassMetadata
|
||||
*/
|
||||
public function newInstance()
|
||||
{
|
||||
if ($this->_prototype === null) {
|
||||
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
|
||||
if ($this->prototype === null) {
|
||||
$this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
|
||||
}
|
||||
|
||||
return clone $this->_prototype;
|
||||
return clone $this->prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return array('fields', 'isCompositeKey', 'identifier', 'name', 'storageName');
|
||||
return ['fields', 'isCompositeKey', 'identifier', 'name', 'storageName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identifiers values.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIdentifierValues($object)
|
||||
{
|
||||
$id = array();
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fully-qualified class name of this persistent class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getName(){}
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mapped identifier field name.
|
||||
@@ -106,54 +174,80 @@ class ClassMetadata implements BaseClassMetadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getIdentifier(){}
|
||||
public function getIdentifier()
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ReflectionClass instance for this mapped class.
|
||||
*
|
||||
* @return ReflectionClass
|
||||
*/
|
||||
function getReflectionClass(){}
|
||||
public function getReflectionClass()
|
||||
{
|
||||
return new ReflectionClass($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given field name is a mapped identifier for this class.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isIdentifier($fieldName){}
|
||||
public function isIdentifier($fieldName)
|
||||
{
|
||||
return in_array($fieldName, $this->identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given field is a mapped property for this class.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function hasField($fieldName){}
|
||||
public function hasField($fieldName)
|
||||
{
|
||||
return isset($this->fields[$fieldName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given field is a mapped association for this class.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function hasAssociation($fieldName){}
|
||||
public function hasAssociation($fieldName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given field is a mapped single valued association for this class.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isSingleValuedAssociation($fieldName){}
|
||||
public function isSingleValuedAssociation($fieldName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given field is a mapped collection valued association for this class.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isCollectionValuedAssociation($fieldName){}
|
||||
public function isCollectionValuedAssociation($fieldName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A numerically indexed list of field names of this persistent class.
|
||||
@@ -162,14 +256,20 @@ class ClassMetadata implements BaseClassMetadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFieldNames(){}
|
||||
public function getFieldNames()
|
||||
{
|
||||
return array_column($this->fields, 'fieldName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of identifier field names numerically indexed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getIdentifierFieldNames(){}
|
||||
public function getIdentifierFieldNames()
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* A numerically indexed list of association names of this persistent class.
|
||||
@@ -178,7 +278,9 @@ class ClassMetadata implements BaseClassMetadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getAssociationNames(){}
|
||||
public function getAssociationNames()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type name of this field.
|
||||
@@ -187,32 +289,44 @@ class ClassMetadata implements BaseClassMetadata
|
||||
* integer, string, boolean, float/double, datetime.
|
||||
*
|
||||
* @param string $fieldName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTypeOfField($fieldName){}
|
||||
public function getTypeOfField($fieldName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target class name of the given association.
|
||||
*
|
||||
* @param string $assocName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getAssociationTargetClass($assocName){}
|
||||
public function getAssociationTargetClass($assocName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the association is the inverse side of a bidirectional association
|
||||
*
|
||||
* @param string $assocName
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isAssociationInverseSide($assocName){}
|
||||
public function isAssociationInverseSide($assocName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target field of the owning side of the association
|
||||
*
|
||||
* @param string $assocName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getAssociationMappedByTargetField($assocName){}
|
||||
public function getAssociationMappedByTargetField($assocName)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -20,9 +21,8 @@
|
||||
namespace Doctrine\KeyValueStore\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata as KeyValueMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
|
||||
/**
|
||||
@@ -32,20 +32,32 @@ use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
*/
|
||||
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.");
|
||||
throw new \InvalidArgumentException('aliasing is not supported.');
|
||||
}
|
||||
|
||||
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
|
||||
@@ -54,30 +66,39 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
|
||||
if ($parent) {
|
||||
$class->rootClassName = $parent->name;
|
||||
$class->storageName = $parent->storageName;
|
||||
$class->storageName = $parent->storageName;
|
||||
}
|
||||
|
||||
if ( ! $class->storageName) {
|
||||
$parts = explode("\\", $class->name);
|
||||
if (! $class->storageName) {
|
||||
$parts = explode('\\', $class->name);
|
||||
$class->storageName = end($parts);
|
||||
}
|
||||
|
||||
if (!$class->identifier) {
|
||||
throw new \InvalidArgumentException("Class " . $class->name . " has no identifier.");
|
||||
if (! $class->identifier) {
|
||||
throw new \InvalidArgumentException('Class ' . $class->name . ' has no identifier.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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) {
|
||||
@@ -85,22 +106,29 @@ 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(array('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
|
||||
*/
|
||||
protected function isEntity(ClassMetadata $class)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function isEntity(CommonClassMetadata $class)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
120
lib/Doctrine/KeyValueStore/Mapping/XmlDriver.php
Normal file
120
lib/Doctrine/KeyValueStore/Mapping/XmlDriver.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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\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
|
||||
{
|
||||
const DEFAULT_FILE_EXTENSION = '.dcm.xml';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||
{
|
||||
parent::__construct($locator, $fileExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a mapping file with the given name and returns a map
|
||||
* from class/entity names to their corresponding file driver elements.
|
||||
*
|
||||
* @param string $file The mapping file to load.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function loadMappingFile($file)
|
||||
{
|
||||
$result = [];
|
||||
$xmlElement = simplexml_load_file($file);
|
||||
|
||||
if (isset($xmlElement->entity)) {
|
||||
foreach ($xmlElement->entity as $entityElement) {
|
||||
$entityName = (string) $entityElement['name'];
|
||||
$result[$entityName] = $entityElement;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the metadata for the specified class into the provided container.
|
||||
*
|
||||
* @param string $className
|
||||
* @param CommonClassMetadata $metadata
|
||||
*/
|
||||
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
|
||||
{
|
||||
try {
|
||||
$xmlRoot = $this->getElement($className);
|
||||
} catch (MappingException $exception) {
|
||||
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.');
|
||||
}
|
||||
|
||||
$class = new ReflectionClass($className);
|
||||
|
||||
if (isset($xmlRoot['storage-name'])) {
|
||||
$metadata->storageName = $xmlRoot['storage-name'];
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
if (isset($xmlRoot->id)) {
|
||||
foreach ($xmlRoot->id as $id) {
|
||||
$ids[] = (string) $id;
|
||||
}
|
||||
}
|
||||
|
||||
$transients = [];
|
||||
if (isset($xmlRoot->transient)) {
|
||||
foreach ($xmlRoot->transient as $transient) {
|
||||
$transients[] = (string) $transient;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (in_array($property->getName(), $ids)) {
|
||||
$metadata->mapIdentifier($property->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($property->getName(), $transients)) {
|
||||
$metadata->skipTransientField($property->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata->mapField([
|
||||
'fieldName' => $property->getName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/Doctrine/KeyValueStore/Mapping/YamlDriver.php
Normal file
102
lib/Doctrine/KeyValueStore/Mapping/YamlDriver.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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\Persistence\Mapping\ClassMetadata as CommonClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
|
||||
use Doctrine\Common\Persistence\Mapping\MappingException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class YamlDriver extends FileDriver
|
||||
{
|
||||
const DEFAULT_FILE_EXTENSION = '.dcm.yml';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
|
||||
{
|
||||
parent::__construct($locator, $fileExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a mapping file with the given name and returns a map
|
||||
* from class/entity names to their corresponding file driver elements.
|
||||
*
|
||||
* @param string $file The mapping file to load.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function loadMappingFile($file)
|
||||
{
|
||||
return Yaml::parse(file_get_contents($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the metadata for the specified class into the provided container.
|
||||
*
|
||||
* @param string $className
|
||||
* @param CommonClassMetadata $metadata
|
||||
*/
|
||||
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
|
||||
{
|
||||
/** @var \Doctrine\KeyValueStore\Mapping\ClassMetadata $metadata */
|
||||
try {
|
||||
$element = $this->getElement($className);
|
||||
} catch (MappingException $exception) {
|
||||
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($className);
|
||||
|
||||
if (isset($element['storageName'])) {
|
||||
$metadata->storageName = $element['storageName'];
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
if (isset($element['id'])) {
|
||||
$ids = $element['id'];
|
||||
}
|
||||
|
||||
$transients = [];
|
||||
if (isset($element['transient'])) {
|
||||
$transients = $element['transient'];
|
||||
}
|
||||
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (in_array($property->getName(), $ids)) {
|
||||
$metadata->mapIdentifier($property->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($property->getName(), $transients)) {
|
||||
$metadata->skipTransientField($property->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata->mapField([
|
||||
'fieldName' => $property->getName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -21,6 +22,8 @@ namespace Doctrine\KeyValueStore;
|
||||
|
||||
class NotFoundException extends KeyValueStoreException
|
||||
{
|
||||
|
||||
public static function notFoundByKey($key)
|
||||
{
|
||||
return new static(sprintf('Could not find an item with key: %s', $key), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -29,14 +30,14 @@ use Doctrine\KeyValueStore\EntityManager;
|
||||
*/
|
||||
class RangeQuery
|
||||
{
|
||||
const CONDITION_EQ = 'eq';
|
||||
const CONDITION_LE = 'le';
|
||||
const CONDITION_LT = 'lt';
|
||||
const CONDITION_GT = 'gt';
|
||||
const CONDITION_GE = 'ge';
|
||||
const CONDITION_NEQ = 'neq';
|
||||
const CONDITION_BETWEEN = 'between';
|
||||
const CONDITION_STARTSWITH = 'startswith';
|
||||
const CONDITION_EQ = 'eq';
|
||||
const CONDITION_LE = 'le';
|
||||
const CONDITION_LT = 'lt';
|
||||
const CONDITION_GT = 'gt';
|
||||
const CONDITION_GE = 'ge';
|
||||
const CONDITION_NEQ = 'neq';
|
||||
const CONDITION_BETWEEN = 'between';
|
||||
const CONDITION_STARTSWITH = 'startswith';
|
||||
|
||||
/**
|
||||
* @param string
|
||||
@@ -51,7 +52,7 @@ class RangeQuery
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $conditions = array();
|
||||
protected $conditions = [];
|
||||
|
||||
/**
|
||||
* Limit result to only a set of entities.
|
||||
@@ -65,35 +66,52 @@ class RangeQuery
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hints = array();
|
||||
protected $hints = [];
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param string $className
|
||||
* @param string $partitionKey
|
||||
*/
|
||||
public function __construct(EntityManager $em, $className, $partitionKey)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->className = $className;
|
||||
$this->em = $em;
|
||||
$this->className = $className;
|
||||
$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()
|
||||
{
|
||||
@@ -101,9 +119,9 @@ class RangeQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* Get partitionKey.
|
||||
* Get partition key.
|
||||
*
|
||||
* @return partitionKey.
|
||||
* @return string
|
||||
*/
|
||||
public function getPartitionKey()
|
||||
{
|
||||
@@ -114,11 +132,12 @@ class RangeQuery
|
||||
* Add range equals condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeEquals($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_EQ, $value);
|
||||
$this->conditions[] = [self::CONDITION_EQ, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -126,11 +145,12 @@ class RangeQuery
|
||||
* Add range not equals condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeNotEquals($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_NEQ, $value);
|
||||
$this->conditions[] = [self::CONDITION_NEQ, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -138,11 +158,12 @@ class RangeQuery
|
||||
* Add range less than condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeLessThan($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_LT, $value);
|
||||
$this->conditions[] = [self::CONDITION_LT, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -150,11 +171,12 @@ class RangeQuery
|
||||
* Add range less than equals condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeLessThanEquals($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_LE, $value);
|
||||
$this->conditions[] = [self::CONDITION_LE, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -162,11 +184,12 @@ class RangeQuery
|
||||
* Add range greater than condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeGreaterThan($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_GT, $value);
|
||||
$this->conditions[] = [self::CONDITION_GT, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -174,11 +197,12 @@ class RangeQuery
|
||||
* Add range greater than equals condition to range key.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return RangeQuery
|
||||
*/
|
||||
public function rangeGreaterThanEquals($value)
|
||||
{
|
||||
$this->conditions[] = array(self::CONDITION_GE, $value);
|
||||
$this->conditions[] = [self::CONDITION_GE, $value];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -201,21 +225,23 @@ class RangeQuery
|
||||
{
|
||||
$storage = $this->em->unwrap();
|
||||
|
||||
if ( ! ($storage instanceof RangeQueryStorage)) {
|
||||
throw new \RuntimeException("The storage backend " . $this->storage->getName() . " does not support range queries.");
|
||||
if (! $storage instanceof RangeQueryStorage) {
|
||||
throw new \RuntimeException(
|
||||
'The storage backend ' . $storage->getName() . ' does not support range queries.'
|
||||
);
|
||||
}
|
||||
|
||||
$uow = $this->em->getUnitOfWork();
|
||||
$class = $this->em->getClassMetadata($this->className);
|
||||
|
||||
return $storage->executeRangeQuery($this, $class->storageName, $class->identifier, function ($row) use($uow, $class) {
|
||||
$key = array();
|
||||
$rowHydration = function ($row) use ($uow, $class) {
|
||||
$key = [];
|
||||
foreach ($class->identifier as $id) {
|
||||
$key[$id] = $row[$id];
|
||||
}
|
||||
|
||||
return $uow->createEntity($class, $key, $row);
|
||||
});
|
||||
};
|
||||
return $storage->executeRangeQuery($this, $class->storageName, $class->identifier, $rowHydration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -31,11 +32,11 @@ interface RangeQueryStorage
|
||||
* Execute the range query and return a ResultIterator
|
||||
*
|
||||
* @param RangeQuery $query
|
||||
* @param string $storageName
|
||||
* @param array $key
|
||||
* @param Closure $hydrateRow
|
||||
* @param string $storageName
|
||||
* @param array $key
|
||||
* @param Closure $hydrateRow
|
||||
*
|
||||
* @return ResultIterator
|
||||
*/
|
||||
function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
|
||||
}
|
||||
|
||||
|
||||
135
lib/Doctrine/KeyValueStore/Storage/ArrayStorage.php
Normal file
135
lib/Doctrine/KeyValueStore/Storage/ArrayStorage.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?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\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* Array storage, mainly used for development purposes.
|
||||
*
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*/
|
||||
class ArrayStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data = [];
|
||||
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage support composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage require composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the storage key specified.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$this->update($storageName, $key, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data into the given key.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
if (! isset($this->data[$storageName])) {
|
||||
$this->data[$storageName] = [];
|
||||
}
|
||||
|
||||
$this->data[$storageName][serialize($key)] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
if (! isset($this->data[$storageName])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! isset($this->data[$storageName][serialize($key)])) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->data[$storageName][serialize($key)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
if (! isset($this->data[$storageName])) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (! isset($this->data[$storageName][serialize($key)])) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
unset($this->data[$storageName][serialize($key)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'array';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,14 +20,13 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use WindowsAzure\Table\TableRestProxy;
|
||||
use WindowsAzure\Table\Models\Entity;
|
||||
use WindowsAzure\Table\Models\EdmType;
|
||||
use WindowsAzure\Common\ServiceException;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
|
||||
use WindowsAzure\Common\ServiceException;
|
||||
use WindowsAzure\Table\Models\EdmType;
|
||||
use WindowsAzure\Table\Models\Entity;
|
||||
use WindowsAzure\Table\TableRestProxy;
|
||||
|
||||
/**
|
||||
* Storage implementation for Microsoft Windows Azure Table using the PHP SDK.
|
||||
@@ -36,10 +36,13 @@ use Doctrine\KeyValueStore\Query\RangeQueryStorage;
|
||||
class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
/**
|
||||
* @var \WindowsAzure\Table\TableRestProxy
|
||||
* @var TableRestProxy
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @param TableRestProxy $client
|
||||
*/
|
||||
public function __construct(TableRestProxy $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
@@ -78,13 +81,14 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
try {
|
||||
$this->client->insertEntity($storageName, $entity);
|
||||
} catch(ServiceException $e){
|
||||
} catch (ServiceException $e) {
|
||||
if ($e->getCode() == 404) {
|
||||
$this->client->createTable($storageName);
|
||||
} else {
|
||||
throw new StorageException(
|
||||
"Could not save entity in table, WindowsAzure SDK client reported error: " . $e->getMessage(),
|
||||
$e->getCode(), $e
|
||||
'Could not save entity in table, WindowsAzure SDK client reported error: ' . $e->getMessage(),
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -99,10 +103,11 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
try {
|
||||
$this->client->updateEntity($storageName, $entity);
|
||||
} catch(ServiceException $e){
|
||||
} catch (ServiceException $e) {
|
||||
throw new StorageException(
|
||||
"Could not update entity in table, WindowsAzure SDK client reported error: " . $e->getMessage(),
|
||||
$e->getCode(), $e
|
||||
'Could not update entity in table, WindowsAzure SDK client reported error: ' . $e->getMessage(),
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -112,14 +117,15 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
list ($partitonKey, $rowKey) = array_values($key);
|
||||
list($partitonKey, $rowKey) = array_values($key);
|
||||
|
||||
try {
|
||||
$this->client->deleteEntity($storageName, $partitonKey, $rowKey);
|
||||
} catch(ServiceException $e) {
|
||||
} catch (ServiceException $e) {
|
||||
throw new StorageException(
|
||||
"Could not delete entity in table, WindowsAzure SDK client reported error: " . $e->getMessage(),
|
||||
$e->getCode(), $e
|
||||
'Could not delete entity in table, WindowsAzure SDK client reported error: ' . $e->getMessage(),
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -129,17 +135,18 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
list ($partitonKey, $rowKey) = array_values($key);
|
||||
list($partitonKey, $rowKey) = array_values($key);
|
||||
|
||||
try {
|
||||
$result = $this->client->getEntity($storageName, $partitonKey, $rowKey);
|
||||
} catch(ServiceException $e) {
|
||||
$result = $this->client->getEntity($storageName, $partitonKey, $rowKey);
|
||||
} catch (ServiceException $e) {
|
||||
if ($e->getCode() === 404) {
|
||||
throw new NotFoundException();
|
||||
} else {
|
||||
throw new StorageException(
|
||||
"Could not find entity in table, WindowsAzure SDK client reported error: " . $e->getMessage(),
|
||||
$e->getCode(), $e
|
||||
'Could not find entity in table, WindowsAzure SDK client reported error: ' . $e->getMessage(),
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -147,14 +154,19 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
return $this->getProperties($result->getEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getProperties(Entity $entity)
|
||||
{
|
||||
$properties = array();
|
||||
$properties = [];
|
||||
|
||||
foreach ($entity->getProperties() as $name => $property) {
|
||||
if ($name === 'PartitionKey') {
|
||||
$name = 'dist';
|
||||
} else if ($name === 'RowKey') {
|
||||
} elseif ($name === 'RowKey') {
|
||||
$name = 'range';
|
||||
}
|
||||
|
||||
@@ -177,19 +189,21 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
*/
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
|
||||
{
|
||||
$filters = array("PartitionKey eq " . $this->quoteFilterValue($query->getPartitionKey()));
|
||||
$filters = ['PartitionKey eq ' . $this->quoteFilterValue($query->getPartitionKey())];
|
||||
|
||||
foreach ($query->getConditions() as $condition) {
|
||||
if ( ! in_array($condition[0], array('eq', 'neq', 'le', 'lt', 'ge', 'gt'))) {
|
||||
throw new \InvalidArgumentException("Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions.");
|
||||
if (! in_array($condition[0], ['eq', 'neq', 'le', 'lt', 'ge', 'gt'])) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions.'
|
||||
);
|
||||
}
|
||||
$filters[] = "RowKey " . $condition[0] . " " . $this->quoteFilterValue($condition[1]);
|
||||
$filters[] = 'RowKey ' . $condition[0] . ' ' . $this->quoteFilterValue($condition[1]);
|
||||
}
|
||||
|
||||
$filter = '(' . implode(" and ", $filters) . ')';
|
||||
$filter = '(' . implode(' and ', $filters) . ')';
|
||||
$result = $this->client->queryEntities($storageName, $filter);
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
|
||||
foreach ($result->getEntities() as $entity) {
|
||||
$row = $this->getProperties($entity);
|
||||
@@ -199,9 +213,14 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function quoteFilterValue($value)
|
||||
{
|
||||
return "'" . str_replace("'", "", $value) . "'";
|
||||
return "'" . str_replace("'", '', $value) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,15 +228,16 @@ 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)
|
||||
{
|
||||
list ($partitonKey, $rowKey) = array_values($key);
|
||||
list($partitonKey, $rowKey) = array_values($key);
|
||||
|
||||
$entity = new Entity();
|
||||
$entity->setPartitionKey((string)$partitonKey);
|
||||
$entity->setRowKey((string)$rowKey);
|
||||
$entity->setPartitionKey((string) $partitonKey);
|
||||
$entity->setRowKey((string) $rowKey);
|
||||
|
||||
foreach ($data as $variable => $value) {
|
||||
$type = $this->getPropertyType($value);
|
||||
@@ -229,16 +249,20 @@ class AzureSdkTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
/**
|
||||
* Infer the property type of variables.
|
||||
*
|
||||
* @param mixed $propertyValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getPropertyType($propertyValue)
|
||||
{
|
||||
if ($propertyValue instanceof \DateTime) {
|
||||
return EdmType::DATETIME;
|
||||
} else if (is_float($propertyValue)) {
|
||||
} elseif (is_float($propertyValue)) {
|
||||
return EdmType::DOUBLE;
|
||||
} else if (is_int($propertyValue)) {
|
||||
} elseif (is_int($propertyValue)) {
|
||||
return EdmType::INT32;
|
||||
} else if (is_bool($propertyValue)) {
|
||||
} elseif (is_bool($propertyValue)) {
|
||||
return EdmType::BOOLEAN;
|
||||
}
|
||||
|
||||
|
||||
189
lib/Doctrine/KeyValueStore/Storage/CassandraStorage.php
Normal file
189
lib/Doctrine/KeyValueStore/Storage/CassandraStorage.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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 Cassandra\ExecutionOptions;
|
||||
use Cassandra\Session;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* Cassandra Storage Engine for KeyValueStore.
|
||||
*
|
||||
* Uses the PHP Driver from Datastax.
|
||||
*
|
||||
* @uses https://github.com/datastax/php-driver
|
||||
*/
|
||||
class CassandraStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param Session $session
|
||||
*/
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$keys = $values = [];
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
$keys[] = $name;
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
foreach ($data as $name => $value) {
|
||||
$keys[] = $name;
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
$stmt = $this->session->prepare('INSERT INTO ' . $storageName . ' (' . implode(', ', $keys) . ') VALUES (' . implode(', ', array_fill(0, count($values), '?')) . ')');
|
||||
|
||||
$options = new ExecutionOptions([
|
||||
'arguments' => $values,
|
||||
]);
|
||||
|
||||
$this->session->execute($stmt, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$where = [];
|
||||
$set = [];
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
$where[] = $name . ' = ?';
|
||||
}
|
||||
|
||||
foreach ($data as $name => $value) {
|
||||
$set[] = $name . ' = ?';
|
||||
}
|
||||
|
||||
$stmt = $this->session->prepare('UPDATE ' . $storageName . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' AND ', $where));
|
||||
|
||||
$values = array_merge(array_values($data), array_values($key));
|
||||
|
||||
$options = new ExecutionOptions([
|
||||
'arguments' => $values,
|
||||
]);
|
||||
|
||||
$this->session->execute($stmt, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$where = [];
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
$where[] = $name . ' = ?';
|
||||
}
|
||||
|
||||
$stmt = $this->session->prepare('DELETE FROM ' . $storageName . ' WHERE ' . implode(' AND ', $where));
|
||||
|
||||
$options = new ExecutionOptions([
|
||||
'arguments' => array_values($key),
|
||||
]);
|
||||
|
||||
$this->session->execute($stmt, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$where = [];
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
$where[] = $name . ' = ?';
|
||||
}
|
||||
|
||||
$stmt = $this->session->prepare('SELECT * FROM ' . $storageName . ' WHERE ' . implode(' AND ', $where));
|
||||
|
||||
$options = new ExecutionOptions([
|
||||
'arguments' => array_values($key),
|
||||
]);
|
||||
|
||||
$result = $this->session->execute($stmt, $options);
|
||||
$rows = iterator_to_array($result);
|
||||
|
||||
if (! isset($rows[0])) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($rows[0] as $column => $value) {
|
||||
if (isset($key[$column])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$column] = $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'cassandra';
|
||||
}
|
||||
}
|
||||
140
lib/Doctrine/KeyValueStore/Storage/CouchDbStorage.php
Normal file
140
lib/Doctrine/KeyValueStore/Storage/CouchDbStorage.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;
|
||||
|
||||
/**
|
||||
* Key-Value-Storage using a Doctrine CouchDB Client library as backend.
|
||||
*
|
||||
* CouchDB requires scalar identifiers, so the `flattenKey` method is used
|
||||
* to flatten passed keys.
|
||||
*
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*/
|
||||
final class CouchDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var CouchDBClient
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @param CouchDBClient $client
|
||||
*/
|
||||
public function __construct(CouchDBClient $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->client->putDocument($data, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->client->putDocument($data, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
$this->client->deleteDocument($key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$key = $this->flattenKey($storageName, $key);
|
||||
return $this->client->findDocument($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'couchdb';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function flattenKey($storageName, $key)
|
||||
{
|
||||
$finalKey = $storageName . '-';
|
||||
|
||||
if (is_string($key)) {
|
||||
return $finalKey . $key;
|
||||
}
|
||||
|
||||
if (! is_array($key)) {
|
||||
throw new \InvalidArgumentException('The key should be a string or a flat array.');
|
||||
}
|
||||
|
||||
foreach ($key as $property => $value) {
|
||||
$finalKey .= sprintf('%s:%s-', $property, $value);
|
||||
}
|
||||
|
||||
return $finalKey;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -17,9 +18,9 @@
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,8 +20,8 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* Relational databased backed system.
|
||||
@@ -31,28 +32,54 @@ use Doctrine\DBAL\Connection;
|
||||
*/
|
||||
class DBALStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $keyColumn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dataColumn;
|
||||
|
||||
public function __construct(Connection $conn, $table = 'storage', $keyColumn = 'id', $dataColumn = 'serialized_data')
|
||||
{
|
||||
$this->conn = $conn;
|
||||
$this->table = $table;
|
||||
$this->keyColumn = $keyColumn;
|
||||
/**
|
||||
* @param Connection $conn
|
||||
* @param string $table
|
||||
* @param string $keyColumn
|
||||
* @param string $dataColumn
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $conn,
|
||||
$table = 'storage',
|
||||
$keyColumn = 'id',
|
||||
$dataColumn = 'serialized_data'
|
||||
) {
|
||||
$this->conn = $conn;
|
||||
$this->table = $table;
|
||||
$this->keyColumn = $keyColumn;
|
||||
$this->dataColumn = $dataColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsPartialUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage support composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsCompositePrimaryKeys()
|
||||
{
|
||||
@@ -60,9 +87,7 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this storage require composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiresCompositePrimaryKeys()
|
||||
{
|
||||
@@ -70,76 +95,62 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the storage key specified.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* @return void
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function insert($storageName, $key, array $data)
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
try {
|
||||
$this->conn->insert($this->table, array(
|
||||
$this->keyColumn => $key,
|
||||
$this->dataColumn => serialize($data)
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
$this->conn->insert($this->table, [
|
||||
$this->keyColumn => $key,
|
||||
$this->dataColumn => serialize($data),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data into the given key.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* @return void
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
try {
|
||||
$this->conn->update($this->table, array(
|
||||
$this->dataColumn => serialize($data)
|
||||
), array(
|
||||
$this->keyColumn => $key
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
$this->conn->update($this->table, [
|
||||
$this->dataColumn => serialize($data),
|
||||
], [
|
||||
$this->keyColumn => $key,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
* @return void
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
try {
|
||||
$this->conn->delete($this->table, array($this->keyColumn => $key));
|
||||
} catch(\Exception $e) {
|
||||
$this->conn->delete($this->table, [$this->keyColumn => $key]);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find data at key
|
||||
*
|
||||
* @param array|string $key
|
||||
* @return array
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$qb = $this->conn->createQueryBuilder();
|
||||
|
||||
$qb->select("s.{$this->dataColumn}")
|
||||
$qb->select('s.' . $this->dataColumn)
|
||||
->from($this->table, 's')
|
||||
->where("{$this->keyColumn} = ?")
|
||||
->setParameters(array($key));
|
||||
->where($this->keyColumn . ' = ?')
|
||||
->setParameters([$key]);
|
||||
|
||||
$stmt = $qb->execute();
|
||||
|
||||
$data = $stmt->fetchColumn();
|
||||
|
||||
if (!$data) {
|
||||
if (! $data) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
@@ -147,13 +158,10 @@ class DBALStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'dbal';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -32,74 +33,110 @@ 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->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) {
|
||||
return $storageName . "-" . $key;
|
||||
if (! $this->supportsCompositeKeys) {
|
||||
return $storageName . '-' . $key;
|
||||
}
|
||||
|
||||
$hash = $storageName . "-oid:";
|
||||
$hash = $storageName . '-oid:';
|
||||
ksort($key);
|
||||
foreach ($key as $property => $value) {
|
||||
$hash .= "$property=$value;";
|
||||
$hash .= $property . '=' . $value . ';';
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
<?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>.
|
||||
*/
|
||||
* 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\KeyValueStore\NotFoundException;
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use Aws\DynamoDb\Exception\ResourceNotFoundException;
|
||||
use Aws\DynamoDb\Iterator\ItemIterator;
|
||||
use Aws\DynamoDb\Marshaler;
|
||||
use Doctrine\KeyValueStore\InvalidArgumentException;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* DyanmoDb storage
|
||||
@@ -31,19 +32,185 @@ use Aws\DynamoDb\Iterator\ItemIterator;
|
||||
*/
|
||||
class DynamoDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* The key that DynamoDb uses to indicate the name of the table.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Aws\DynamoDb\DynamoDbClient $client
|
||||
* @var Marshaler
|
||||
*/
|
||||
public function __construct(DynamoDbClient $client)
|
||||
private $marshaler;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultKeyName = 'Id';
|
||||
|
||||
/**
|
||||
* 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,
|
||||
$defaultKeyName = null,
|
||||
array $tableKeys = []
|
||||
) {
|
||||
$this->client = $client;
|
||||
$this->marshaler = $marshaler ?: new Marshaler();
|
||||
|
||||
if ($defaultKeyName !== null) {
|
||||
$this->setDefaultKeyName($defaultKeyName);
|
||||
}
|
||||
|
||||
foreach ($tableKeys as $table => $keyName) {
|
||||
$this->setKeyForTable($table, $keyName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a DynamoDB key name.
|
||||
*
|
||||
* @param $name mixed The name to validate.
|
||||
*
|
||||
* @throws InvalidArgumentException When the key name is invalid.
|
||||
*/
|
||||
private function validateKeyName($name)
|
||||
{
|
||||
$this->client = $client;
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,15 +242,10 @@ class DynamoDbStorage implements Storage
|
||||
*/
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$this->createTable($storageName);
|
||||
|
||||
$this->prepareData($key, $data);
|
||||
|
||||
$result = $this->client->putItem(array(
|
||||
'TableName' => $storageName,
|
||||
'Item' => $this->client->formatAttributes($data),
|
||||
'ReturnConsumedCapacity' => 'TOTAL'
|
||||
));
|
||||
$this->client->putItem([
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::TABLE_ITEM_KEY => $this->prepareKey($storageName, $key) + $this->marshaler->marshalItem($this->prepareData($data)),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,23 +253,9 @@ class DynamoDbStorage implements Storage
|
||||
*/
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$this->prepareData($key, $data);
|
||||
|
||||
unset($data['id']);
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$data[$k] = array(
|
||||
"Value" => $this->client->formatValue($v),
|
||||
);
|
||||
}
|
||||
|
||||
$result = $this->client->updateItem(array(
|
||||
'TableName' => $storageName,
|
||||
'Key' => array(
|
||||
"id" => array('S' => $key)
|
||||
),
|
||||
"AttributeUpdates" => $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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,12 +263,10 @@ class DynamoDbStorage implements Storage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$result = $this->client->deleteItem(array(
|
||||
'TableName' => $storageName,
|
||||
'Key' => array(
|
||||
'id' => array('S' => $key),
|
||||
)
|
||||
));
|
||||
$this->client->deleteItem([
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::TABLE_KEY => $this->prepareKey($storageName, $key),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,79 +274,47 @@ class DynamoDbStorage implements Storage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$iterator = new ItemIterator($this->client->getScanIterator(array(
|
||||
"TableName" => $storageName,
|
||||
"Key" => array(
|
||||
"Id" => array('S' => $key),
|
||||
),
|
||||
)));
|
||||
$item = $this->client->getItem([
|
||||
self::TABLE_NAME_KEY => $storageName,
|
||||
self::CONSISTENT_READ_KEY => true,
|
||||
self::TABLE_KEY => $this->prepareKey($storageName, $key),
|
||||
]);
|
||||
|
||||
$results = $iterator->toArray();
|
||||
|
||||
if (count($results)) {
|
||||
return array_shift($results);
|
||||
if (! $item) {
|
||||
throw NotFoundException::notFoundByKey($key);
|
||||
}
|
||||
|
||||
throw new NotFoundException();
|
||||
$item = $item->get(self::TABLE_ITEM_KEY);
|
||||
|
||||
return $this->marshaler->unmarshalItem($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'dynamodb';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* Prepare data by removing empty item attributes.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function createTable($tableName)
|
||||
protected function prepareData($data)
|
||||
{
|
||||
try {
|
||||
$this->client->describeTable(array(
|
||||
'TableName' => $tableName,
|
||||
));
|
||||
} catch(ResourceNotFoundException $e) {
|
||||
$this->client->createTable(array(
|
||||
'AttributeDefinitions' => array(
|
||||
array(
|
||||
'AttributeName' => 'id',
|
||||
'AttributeType' => 'S',
|
||||
),
|
||||
),
|
||||
'TableName' => $tableName,
|
||||
'KeySchema' => array(
|
||||
array(
|
||||
'AttributeName' => 'id',
|
||||
'KeyType' => 'HASH',
|
||||
),
|
||||
),
|
||||
'ProvisionedThroughput' => array(
|
||||
'ReadCapacityUnits' => 1,
|
||||
'WriteCapacityUnits' => 1,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
$callback = function ($value) {
|
||||
return $value !== null && $value !== [] && $value !== '';
|
||||
};
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $data
|
||||
*/
|
||||
protected function prepareData($key, &$data)
|
||||
{
|
||||
$data = array_merge($data, array(
|
||||
'id' => $key,
|
||||
));
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value === null || $value === array() || $value === '') {
|
||||
unset($data[$key]);
|
||||
foreach ($data as &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->prepareData($value);
|
||||
}
|
||||
}
|
||||
return array_filter($data, $callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
<?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>.
|
||||
*/
|
||||
* 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\KeyValueStore\NotFoundException;
|
||||
use Mongo;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* MongoDb storage
|
||||
@@ -29,7 +32,7 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
class MongoDbStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Mongo
|
||||
* @var Mongo
|
||||
*/
|
||||
protected $mongo;
|
||||
|
||||
@@ -46,22 +49,22 @@ class MongoDbStorage implements Storage
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Mongo $mongo
|
||||
* @param Mongo $mongo
|
||||
* @param array $dbOptions
|
||||
*/
|
||||
public function __construct(\Mongo $mongo, array $dbOptions = array())
|
||||
public function __construct(Mongo $mongo, array $dbOptions = [])
|
||||
{
|
||||
$this->mongo = $mongo;
|
||||
$this->dbOptions = array_merge(array(
|
||||
'database' => '',
|
||||
$this->mongo = $mongo;
|
||||
$this->dbOptions = array_merge([
|
||||
'database' => '',
|
||||
'collection' => '',
|
||||
), $dbOptions);
|
||||
], $dbOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the mongodb collection
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
@@ -70,13 +73,16 @@ class MongoDbStorage implements Storage
|
||||
}
|
||||
|
||||
if (empty($this->dbOptions['database'])) {
|
||||
throw new \RuntimeException('The option "database" must be set');
|
||||
throw new RuntimeException('The option "database" must be set');
|
||||
}
|
||||
if (empty($this->dbOptions['collection'])) {
|
||||
throw new \RuntimeException('The option "collection" must be set');
|
||||
throw new RuntimeException('The option "collection" must be set');
|
||||
}
|
||||
|
||||
$this->collection = $this->mongo->selectDB($this->dbOptions['database'])->selectCollection($this->dbOptions['collection']);
|
||||
$this->collection = $this
|
||||
->mongo
|
||||
->selectDB($this->dbOptions['database'])
|
||||
->selectCollection($this->dbOptions['collection']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,10 +116,10 @@ class MongoDbStorage implements Storage
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$value = array(
|
||||
$value = [
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
);
|
||||
];
|
||||
|
||||
$this->collection->insert($value);
|
||||
}
|
||||
@@ -125,12 +131,12 @@ class MongoDbStorage implements Storage
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$value = array(
|
||||
$value = [
|
||||
'key' => $key,
|
||||
'value' => $data,
|
||||
);
|
||||
];
|
||||
|
||||
$this->collection->update(array('key' => $key), $value);
|
||||
$this->collection->update(['key' => $key], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +146,7 @@ class MongoDbStorage implements Storage
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$this->collection->remove(array('key' => $key));
|
||||
$this->collection->remove(['key' => $key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +156,7 @@ class MongoDbStorage implements Storage
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$value = $this->collection->findOne(array('key' => $key), array('value'));
|
||||
$value = $this->collection->findOne(['key' => $key], ['value']);
|
||||
|
||||
if ($value) {
|
||||
return $value['value'];
|
||||
@@ -160,12 +166,10 @@ class MongoDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'mongodb';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -17,10 +18,10 @@
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
|
||||
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,16 +48,16 @@ class RedisStorage implements Storage
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Redis $redis
|
||||
* @param Redis $redis
|
||||
* @param array $dbOptions
|
||||
*/
|
||||
public function __construct($redis, $dbOptions = array())
|
||||
public function __construct(Redis $redis, $dbOptions = [])
|
||||
{
|
||||
$this->client = $redis;
|
||||
|
||||
$this->dbOptions = array_merge(array(
|
||||
'keyPrefix' => $this->keyPrefix
|
||||
), $dbOptions);
|
||||
$this->dbOptions = array_merge([
|
||||
'keyPrefix' => $this->keyPrefix,
|
||||
], $dbOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,9 +127,7 @@ class RedisStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@@ -138,7 +137,8 @@ class RedisStorage implements Storage
|
||||
/**
|
||||
* Add prefix to Redis key space name
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyName($key)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -17,11 +18,9 @@
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
use Riak\Client;
|
||||
|
||||
/**
|
||||
@@ -30,15 +29,12 @@ use Riak\Client;
|
||||
class RiakStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* @var \Riak\Client
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Riak\Client $riak
|
||||
* @param string $bucketName
|
||||
* @param Client $riak
|
||||
*/
|
||||
public function __construct(Client $riak)
|
||||
{
|
||||
@@ -102,7 +98,7 @@ class RiakStorage implements Storage
|
||||
/** @var $object \Riak\Object */
|
||||
$object = $bucket->get($key);
|
||||
|
||||
if (!$object->exists()) {
|
||||
if (! $object->exists()) {
|
||||
// object does not exist, do nothing
|
||||
return;
|
||||
}
|
||||
@@ -120,7 +116,7 @@ class RiakStorage implements Storage
|
||||
/** @var $object \Riak\Object */
|
||||
$object = $bucket->get($key);
|
||||
|
||||
if (!$object->exists()) {
|
||||
if (! $object->exists()) {
|
||||
throw new NotFoundException;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
<?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>.
|
||||
*/
|
||||
* 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\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\KeyValueStoreException;
|
||||
use Aws\SimpleDb\SimpleDbClient;
|
||||
use Aws\SimpleDb\Exception\NoSuchDomainException;
|
||||
use Aws\SimpleDb\Exception\SimpleDbException;
|
||||
use Aws\SimpleDb\SimpleDbClient;
|
||||
use Doctrine\KeyValueStore\KeyValueStoreException;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
|
||||
/**
|
||||
* SimpleDb storage
|
||||
@@ -33,14 +34,12 @@ use Aws\SimpleDb\Exception\SimpleDbException;
|
||||
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)
|
||||
{
|
||||
@@ -78,11 +77,11 @@ class SimpleDbStorage implements Storage
|
||||
{
|
||||
$this->createDomain($storageName);
|
||||
|
||||
$this->client->putAttributes(array(
|
||||
$this->client->putAttributes([
|
||||
'DomainName' => $storageName,
|
||||
'ItemName' => $key,
|
||||
'Attributes' => $this->makeAttributes($data),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,10 +97,10 @@ class SimpleDbStorage implements Storage
|
||||
*/
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$this->client->deleteAttributes(array(
|
||||
$this->client->deleteAttributes([
|
||||
'DomainName' => $storageName,
|
||||
'ItemName' => $key,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,19 +108,19 @@ class SimpleDbStorage implements Storage
|
||||
*/
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$select = "select * from {$storageName} where itemName() = '{$key}'";
|
||||
$select = 'select * from ' . $storageName . ' where itemName() = \'' . $key . '\'';
|
||||
|
||||
$iterator = $this->client->select(array(
|
||||
$iterator = $this->client->select([
|
||||
'SelectExpression' => $select,
|
||||
));
|
||||
|
||||
]);
|
||||
|
||||
$results = $iterator->get('Items');
|
||||
|
||||
if (count($results)) {
|
||||
$result = array_shift($results);
|
||||
|
||||
$data = array('id' => $result['Name']);
|
||||
|
||||
$data = ['id' => $result['Name']];
|
||||
|
||||
foreach ($result['Attributes'] as $attribute) {
|
||||
$data[$attribute['Name']] = $attribute['Value'];
|
||||
}
|
||||
@@ -133,9 +132,7 @@ class SimpleDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@@ -144,15 +141,17 @@ class SimpleDbStorage implements Storage
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createDomain($domainName)
|
||||
{
|
||||
try {
|
||||
$domain = $this->client->domainMetadata(array('DomainName' => $domainName));
|
||||
$domain = $this->client->domainMetadata(['DomainName' => $domainName]);
|
||||
} catch (NoSuchDomainException $e) {
|
||||
$this->client->createDomain(array('DomainName' => $domainName));
|
||||
$this->client->createDomain(['DomainName' => $domainName]);
|
||||
|
||||
$domain = $this->client->domainMetadata(array('DomainName' => $domainName));
|
||||
$domain = $this->client->domainMetadata(['DomainName' => $domainName]);
|
||||
} catch (SimpleDbException $e) {
|
||||
throw new KeyValueStoreException($e->getMessage(), 0, $e);
|
||||
}
|
||||
@@ -161,23 +160,24 @@ class SimpleDbStorage implements Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function makeAttributes($data)
|
||||
{
|
||||
$attributes = array();
|
||||
$attributes = [];
|
||||
|
||||
foreach ($data as $name => $value) {
|
||||
if ($value !== null && $value !== array() && $value !== '') {
|
||||
$attributes[] = array(
|
||||
'Name' => $name,
|
||||
'Value' => $value,
|
||||
if ($value !== null && $value !== [] && $value !== '') {
|
||||
$attributes[] = [
|
||||
'Name' => $name,
|
||||
'Value' => $value,
|
||||
'Replace' => true,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -47,70 +48,67 @@ interface Storage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function supportsPartialUpdates();
|
||||
public function supportsPartialUpdates();
|
||||
|
||||
/**
|
||||
* Does this storage support composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function supportsCompositePrimaryKeys();
|
||||
public function supportsCompositePrimaryKeys();
|
||||
|
||||
/**
|
||||
* Does this storage require composite primary keys?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function requiresCompositePrimaryKeys();
|
||||
public function requiresCompositePrimaryKeys();
|
||||
|
||||
/**
|
||||
* Insert data into the storage key specified.
|
||||
*
|
||||
* @param string $storageName
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @param array $data
|
||||
*/
|
||||
function insert($storageName, $key, array $data);
|
||||
public function insert($storageName, $key, array $data);
|
||||
|
||||
/**
|
||||
* Update data into the given key.
|
||||
*
|
||||
* @param string $storageName
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @param array $data
|
||||
*/
|
||||
function update($storageName, $key, array $data);
|
||||
public function update($storageName, $key, array $data);
|
||||
|
||||
/**
|
||||
* Delete data at key
|
||||
*
|
||||
* @param string $storageName
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
* @return void
|
||||
*/
|
||||
function delete($storageName, $key);
|
||||
public function delete($storageName, $key);
|
||||
|
||||
/**
|
||||
* Find data at key
|
||||
*
|
||||
* Important note: The returned array does contain the identifier (again)!
|
||||
*
|
||||
*
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
*
|
||||
* @throws Doctrine\KeyValueStore\NotFoundException When data with key is not found.
|
||||
*
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
* @return array
|
||||
*/
|
||||
function find($storageName, $key);
|
||||
public function find($storageName, $key);
|
||||
|
||||
/**
|
||||
* Return a name of the underlying storage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getName();
|
||||
public function getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Doctrine KeyValueStore
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to kontakt@beberlei.de so I can send you a copy immediately.
|
||||
* 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;
|
||||
@@ -18,4 +25,3 @@ use Doctrine\KeyValueStore\KeyValueStoreException;
|
||||
class StorageException extends KeyValueStoreException
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -16,13 +17,17 @@
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;
|
||||
|
||||
/**
|
||||
* Abstraction for WindowsAzure Authorization Schemes
|
||||
*
|
||||
* @link http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
interface AuthorizationSchema
|
||||
{
|
||||
@@ -33,9 +38,9 @@ interface AuthorizationSchema
|
||||
* @param string $path
|
||||
* @param string $queryString
|
||||
* @param string $body
|
||||
* @param array $headers
|
||||
* @param array $headers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function signRequest($method, $path, $queryString, $body, array $headers);
|
||||
public function signRequest($method, $path, $queryString, $body, array $headers);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Doctrine Key Value Store
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to kontakt@beberlei.de so I can send you a copy immediately.
|
||||
* 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\WindowsAzureTable;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\StorageException;
|
||||
|
||||
/**
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
class HttpStorageException extends StorageException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,6 +20,9 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;
|
||||
|
||||
/**
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
class SharedKeyAuthorization implements AuthorizationSchema
|
||||
{
|
||||
/**
|
||||
@@ -33,7 +37,7 @@ class SharedKeyAuthorization implements AuthorizationSchema
|
||||
public function __construct($accountName, $accountKey)
|
||||
{
|
||||
$this->accountName = $accountName;
|
||||
$this->accountKey = base64_decode($accountKey);
|
||||
$this->accountKey = base64_decode($accountKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,13 +46,13 @@ class SharedKeyAuthorization implements AuthorizationSchema
|
||||
*/
|
||||
public function signRequest($method, $path, $queryString, $body, array $headers)
|
||||
{
|
||||
$canonicalResource = "/" . $this->accountName . $path;
|
||||
$stringToSign = $method . "\n" .
|
||||
$canonicalResource = '/' . $this->accountName . $path;
|
||||
$stringToSign = $method . "\n" .
|
||||
md5($body) . "\n" .
|
||||
"application/atom+xml\n" .
|
||||
$headers['x-ms-date'] . "\n" .
|
||||
$canonicalResource;
|
||||
return "Authorization: SharedKey " . $this->accountName . ":" . base64_encode(hash_hmac('sha256', $stringToSign, $this->accountKey, true));
|
||||
return 'Authorization: SharedKey ' . $this->accountName . ':' .
|
||||
base64_encode(hash_hmac('sha256', $stringToSign, $this->accountKey, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -19,6 +20,9 @@
|
||||
|
||||
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;
|
||||
|
||||
/**
|
||||
* @deprecated This class is deprecated and will be removed in 2.0.
|
||||
*/
|
||||
class SharedKeyLiteAuthorization implements AuthorizationSchema
|
||||
{
|
||||
/**
|
||||
@@ -33,7 +37,7 @@ class SharedKeyLiteAuthorization implements AuthorizationSchema
|
||||
public function __construct($accountName, $accountKey)
|
||||
{
|
||||
$this->accountName = $accountName;
|
||||
$this->accountKey = base64_decode($accountKey);
|
||||
$this->accountKey = base64_decode($accountKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,10 +46,10 @@ class SharedKeyLiteAuthorization implements AuthorizationSchema
|
||||
*/
|
||||
public function signRequest($method, $path, $queryString, $body, array $headers)
|
||||
{
|
||||
$canonicalResource = "/" . $this->accountName . $path;
|
||||
$stringToSign = $headers['x-ms-date'] . "\n" .
|
||||
$canonicalResource = '/' . $this->accountName . $path;
|
||||
$stringToSign = $headers['x-ms-date'] . "\n" .
|
||||
$canonicalResource;
|
||||
return "Authorization: SharedKeyLite " . $this->accountName . ":" . base64_encode(hash_hmac('sha256', $stringToSign, $this->accountKey, true));
|
||||
return 'Authorization: SharedKeyLite ' . $this->accountName . ':' .
|
||||
base64_encode(hash_hmac('sha256', $stringToSign, $this->accountKey, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -20,11 +21,11 @@
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\KeyValueStore\Http\Client;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\HttpStorageException;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\HttpStorageException;
|
||||
|
||||
/**
|
||||
* Storage implementation for Microsoft Windows Azure Table.
|
||||
@@ -32,14 +33,15 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
* Using a HTTP client to communicate with the REST API of Azure Table.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @deprecated Use the AzureSdkTableStorage instead, this will be unmaintained.
|
||||
*
|
||||
* @deprecated This class is deprecated and will be removed in 2.0, use the AzureSdkTableStorage instead.
|
||||
*/
|
||||
class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
const WINDOWS_AZURE_TABLE_BASEURL = 'https://%s.table.core.windows.net';
|
||||
|
||||
const METADATA_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata';
|
||||
const DATA_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices';
|
||||
const DATA_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -59,7 +61,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
</entry>';
|
||||
|
||||
const XML_TEMPLATE_TABLE = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
|
||||
<title />
|
||||
<updated></updated>
|
||||
<author>
|
||||
@@ -73,12 +75,12 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
</content>
|
||||
</entry>';
|
||||
|
||||
const TYPE_INT32 = 'Edm.Int32';
|
||||
const TYPE_INT64 = 'Edm.Int64';
|
||||
const TYPE_INT32 = 'Edm.Int32';
|
||||
const TYPE_INT64 = 'Edm.Int64';
|
||||
const TYPE_DATETIME = 'Edm.DateTime';
|
||||
const TYPE_BOOLEAN = 'Edm.Boolean';
|
||||
const TYPE_DOUBLE = 'Edm.Double';
|
||||
const TYPE_BINARY = 'Edm.Binary';
|
||||
const TYPE_BOOLEAN = 'Edm.Boolean';
|
||||
const TYPE_DOUBLE = 'Edm.Double';
|
||||
const TYPE_BINARY = 'Edm.Binary';
|
||||
|
||||
/**
|
||||
* @var \Doctrine\KeyValueStore\Http\Client
|
||||
@@ -101,16 +103,16 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
private $now;
|
||||
|
||||
/**
|
||||
* @param HttpClient $client
|
||||
* @param HttpClient $client
|
||||
* @param AuthorizationSchema $authorization
|
||||
*/
|
||||
public function __construct(Client $client, $accountName, AuthorizationSchema $authorization, \DateTime $now = null)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->client = $client;
|
||||
$this->authorization = $authorization;
|
||||
$this->baseUrl = sprintf(self::WINDOWS_AZURE_TABLE_BASEURL, $accountName);
|
||||
$this->now = $now ? clone $now : new \DateTime();
|
||||
$this->now->setTimeZone(new \DateTimeZone("UTC"));
|
||||
$this->baseUrl = sprintf(self::WINDOWS_AZURE_TABLE_BASEURL, $accountName);
|
||||
$this->now = $now ? clone $now : new \DateTime();
|
||||
$this->now->setTimeZone(new \DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
public function supportsPartialUpdates()
|
||||
@@ -130,9 +132,9 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
public function insert($storageName, $key, array $data)
|
||||
{
|
||||
$headers = array(
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
);
|
||||
];
|
||||
// TODO: This sucks
|
||||
$tableName = $storageName;
|
||||
|
||||
@@ -147,15 +149,13 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$contentNodes->item(0)->appendChild($propertiesNode);
|
||||
$xml = $dom->saveXML();
|
||||
|
||||
$url = $this->baseUrl . '/' . $tableName;
|
||||
$url = $this->baseUrl . '/' . $tableName;
|
||||
$response = $this->request('POST', $url, $xml, $headers);
|
||||
|
||||
if ($response->getStatusCode() == 404) {
|
||||
|
||||
$this->createTable($tableName);
|
||||
$this->insert($storageName, $key, $data);
|
||||
} else if ($response->getStatusCode() >= 400) {
|
||||
|
||||
} elseif ($response->getStatusCode() >= 400) {
|
||||
$this->convertResponseToException($response);
|
||||
}
|
||||
}
|
||||
@@ -168,22 +168,22 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$node = $dom->getElementsByTagName('Message')->item(0);
|
||||
|
||||
throw new HttpStorageException(
|
||||
$node ? $node->nodeValue : "An error has occured"
|
||||
$node ? $node->nodeValue : 'An error has occured'
|
||||
);
|
||||
}
|
||||
|
||||
public function createTable($tableName)
|
||||
{
|
||||
$headers = array(
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
);
|
||||
];
|
||||
|
||||
$dom = $this->createDomDocumentRequestBody(self::XML_TEMPLATE_TABLE);
|
||||
$dom = $this->createDomDocumentRequestBody(self::XML_TEMPLATE_TABLE);
|
||||
$tableNode = $dom->getElementsByTagNameNS(self::DATA_NS, 'TableName')->item(0);
|
||||
$tableNode->appendChild($dom->createTextNode($tableName));
|
||||
$xml = $dom->saveXML();
|
||||
|
||||
$url = $this->baseUrl . '/Tables';
|
||||
$url = $this->baseUrl . '/Tables';
|
||||
$response = $this->request('POST', $url, $xml, $headers);
|
||||
|
||||
if ($response->getStatusCode() != 201) {
|
||||
@@ -195,11 +195,11 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
public function update($storageName, $key, array $data)
|
||||
{
|
||||
$headers = array(
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
'If-Match' => '*',
|
||||
);
|
||||
'x-ms-date' => $this->now(),
|
||||
'If-Match' => '*',
|
||||
];
|
||||
// TODO: This sucks
|
||||
$tableName = $storageName;
|
||||
|
||||
@@ -209,10 +209,14 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
$this->serializeKeys($propertiesNode, $key);
|
||||
$this->serializeProperties($propertiesNode, $key, $data);
|
||||
$keys = array_values($key);
|
||||
$clientUrl = $this->baseUrl . '/' . $tableName . ("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
|
||||
$idNode = $dom->getElementsByTagName('id')->item(0);
|
||||
$keys = array_values($key);
|
||||
$clientUrl = $this->baseUrl . '/' . $tableName . (
|
||||
"(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')"
|
||||
);
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode(
|
||||
"(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')"
|
||||
);
|
||||
$idNode = $dom->getElementsByTagName('id')->item(0);
|
||||
$idNode->appendChild($dom->createTextNode($clientUrl));
|
||||
|
||||
$contentNodes = $dom->getElementsByTagName('content');
|
||||
@@ -228,17 +232,19 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
public function delete($storageName, $key)
|
||||
{
|
||||
$headers = array(
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
'Content-Length' => 0,
|
||||
'If-Match' => '*',
|
||||
);
|
||||
'If-Match' => '*',
|
||||
];
|
||||
|
||||
// TODO: This sucks
|
||||
$tableName = $storageName;
|
||||
$keys = array_values($key);
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
|
||||
$keys = array_values($key);
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode(
|
||||
"(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')"
|
||||
);
|
||||
|
||||
$response = $this->request('DELETE', $url, '', $headers);
|
||||
|
||||
@@ -249,16 +255,18 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
public function find($storageName, $key)
|
||||
{
|
||||
$headers = array(
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
'Content-Length' => 0,
|
||||
);
|
||||
];
|
||||
|
||||
// TODO: This sucks
|
||||
$tableName = $storageName;
|
||||
$keys = array_values($key);
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
|
||||
$keys = array_values($key);
|
||||
$url = $this->baseUrl . '/' . $tableName . rawurlencode(
|
||||
"(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')"
|
||||
);
|
||||
|
||||
$response = $this->request('GET', $url, '', $headers);
|
||||
|
||||
@@ -276,7 +284,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$xpath = new \DOMXpath($dom);
|
||||
$xpath->registerNamespace('d', 'http://schemas.microsoft.com/ado/2007/08/dataservices');
|
||||
$xpath->registerNamespace('m', 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
|
||||
$entries = $xpath->evaluate('/atom:entry');
|
||||
|
||||
return $this->createRow(array_keys($key), $xpath, $entries->item(0));
|
||||
@@ -286,21 +294,21 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
$properties = $xpath->evaluate('atom:content/m:properties/d:*', $entry);
|
||||
|
||||
$data = array();
|
||||
$data = [];
|
||||
list($partitionKey, $rowKey) = $keyNames;
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$name = substr($property->tagName, 2);
|
||||
if ($name == "PartitionKey") {
|
||||
if ($name == 'PartitionKey') {
|
||||
$name = $partitionKey;
|
||||
} else if ($name == "RowKey") {
|
||||
} elseif ($name == 'RowKey') {
|
||||
$name = $rowKey;
|
||||
}
|
||||
|
||||
$value = $property->nodeValue;
|
||||
if ($property->hasAttributeNS(self::METADATA_NS, 'null')) {
|
||||
$value = null;
|
||||
} else if ($property->hasAttributeNS(self::METADATA_NS, 'type')) {
|
||||
} elseif ($property->hasAttributeNS(self::METADATA_NS, 'type')) {
|
||||
$type = $property->getAttributeNS(self::METADATA_NS, 'type');
|
||||
switch ($type) {
|
||||
case self::TYPE_BOOLEAN:
|
||||
@@ -310,7 +318,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$value = new \DateTime(substr($value, 0, 19), new \DateTimeZone('UTC'));
|
||||
break;
|
||||
case self::TYPE_INT32:
|
||||
$value = (int)$value;
|
||||
$value = (int) $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -322,23 +330,25 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
|
||||
{
|
||||
$headers = array(
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
$headers = [
|
||||
'Content-Type' => 'application/atom+xml',
|
||||
'x-ms-date' => $this->now(),
|
||||
'Content-Length' => 0,
|
||||
);
|
||||
];
|
||||
|
||||
$filters = array("PartitionKey eq " . $this->quoteFilterValue($query->getPartitionKey()));
|
||||
$filters = ['PartitionKey eq ' . $this->quoteFilterValue($query->getPartitionKey())];
|
||||
foreach ($query->getConditions() as $condition) {
|
||||
if ( ! in_array($condition[0], array('eq', 'neq', 'le', 'lt', 'ge', 'gt'))) {
|
||||
throw new \InvalidArgumentException("Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions.");
|
||||
if (! in_array($condition[0], ['eq', 'neq', 'le', 'lt', 'ge', 'gt'])) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions.'
|
||||
);
|
||||
}
|
||||
$filters[] = $key[1] . " " . $condition[0] . " " . $this->quoteFilterValue($condition[1]);
|
||||
$filters[] = $key[1] . ' ' . $condition[0] . ' ' . $this->quoteFilterValue($condition[1]);
|
||||
}
|
||||
|
||||
// TODO: This sucks
|
||||
$tableName = $storageName;
|
||||
$url = $this->baseUrl . '/' . $tableName . '()?$filter=' . rawurlencode(implode(' ', $filters));
|
||||
$url = $this->baseUrl . '/' . $tableName . '()?$filter=' . rawurlencode(implode(' ', $filters));
|
||||
if ($query->getLimit()) {
|
||||
$url .= '&$top=' . $query->getLimit();
|
||||
}
|
||||
@@ -355,12 +365,12 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$xpath = new \DOMXpath($dom);
|
||||
$xpath->registerNamespace('d', 'http://schemas.microsoft.com/ado/2007/08/dataservices');
|
||||
$xpath->registerNamespace('m', 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
|
||||
$entries = $xpath->evaluate('/atom:feed/atom:entry');
|
||||
|
||||
$results = array();
|
||||
$results = [];
|
||||
foreach ($entries as $entry) {
|
||||
$data = $this->createRow($key, $xpath, $entry);
|
||||
$data = $this->createRow($key, $xpath, $entry);
|
||||
$results[] = $hydrateRow ? $hydrateRow($data) : $data;
|
||||
}
|
||||
|
||||
@@ -373,7 +383,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
return $value;
|
||||
}
|
||||
|
||||
return "'" . str_replace("'", "", $value) . "'";
|
||||
return "'" . str_replace("'", '', $value) . "'";
|
||||
}
|
||||
|
||||
public function getName()
|
||||
@@ -407,7 +417,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
if ($propertyValue instanceof \DateTime) {
|
||||
return self::TYPE_DATETIME;
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
private function convertPropertyValue($propertyValue, $type)
|
||||
@@ -417,7 +427,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$propertyValue = $this->isoDate($propertyValue);
|
||||
break;
|
||||
case self::TYPE_BOOLEAN:
|
||||
$propertyValue = $propertyValue ? "1" : "0";
|
||||
$propertyValue = $propertyValue ? '1' : '0';
|
||||
break;
|
||||
}
|
||||
return $propertyValue;
|
||||
@@ -429,7 +439,11 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
foreach ($key as $keyName => $keyValue) {
|
||||
switch ($keys) {
|
||||
case 0:
|
||||
$partitionKey = $propertiesNode->ownerDocument->createElementNS(self::DATA_NS, 'PartitionKey', $keyValue);
|
||||
$partitionKey = $propertiesNode->ownerDocument->createElementNS(
|
||||
self::DATA_NS,
|
||||
'PartitionKey',
|
||||
$keyValue
|
||||
);
|
||||
$propertiesNode->appendChild($partitionKey);
|
||||
break;
|
||||
case 1:
|
||||
@@ -437,27 +451,27 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
$propertiesNode->appendChild($rowKey);
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException("Only exactly 2 composite key fields allowed.");
|
||||
throw new \RuntimeException('Only exactly 2 composite key fields allowed.');
|
||||
}
|
||||
$keys++;
|
||||
++$keys;
|
||||
}
|
||||
}
|
||||
|
||||
private function request($method, $url, $xml, $headers)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
$requestDate = $this->now->format('D, d M Y H:i:s') . ' GMT';
|
||||
$headers['Content-Length'] = strlen($xml);
|
||||
$headers['Date'] = $requestDate;
|
||||
$headers['x-ms-date'] = $requestDate;
|
||||
$authorizationHeader = $this->authorization->signRequest(
|
||||
$parts = parse_url($url);
|
||||
$requestDate = $this->now->format('D, d M Y H:i:s') . ' GMT';
|
||||
$headers['Content-Length'] = strlen($xml);
|
||||
$headers['Date'] = $requestDate;
|
||||
$headers['x-ms-date'] = $requestDate;
|
||||
$authorizationHeader = $this->authorization->signRequest(
|
||||
$method,
|
||||
isset($parts['path']) ? $parts['path'] : '/',
|
||||
isset($parts['query']) ? $parts['query'] : '',
|
||||
$xml,
|
||||
$headers
|
||||
);
|
||||
$authorizationParts = explode(":" , $authorizationHeader, 2);
|
||||
$authorizationParts = explode(':', $authorizationHeader, 2);
|
||||
$headers[$authorizationParts[0]] = ltrim($authorizationParts[1]);
|
||||
return $this->client->request($method, $url, $xml, $headers);
|
||||
}
|
||||
@@ -465,11 +479,11 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
private function serializeProperties($propertiesNode, array $key, array $data)
|
||||
{
|
||||
foreach ($data as $propertyName => $propertyValue) {
|
||||
if ( isset($key[$propertyName])) {
|
||||
if (isset($key[$propertyName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $this->getPropertyType($propertyValue);
|
||||
$type = $this->getPropertyType($propertyValue);
|
||||
$propertyValue = $this->convertPropertyValue($propertyValue, $type);
|
||||
|
||||
$property = $propertiesNode->ownerDocument->createElementNS(self::DATA_NS, $propertyName, $propertyValue);
|
||||
@@ -481,4 +495,3 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -35,10 +36,12 @@ class UnitOfWork
|
||||
* @var ClassMetadataFactory
|
||||
*/
|
||||
private $cmf;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
private $storageDriver;
|
||||
|
||||
/**
|
||||
* @var IdHandlingStrategy
|
||||
*/
|
||||
@@ -52,14 +55,38 @@ class UnitOfWork
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $identifiers;
|
||||
private $identifiers = [];
|
||||
|
||||
private $originalData;
|
||||
private $scheduledInsertions = array();
|
||||
private $scheduledDeletions = array();
|
||||
private $identityMap = array();
|
||||
/**
|
||||
* @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;
|
||||
@@ -70,27 +97,46 @@ 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);
|
||||
if (isset($this->identityMap[$className][$idHash])) {
|
||||
return $this->identityMap[$className][$idHash];
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
public function reconsititute($className, $key)
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string|array $key
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function reconstititute($className, $key)
|
||||
{
|
||||
$class = $this->cmf->getMetadataFor($className);
|
||||
$id = $this->idHandler->normalizeId($class, $key);
|
||||
$data = $this->storageDriver->find($class->storageName, $id);
|
||||
|
||||
if (!$data) {
|
||||
if (! $data) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
@@ -99,16 +145,18 @@ class UnitOfWork
|
||||
|
||||
public function createEntity($class, $id, $data)
|
||||
{
|
||||
if ( isset($data['php_class'])) {
|
||||
if ( $data['php_class'] !== $class->name && ! is_subclass_of($data['php_class'], $class->name)) {
|
||||
throw new \RuntimeException("Row is of class '" . $data['php_class'] . "' which is not a subtype of expected " . $class->name);
|
||||
if (isset($data['php_class'])) {
|
||||
if ($data['php_class'] !== $class->name && ! is_subclass_of($data['php_class'], $class->name)) {
|
||||
throw new \RuntimeException(
|
||||
"Row is of class '" . $data['php_class'] . "' which is not a subtype of expected " . $class->name
|
||||
);
|
||||
}
|
||||
$class = $this->cmf->getMetadataFor($data['php_class']);
|
||||
}
|
||||
unset($data['php_class']);
|
||||
|
||||
$object = $this->tryGetById($class->name, $id);
|
||||
if ( $object) {
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
@@ -136,16 +184,16 @@ class UnitOfWork
|
||||
private function computeChangeSet($class, $object)
|
||||
{
|
||||
$snapshot = $this->getObjectSnapshot($class, $object);
|
||||
$changeSet = array();
|
||||
$changeSet = [];
|
||||
$originalData = $this->originalData[spl_object_hash($object)];
|
||||
|
||||
foreach ($snapshot as $field => $value) {
|
||||
if ( ! isset($originalData[$field]) || $originalData[$field] !== $value) {
|
||||
if (! isset($originalData[$field]) || $originalData[$field] !== $value) {
|
||||
$changeSet[$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $changeSet && ! $this->storageDriver->supportsPartialUpdates()) {
|
||||
if ($changeSet && ! $this->storageDriver->supportsPartialUpdates()) {
|
||||
$changeSet = array_merge($originalData, $changeSet);
|
||||
}
|
||||
return $changeSet;
|
||||
@@ -153,16 +201,16 @@ class UnitOfWork
|
||||
|
||||
private function getObjectSnapshot($class, $object)
|
||||
{
|
||||
$data = array();
|
||||
$data = [];
|
||||
|
||||
foreach ($class->reflFields as $fieldName => $reflProperty) {
|
||||
if ( ! isset( $class->fields[$fieldName]['id'])) {
|
||||
if (! isset($class->fields[$fieldName]['id'])) {
|
||||
$data[$fieldName] = $reflProperty->getValue($object);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (get_object_vars($object) as $property => $value) {
|
||||
if ( ! isset($data[$property])) {
|
||||
if (! isset($data[$property])) {
|
||||
$data[$property] = $value;
|
||||
}
|
||||
}
|
||||
@@ -180,14 +228,14 @@ class UnitOfWork
|
||||
$class = $this->cmf->getMetadataFor(get_class($object));
|
||||
$id = $this->idHandler->getIdentifier($class, $object);
|
||||
|
||||
if ( ! $id) {
|
||||
throw new \RuntimeException("Trying to persist entity that has no id.");
|
||||
if (! $id) {
|
||||
throw new \RuntimeException('Trying to persist entity that has no id.');
|
||||
}
|
||||
|
||||
$idHash = $this->idHandler->hash($id);
|
||||
|
||||
if (isset($this->identityMap[$class->name][$idHash])) {
|
||||
throw new \RuntimeException("Object with ID already exists.");
|
||||
throw new \RuntimeException('Object with ID already exists.');
|
||||
}
|
||||
|
||||
$this->scheduledInsertions[$oid] = $object;
|
||||
@@ -197,8 +245,10 @@ class UnitOfWork
|
||||
public function scheduleForDelete($object)
|
||||
{
|
||||
$oid = spl_object_hash($object);
|
||||
if (!isset($this->identifiers[$oid])) {
|
||||
throw new \RuntimeException("Object scheduled for deletion is not managed. Only managed objects can be deleted.");
|
||||
if (! isset($this->identifiers[$oid])) {
|
||||
throw new \RuntimeException(
|
||||
'Object scheduled for deletion is not managed. Only managed objects can be deleted.'
|
||||
);
|
||||
}
|
||||
$this->scheduledDeletions[$oid] = $object;
|
||||
}
|
||||
@@ -209,7 +259,7 @@ class UnitOfWork
|
||||
foreach ($entities as $object) {
|
||||
$hash = spl_object_hash($object);
|
||||
|
||||
if ( isset($this->scheduledInsertions[$hash])) {
|
||||
if (isset($this->scheduledInsertions[$hash])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -237,8 +287,8 @@ class UnitOfWork
|
||||
$id = $this->idHandler->getIdentifier($class, $object);
|
||||
$id = $this->idConverter->serialize($class, $id);
|
||||
|
||||
if ( ! $id) {
|
||||
throw new \RuntimeException("Trying to persist entity that has no id.");
|
||||
if (! $id) {
|
||||
throw new \RuntimeException('Trying to persist entity that has no id.');
|
||||
}
|
||||
|
||||
$data = $this->getObjectSnapshot($class, $object);
|
||||
@@ -275,17 +325,19 @@ class UnitOfWork
|
||||
$this->processInsertions();
|
||||
$this->processDeletions();
|
||||
|
||||
$this->scheduledInsertions = array();
|
||||
$this->scheduledDeletions = array();
|
||||
$this->scheduledInsertions = [];
|
||||
$this->scheduledDeletions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the unit of work.
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->scheduledInsertions = array();
|
||||
$this->scheduledDeletions = array();
|
||||
$this->identifiers = array();
|
||||
$this->originalData = array();
|
||||
$this->identityMap = array();
|
||||
$this->scheduledInsertions = [];
|
||||
$this->scheduledDeletions = [];
|
||||
$this->identifiers = [];
|
||||
$this->originalData = [];
|
||||
$this->identityMap = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,30 @@
|
||||
<?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;
|
||||
|
||||
use Doctrine\KeyValueStore\Configuration;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNoMappingDriver()
|
||||
@@ -16,17 +38,16 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefaultCacheDriver()
|
||||
{
|
||||
$config = new Configuration();
|
||||
$cache = $config->getMetadataCache();
|
||||
$cache = $config->getMetadataCache();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Cache\Cache', $cache);
|
||||
}
|
||||
|
||||
public function testDefaultIdConverterStrategy()
|
||||
{
|
||||
$config = new Configuration();
|
||||
$config = new Configuration();
|
||||
$strategy = $config->getIdConverterStrategy();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\KeyValueStore\Id\NullIdConverter', $strategy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -13,7 +14,7 @@
|
||||
* 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 LGPL. For more information, see
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
@@ -22,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;
|
||||
@@ -30,7 +34,6 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
public function setUp()
|
||||
{
|
||||
$this->storage = $this->createStorage();
|
||||
$this->manager = $this->createManager($this->storage);
|
||||
}
|
||||
|
||||
abstract protected function createStorage();
|
||||
@@ -41,12 +44,17 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
|
||||
abstract protected function find($id);
|
||||
|
||||
public function testPersistItem()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testPersistItem($mappingDriver)
|
||||
{
|
||||
$post = new Post();
|
||||
$post->id = "1";
|
||||
$post->headline = "asdf";
|
||||
$post->text = "foo";
|
||||
$this->manager = $this->createManager($this->storage, $mappingDriver);
|
||||
|
||||
$post = new Post();
|
||||
$post->id = '1';
|
||||
$post->headline = 'asdf';
|
||||
$post->text = 'foo';
|
||||
|
||||
$this->manager->persist($post);
|
||||
$this->manager->flush();
|
||||
@@ -54,12 +62,17 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
$this->assertKeyExists($post->id);
|
||||
}
|
||||
|
||||
public function testPersistAndRetrieveItem()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testPersistAndRetrieveItem($mappingDriver)
|
||||
{
|
||||
$post = new Post();
|
||||
$post->id = "1";
|
||||
$post->headline = "asdf";
|
||||
$post->text = "foo";
|
||||
$this->manager = $this->createManager($this->storage, $mappingDriver);
|
||||
|
||||
$post = new Post();
|
||||
$post->id = '1';
|
||||
$post->headline = 'asdf';
|
||||
$post->text = 'foo';
|
||||
|
||||
$this->manager->persist($post);
|
||||
$this->manager->flush();
|
||||
@@ -68,9 +81,14 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
$this->assertSame($post, $post2);
|
||||
}
|
||||
|
||||
public function testRetrieveItem()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testRetrieveItem($mappingDriver)
|
||||
{
|
||||
$this->populate(1, array('id' => 1, 'headline' => 'test', 'body' => 'tset', 'foo' => 'bar', 'php_class' => __NAMESPACE__ . '\\Post'));
|
||||
$this->manager = $this->createManager($this->storage, $mappingDriver);
|
||||
|
||||
$this->populate(1, ['id' => 1, 'headline' => 'test', 'body' => 'tset', 'foo' => 'bar', 'php_class' => __NAMESPACE__ . '\\Post']);
|
||||
|
||||
$post = $this->manager->find(__NAMESPACE__ . '\\Post', 1);
|
||||
|
||||
@@ -82,39 +100,49 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
$this->assertSame($post, $post2);
|
||||
}
|
||||
|
||||
public function testUpdateClass()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testUpdateClass($mappingDriver)
|
||||
{
|
||||
$post = new Post();
|
||||
$post->id = "1";
|
||||
$post->headline = "asdf";
|
||||
$post->text = "foo";
|
||||
$this->manager = $this->createManager($this->storage, $mappingDriver);
|
||||
|
||||
$post = new Post();
|
||||
$post->id = '1';
|
||||
$post->headline = 'asdf';
|
||||
$post->text = 'foo';
|
||||
|
||||
$this->manager->persist($post);
|
||||
$this->manager->flush();
|
||||
|
||||
$post->body = "bar";
|
||||
$post->text = "baz";
|
||||
$post->body = 'bar';
|
||||
$post->text = 'baz';
|
||||
|
||||
$this->manager->flush();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 1,
|
||||
'headline' => 'asdf',
|
||||
'body' => 'bar',
|
||||
'text' => 'baz',
|
||||
'php_class' => __NAMESPACE__ . '\\Post'
|
||||
),
|
||||
[
|
||||
'id' => 1,
|
||||
'headline' => 'asdf',
|
||||
'body' => 'bar',
|
||||
'text' => 'baz',
|
||||
'php_class' => __NAMESPACE__ . '\\Post',
|
||||
],
|
||||
$this->find(1)
|
||||
);
|
||||
}
|
||||
|
||||
public function testRemoveClass()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testRemoveClass($mappingDriver)
|
||||
{
|
||||
$post = new Post();
|
||||
$post->id = "1";
|
||||
$post->headline = "asdf";
|
||||
$post->text = "foo";
|
||||
$this->manager = $this->createManager($this->storage, $mappingDriver);
|
||||
|
||||
$post = new Post();
|
||||
$post->id = '1';
|
||||
$post->headline = 'asdf';
|
||||
$post->text = 'foo';
|
||||
|
||||
$this->manager->persist($post);
|
||||
$this->manager->flush();
|
||||
@@ -126,6 +154,15 @@ abstract class BasicCrudTestCase extends KeyValueStoreTestCase
|
||||
|
||||
$this->assertKeyNotExists($post->id);
|
||||
}
|
||||
|
||||
public function mappingDrivers()
|
||||
{
|
||||
return [
|
||||
['annotation'],
|
||||
['yaml'],
|
||||
['xml'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,5 +174,4 @@ class Post
|
||||
public $id;
|
||||
public $headline;
|
||||
public $body;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
<?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\Functional;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class CompositeBasicCrudTest extends BasicCrudTestCase
|
||||
{
|
||||
private $cache;
|
||||
@@ -11,28 +33,27 @@ class CompositeBasicCrudTest extends BasicCrudTestCase
|
||||
protected function createStorage()
|
||||
{
|
||||
$this->cache = new ArrayCache();
|
||||
$storage = new DoctrineCacheStorage($this->cache);
|
||||
$storage = new DoctrineCacheStorage($this->cache);
|
||||
return $storage;
|
||||
}
|
||||
|
||||
public function assertKeyExists($id)
|
||||
{
|
||||
$this->assertTrue($this->cache->contains("post-oid:id=".$id.";"));
|
||||
$this->assertTrue($this->cache->contains('post-oid:id=' . $id . ';'));
|
||||
}
|
||||
|
||||
public function assertKeyNotExists($id)
|
||||
{
|
||||
$this->assertFalse($this->cache->contains("post-oid:id=".$id.";"));
|
||||
$this->assertFalse($this->cache->contains('post-oid:id=' . $id . ';'));
|
||||
}
|
||||
|
||||
public function populate($id, array $data)
|
||||
{
|
||||
$this->cache->save("post-oid:id=".$id.";", $data);
|
||||
$this->cache->save('post-oid:id=' . $id . ';', $data);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->cache->fetch("post-oid:id=".$id.";");
|
||||
return $this->cache->fetch('post-oid:id=' . $id . ';');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,56 @@
|
||||
<?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\Functional;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations as KVS;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class InheritanceTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $manager;
|
||||
protected $storage;
|
||||
|
||||
public function setUp()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testInheritance($mappingDriver)
|
||||
{
|
||||
$cache = new ArrayCache();
|
||||
$storage = new DoctrineCacheStorage($cache);
|
||||
$this->manager = $this->createManager($storage);
|
||||
}
|
||||
$cache = new ArrayCache();
|
||||
$storage = new DoctrineCacheStorage($cache);
|
||||
$this->manager = $this->createManager($storage, $mappingDriver);
|
||||
|
||||
public function testInheritance()
|
||||
{
|
||||
$parent = new ParentEntity;
|
||||
$parent->id = 1;
|
||||
$parent->foo = "foo";
|
||||
$parent = new ParentEntity;
|
||||
$parent->id = 1;
|
||||
$parent->foo = 'foo';
|
||||
$this->manager->persist($parent);
|
||||
|
||||
$child = new ChildEntity;
|
||||
$child->id = 2;
|
||||
$child->foo = "bar";
|
||||
$child->bar = "baz";
|
||||
$child = new ChildEntity;
|
||||
$child->id = 2;
|
||||
$child->foo = 'bar';
|
||||
$child->bar = 'baz';
|
||||
|
||||
$this->manager->persist($child);
|
||||
$this->manager->flush();
|
||||
@@ -45,6 +67,15 @@ class InheritanceTest extends KeyValueStoreTestCase
|
||||
$this->assertEquals('bar', $child->foo);
|
||||
$this->assertEquals('baz', $child->bar);
|
||||
}
|
||||
|
||||
public function mappingDrivers()
|
||||
{
|
||||
return [
|
||||
['annotation'],
|
||||
['yaml'],
|
||||
['xml'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@@ -13,41 +14,53 @@
|
||||
* 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 LGPL. For more information, see
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\KeyValueStore\Functional;
|
||||
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
use Doctrine\KeyValueStore\Mapping\Annotations as KVS;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class PersistTest extends KeyValueStoreTestCase
|
||||
{
|
||||
public function testPersistUnmappedThrowsException()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testPersistUnmappedThrowsException($mappingDriver)
|
||||
{
|
||||
$manager = $this->createManager();
|
||||
$manager = $this->createManager(null, $mappingDriver);
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException', 'stdClass is not a valid key-value-store entity.');
|
||||
$manager->persist(new \stdClass());
|
||||
}
|
||||
|
||||
public function testPersistWithoutIdThrowsException()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testPersistWithoutIdThrowsException($mappingDriver)
|
||||
{
|
||||
$manager = $this->createManager();
|
||||
$manager = $this->createManager(null, $mappingDriver);
|
||||
$persist = new PersistEntity();
|
||||
|
||||
$this->setExpectedException('RuntimeException', 'Trying to persist entity that has no id.');
|
||||
$manager->persist($persist);
|
||||
}
|
||||
|
||||
public function testPersistKnownIdThrowsException()
|
||||
/**
|
||||
* @dataProvider mappingDrivers
|
||||
*/
|
||||
public function testPersistKnownIdThrowsException($mappingDriver)
|
||||
{
|
||||
$manager = $this->createManager();
|
||||
$persist = new PersistEntity();
|
||||
$manager = $this->createManager(null, $mappingDriver);
|
||||
$persist = new PersistEntity();
|
||||
$persist->id = 1;
|
||||
|
||||
$persist2 = new PersistEntity();
|
||||
$persist2 = new PersistEntity();
|
||||
$persist2->id = 1;
|
||||
|
||||
$manager->persist($persist);
|
||||
@@ -55,6 +68,15 @@ class PersistTest extends KeyValueStoreTestCase
|
||||
$this->setExpectedException('RuntimeException', 'Object with ID already exists.');
|
||||
$manager->persist($persist2);
|
||||
}
|
||||
|
||||
public function mappingDrivers()
|
||||
{
|
||||
return [
|
||||
['annotation'],
|
||||
['yaml'],
|
||||
['xml'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
<?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\Functional;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SingleBasicCrudTest extends BasicCrudTestCase
|
||||
{
|
||||
private $cache;
|
||||
@@ -11,23 +33,23 @@ class SingleBasicCrudTest extends BasicCrudTestCase
|
||||
protected function createStorage()
|
||||
{
|
||||
$this->cache = new ArrayCache();
|
||||
$storage = new DoctrineCacheStorage($this->cache, false);
|
||||
$storage = new DoctrineCacheStorage($this->cache, false);
|
||||
return $storage;
|
||||
}
|
||||
|
||||
public function assertKeyExists($id)
|
||||
{
|
||||
$this->assertTrue($this->cache->contains("post-".$id));
|
||||
$this->assertTrue($this->cache->contains('post-' . $id));
|
||||
}
|
||||
|
||||
public function assertKeyNotExists($id)
|
||||
{
|
||||
$this->assertFalse($this->cache->contains("post-".$id));
|
||||
$this->assertFalse($this->cache->contains('post-' . $id));
|
||||
}
|
||||
|
||||
public function populate($id, array $data)
|
||||
{
|
||||
$this->cache->save("post-".$id, $data);
|
||||
$this->cache->save('post-' . $id, $data);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
@@ -35,4 +57,3 @@ class SingleBasicCrudTest extends BasicCrudTestCase
|
||||
return $this->storage->find('post', $id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,33 @@
|
||||
<?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\Functional\Storage;
|
||||
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\AzureSdkTableStorage;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\AzureSdkTableStorage;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
use WindowsAzure\Common\ServicesBuilder;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AzureSdkTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $storage;
|
||||
@@ -17,11 +37,11 @@ class AzureSdkTableTest extends KeyValueStoreTestCase
|
||||
parent::setUp();
|
||||
|
||||
if (empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME']) || empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY'])) {
|
||||
$this->markTestSkipped("Missing Azure credentials.");
|
||||
$this->markTestSkipped('Missing Azure credentials.');
|
||||
}
|
||||
|
||||
$connectionString = sprintf(
|
||||
"DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s",
|
||||
'DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s',
|
||||
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME'],
|
||||
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY']
|
||||
);
|
||||
@@ -34,42 +54,42 @@ class AzureSdkTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
$key = array("dist" => "sdktest", "range" => time());
|
||||
$storage->insert("test", $key, array("foo" => "bar"));
|
||||
$data = $storage->find("test", $key);
|
||||
$key = ['dist' => 'sdktest', 'range' => time()];
|
||||
$storage->insert('test', $key, ['foo' => 'bar']);
|
||||
$data = $storage->find('test', $key);
|
||||
|
||||
$this->assertInstanceOf('DateTime', $data['Timestamp']);
|
||||
$this->assertEquals('bar', $data['foo']);
|
||||
$this->assertEquals('sdktest', $data['dist']);
|
||||
$this->assertEquals($key['range'], $data['range']);
|
||||
|
||||
$storage->update("test", $key, array("foo" => "baz", "bar" => "baz"));
|
||||
$data = $storage->find("test", $key);
|
||||
$storage->update('test', $key, ['foo' => 'baz', 'bar' => 'baz']);
|
||||
$data = $storage->find('test', $key);
|
||||
|
||||
$this->assertEquals('baz', $data['foo']);
|
||||
$this->assertEquals('baz', $data['bar']);
|
||||
|
||||
$storage->delete("test", $key);
|
||||
$storage->delete('test', $key);
|
||||
|
||||
$this->setExpectedException("Doctrine\KeyValueStore\NotFoundException");
|
||||
$storage->find("test", $key);
|
||||
$storage->find('test', $key);
|
||||
}
|
||||
|
||||
public function testTypes()
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
$data = array(
|
||||
"string" => "foo",
|
||||
"date" => new \DateTime("now"),
|
||||
"int" => 1234,
|
||||
"float" => 123.45,
|
||||
"bool" => false,
|
||||
);
|
||||
$data = [
|
||||
'string' => 'foo',
|
||||
'date' => new \DateTime('now'),
|
||||
'int' => 1234,
|
||||
'float' => 123.45,
|
||||
'bool' => false,
|
||||
];
|
||||
|
||||
$key = array("dist" => "sdktest", "range" => time()+1);
|
||||
$storage->insert("test", $key, $data);
|
||||
$data = $storage->find("test", $key);
|
||||
$key = ['dist' => 'sdktest', 'range' => time()+1];
|
||||
$storage->insert('test', $key, $data);
|
||||
$data = $storage->find('test', $key);
|
||||
|
||||
$this->assertInstanceOf('DateTime', $data['date']);
|
||||
$this->assertInternalType('string', $data['string']);
|
||||
@@ -83,11 +103,10 @@ class AzureSdkTableTest extends KeyValueStoreTestCase
|
||||
$rangeQuery = new RangeQuery($this->createManager(), 'test', 'sdktest');
|
||||
$rangeQuery->rangeLessThan(time());
|
||||
|
||||
$data = $this->storage->executeRangeQuery($rangeQuery, 'test', array('dist', 'range'), function($row) {
|
||||
$data = $this->storage->executeRangeQuery($rangeQuery, 'test', ['dist', 'range'], function ($row) {
|
||||
return $row;
|
||||
});
|
||||
|
||||
$this->assertTrue(count($data) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?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\Functional\Storage;
|
||||
|
||||
use Cassandra;
|
||||
use Doctrine\KeyValueStore\Storage\CassandraStorage;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @requires extension cassandra
|
||||
*/
|
||||
class CassandraTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $session;
|
||||
private $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$cluster = Cassandra::cluster()->build();
|
||||
$this->session = $cluster->connect();
|
||||
|
||||
try {
|
||||
$this->session->execute(new \Cassandra\SimpleStatement('DROP KEYSPACE doctrine'));
|
||||
} catch (\Cassandra\Exception\RuntimeException $e) {
|
||||
// Cannot drop non existing keyspace 'doctrine'.
|
||||
}
|
||||
|
||||
$cql = "CREATE KEYSPACE doctrine WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
|
||||
$statement = new \Cassandra\SimpleStatement($cql);
|
||||
$this->session->execute($statement);
|
||||
|
||||
$this->session->execute(new \Cassandra\SimpleStatement('USE doctrine'));
|
||||
|
||||
$cql = 'CREATE TABLE books (id int, author text, title text, PRIMARY KEY (id));';
|
||||
|
||||
$this->session->execute(new \Cassandra\SimpleStatement($cql));
|
||||
$this->storage = new CassandraStorage($this->session);
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('books', ['id' => 1], $data);
|
||||
|
||||
$cql = 'SELECT * FROM books WHERE id = 1';
|
||||
$result = $this->session->execute(new \Cassandra\SimpleStatement($cql));
|
||||
$rows = iterator_to_array($result);
|
||||
|
||||
$this->assertEquals('1', $rows[0]['id']);
|
||||
$this->assertEquals('John Doe', $rows[0]['author']);
|
||||
$this->assertEquals('example book', $rows[0]['title']);
|
||||
}
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('books', ['id' => 2], $data);
|
||||
|
||||
$this->assertEquals($data, $this->storage->find('books', ['id' => 2]));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('books', ['id' => 3], $data);
|
||||
$this->storage->update('books', ['id' => 3], ['author' => 'Jane Doe']);
|
||||
|
||||
$this->assertEquals(
|
||||
['author' => 'Jane Doe', 'title' => 'example book'],
|
||||
$this->storage->find('books', ['id' => 3])
|
||||
);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->insert('books', ['id' => 4], $data);
|
||||
$this->storage->delete('books', ['id' => 4]);
|
||||
|
||||
$this->setExpectedException('Doctrine\KeyValueStore\NotFoundException');
|
||||
|
||||
$this->storage->find('books', ['id' => 4]);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,34 @@
|
||||
<?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\Functional\Storage;
|
||||
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage;
|
||||
use Doctrine\KeyValueStore\Http\SocketClient;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\SharedKeyLiteAuthorization;
|
||||
use Doctrine\KeyValueStore\Http\SocketClient;
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTableStorage;
|
||||
use Doctrine\Tests\KeyValueStoreTestCase;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class WindowsAzureTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
private $storage;
|
||||
@@ -16,7 +38,7 @@ class WindowsAzureTableTest extends KeyValueStoreTestCase
|
||||
parent::setUp();
|
||||
|
||||
if (empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME']) || empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY'])) {
|
||||
$this->markTestSkipped("Missing Azure credentials.");
|
||||
$this->markTestSkipped('Missing Azure credentials.');
|
||||
}
|
||||
|
||||
switch ($GLOBALS['DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA']) {
|
||||
@@ -39,25 +61,25 @@ class WindowsAzureTableTest extends KeyValueStoreTestCase
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
$key = array("dist" => "foo", "range" => time());
|
||||
$storage->insert("test", $key, array("foo" => "bar"));
|
||||
$data = $storage->find("test", $key);
|
||||
$key = ['dist' => 'foo', 'range' => time()];
|
||||
$storage->insert('test', $key, ['foo' => 'bar']);
|
||||
$data = $storage->find('test', $key);
|
||||
|
||||
$this->assertInstanceOf('DateTime', $data['Timestamp']);
|
||||
$this->assertEquals('bar', $data['foo']);
|
||||
$this->assertEquals('foo', $data['dist']);
|
||||
$this->assertEquals($key['range'], $data['range']);
|
||||
|
||||
$storage->update("test", $key, array("foo" => "baz", "bar" => "baz"));
|
||||
$data = $storage->find("test", $key);
|
||||
$storage->update('test', $key, ['foo' => 'baz', 'bar' => 'baz']);
|
||||
$data = $storage->find('test', $key);
|
||||
|
||||
$this->assertEquals('baz', $data['foo']);
|
||||
$this->assertEquals('baz', $data['bar']);
|
||||
|
||||
$storage->delete("test", $key);
|
||||
$storage->delete('test', $key);
|
||||
|
||||
$this->setExpectedException("Doctrine\KeyValueStore\NotFoundException");
|
||||
$storage->find("test", $key);
|
||||
$storage->find('test', $key);
|
||||
}
|
||||
|
||||
public function testQueryRange()
|
||||
@@ -65,11 +87,10 @@ class WindowsAzureTableTest extends KeyValueStoreTestCase
|
||||
$rangeQuery = new RangeQuery($this->createManager(), 'test', 'foo');
|
||||
$rangeQuery->rangeLessThan(time());
|
||||
|
||||
$data = $this->storage->executeRangeQuery($rangeQuery, 'test', array('dist', 'range'), function($row) {
|
||||
$data = $this->storage->executeRangeQuery($rangeQuery, 'test', ['dist', 'range'], function ($row) {
|
||||
return $row;
|
||||
});
|
||||
|
||||
$this->assertTrue(count($data) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,32 @@
|
||||
<?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\Mapping;
|
||||
|
||||
use Doctrine\KeyValueStore\Mapping\ClassMetadata;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Doctrine\KeyValueStore\Mapping\ClassMetadata
|
||||
* @group legacy
|
||||
*/
|
||||
class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $metadata;
|
||||
@@ -20,34 +44,147 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testIdentifier()
|
||||
{
|
||||
$this->metadata->mapIdentifier("id");
|
||||
$this->metadata->mapIdentifier('id');
|
||||
$this->assertFalse($this->metadata->isCompositeKey);
|
||||
|
||||
$this->metadata->mapIdentifier("id2");
|
||||
$this->metadata->mapIdentifier('id2');
|
||||
|
||||
$this->assertEquals(array("id", "id2"), $this->metadata->identifier);
|
||||
$this->assertEquals(['id', 'id2'], $this->metadata->identifier);
|
||||
$this->assertTrue($this->metadata->isCompositeKey);
|
||||
}
|
||||
|
||||
public function testIdentifierfield()
|
||||
{
|
||||
$this->metadata->mapIdentifier("id");
|
||||
$this->metadata->mapIdentifier('id');
|
||||
|
||||
$this->assertEquals(array('id' => array('fieldName' => 'id', 'id' => true)), $this->metadata->fields);
|
||||
$this->assertEquals(['id' => ['fieldName' => 'id', 'id' => true]], $this->metadata->fields);
|
||||
}
|
||||
|
||||
public function testMapField()
|
||||
{
|
||||
$this->metadata->mapField(array('fieldName' => 'metadata'));
|
||||
$this->assertEquals(array('metadata' => array('fieldName' => 'metadata')), $this->metadata->fields);
|
||||
$this->metadata->mapField(['fieldName' => 'metadata']);
|
||||
$this->assertEquals(['metadata' => ['fieldName' => 'metadata']], $this->metadata->fields);
|
||||
}
|
||||
|
||||
public function testSkipTransientColumns()
|
||||
{
|
||||
$this->metadata->skipTransientField('metadata');
|
||||
$this->metadata->mapField(array('fieldName' => 'metadata'));
|
||||
$this->metadata->mapField(['fieldName' => 'metadata']);
|
||||
|
||||
$this->assertEquals(array(), $this->metadata->fields);
|
||||
$this->assertEquals([], $this->metadata->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testGetIdentifier()
|
||||
{
|
||||
$identifier = $this->metadata->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->metadata->getReflectionClass();
|
||||
|
||||
$this->assertInstanceOf(ReflectionClass::class, $reflectionClass);
|
||||
$this->assertSame(__CLASS__, $reflectionClass->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isIdentifier
|
||||
*/
|
||||
public function testIsIdentifier()
|
||||
{
|
||||
$this->metadata->mapIdentifier('id');
|
||||
|
||||
$this->assertTrue($this->metadata->isIdentifier('id'));
|
||||
$this->assertFalse($this->metadata->isIdentifier('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hasField
|
||||
*/
|
||||
public function testHasField()
|
||||
{
|
||||
$this->metadata->mapField(['fieldName' => 'foo']);
|
||||
|
||||
$this->assertTrue($this->metadata->hasField('foo'));
|
||||
$this->assertFalse($this->metadata->hasField('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hasAssociation
|
||||
*/
|
||||
public function testHasAssociation()
|
||||
{
|
||||
$this->assertFalse($this->metadata->hasAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isSingleValuedAssociation
|
||||
*/
|
||||
public function testIsSingleValuedAssociation()
|
||||
{
|
||||
$this->assertFalse($this->metadata->isSingleValuedAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isCollectionValuedAssociation
|
||||
*/
|
||||
public function testIsCollectionValuedAssociation()
|
||||
{
|
||||
$this->assertFalse($this->metadata->isCollectionValuedAssociation(sha1(rand())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldNames
|
||||
*/
|
||||
public function testGetFieldNames()
|
||||
{
|
||||
$this->metadata->mapField(['fieldName' => 'foo']);
|
||||
|
||||
$fieldNames = $this->metadata->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->metadata->getIdentifierFieldNames();
|
||||
|
||||
$this->assertInternalType('array', $identifierFieldNames);
|
||||
|
||||
foreach ($identifierFieldNames as $key => $value) {
|
||||
$this->assertInternalType('integer', $key);
|
||||
$this->assertInternalType('string', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isAssociationInverseSide
|
||||
*/
|
||||
public function testIsAssociationInverseSide()
|
||||
{
|
||||
$this->assertFalse($this->metadata->isAssociationInverseSide(sha1(rand())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
250
tests/Doctrine/Tests/KeyValueStore/Query/RangeQueryTest.php
Normal file
250
tests/Doctrine/Tests/KeyValueStore/Query/RangeQueryTest.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?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\Query;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\KeyValueStore\EntityManager;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
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
|
||||
*/
|
||||
public function testWrongExecute()
|
||||
{
|
||||
$this->entityManager
|
||||
->method('unwrap')
|
||||
->willReturn(new DoctrineCacheStorage(new ArrayCache));
|
||||
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
$this->object->execute();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,28 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
@@ -20,19 +42,19 @@ abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testInsertCompositeKey()
|
||||
{
|
||||
if ( ! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped("Composite keys need to be supported for this test to run.");
|
||||
if (! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped('Composite keys need to be supported for this test to run.');
|
||||
}
|
||||
|
||||
$key = array('dist' => 'foo', 'range' => 100);
|
||||
$data = array(
|
||||
'dist' => 'foo',
|
||||
'range' => 100,
|
||||
'name' => 'Test',
|
||||
'value' => 1,
|
||||
'amount' => 200.23,
|
||||
'timestamp' => new \DateTime("2012-03-26 12:12:12")
|
||||
);
|
||||
$key = ['dist' => 'foo', 'range' => 100];
|
||||
$data = [
|
||||
'dist' => 'foo',
|
||||
'range' => 100,
|
||||
'name' => 'Test',
|
||||
'value' => 1,
|
||||
'amount' => 200.23,
|
||||
'timestamp' => new \DateTime('2012-03-26 12:12:12'),
|
||||
];
|
||||
|
||||
$this->mockInsertCompositeKey($key, $data);
|
||||
$this->storage->insert('stdClass', $key, $data);
|
||||
@@ -40,19 +62,19 @@ abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUpdateCompositeKey()
|
||||
{
|
||||
if ( ! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped("Composite keys need to be supported for this test to run.");
|
||||
if (! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped('Composite keys need to be supported for this test to run.');
|
||||
}
|
||||
|
||||
$key = array('dist' => 'foo', 'range' => 100);
|
||||
$data = array(
|
||||
'dist' => 'foo',
|
||||
'range' => 100,
|
||||
'name' => 'Test',
|
||||
'value' => 1,
|
||||
'amount' => 200.23,
|
||||
'timestamp' => new \DateTime("2012-03-26 12:12:12")
|
||||
);
|
||||
$key = ['dist' => 'foo', 'range' => 100];
|
||||
$data = [
|
||||
'dist' => 'foo',
|
||||
'range' => 100,
|
||||
'name' => 'Test',
|
||||
'value' => 1,
|
||||
'amount' => 200.23,
|
||||
'timestamp' => new \DateTime('2012-03-26 12:12:12'),
|
||||
];
|
||||
|
||||
$this->mockUpdateCompositeKey($key, $data);
|
||||
$this->storage->update('stdClass', $key, $data);
|
||||
@@ -60,11 +82,11 @@ abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDeleteCompositeKey()
|
||||
{
|
||||
if ( ! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped("Composite keys need to be supported for this test to run.");
|
||||
if (! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped('Composite keys need to be supported for this test to run.');
|
||||
}
|
||||
|
||||
$key = array('dist' => 'foo', 'range' => 100);
|
||||
$key = ['dist' => 'foo', 'range' => 100];
|
||||
|
||||
$this->mockDeleteCompositeKey($key);
|
||||
$this->storage->delete('stdClass', $key);
|
||||
@@ -72,29 +94,28 @@ abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFindCompositeKey()
|
||||
{
|
||||
if ( ! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped("Composite keys need to be supported for this test to run.");
|
||||
if (! $this->storage->supportsCompositePrimaryKeys()) {
|
||||
$this->markTestSkipped('Composite keys need to be supported for this test to run.');
|
||||
}
|
||||
|
||||
$key = array('dist' => 'foo', 'range' => 100);
|
||||
$key = ['dist' => 'foo', 'range' => 100];
|
||||
|
||||
$this->mockFindCompositeKey($key);
|
||||
$data = $this->storage->find('stdClass', $key);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'dist' => 'foo',
|
||||
'range' => '100',
|
||||
'timestamp' => new \DateTime('2008-09-18 23:46:19', new \DateTimeZone("UTC")),
|
||||
'name' => 'Test',
|
||||
'value' => 23,
|
||||
'amount' => 200.23,
|
||||
'bool' => true,
|
||||
), $data);
|
||||
$this->assertEquals([
|
||||
'dist' => 'foo',
|
||||
'range' => '100',
|
||||
'timestamp' => new \DateTime('2008-09-18 23:46:19', new \DateTimeZone('UTC')),
|
||||
'name' => 'Test',
|
||||
'value' => 23,
|
||||
'amount' => 200.23,
|
||||
'bool' => true,
|
||||
], $data);
|
||||
}
|
||||
|
||||
abstract function mockInsertCompositeKey($key, $data);
|
||||
abstract function mockUpdateCompositeKey($key, $data);
|
||||
abstract function mockDeleteCompositeKey($key);
|
||||
abstract function mockFindCompositeKey($key);
|
||||
abstract public function mockInsertCompositeKey($key, $data);
|
||||
abstract public function mockUpdateCompositeKey($key, $data);
|
||||
abstract public function mockDeleteCompositeKey($key);
|
||||
abstract public function mockFindCompositeKey($key);
|
||||
}
|
||||
|
||||
|
||||
102
tests/Doctrine/Tests/KeyValueStore/Storage/ArrayStorageTest.php
Normal file
102
tests/Doctrine/Tests/KeyValueStore/Storage/ArrayStorageTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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\ArrayStorage;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*/
|
||||
class ArrayStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ArrayStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
$this->storage = new ArrayStorage();
|
||||
}
|
||||
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
$this->assertFalse($this->storage->supportsPartialUpdates());
|
||||
}
|
||||
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->storage->supportsCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->storage->requiresCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodsProvider
|
||||
*/
|
||||
public function testInsert($method)
|
||||
{
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
];
|
||||
|
||||
$this->storage->$method('foo', 'bar', $data);
|
||||
|
||||
$reflector = new ReflectionProperty(ArrayStorage::class, 'data');
|
||||
$reflector->setAccessible(true);
|
||||
|
||||
$storedValue = $reflector->getValue($this->storage);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'foo' => [
|
||||
serialize('bar') => $data,
|
||||
],
|
||||
],
|
||||
$storedValue
|
||||
);
|
||||
|
||||
$this->storage->$method('foo', 'bar', $data);
|
||||
$this->assertCount(1, $storedValue);
|
||||
$this->assertCount(1, $storedValue['foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function methodsProvider()
|
||||
{
|
||||
return [
|
||||
['insert'],
|
||||
['update'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('array', $this->storage->getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?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\CouchDbStorage;
|
||||
|
||||
/**
|
||||
* CouchDb storage testcase
|
||||
*
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*
|
||||
* @covers \Doctrine\KeyValueStore\Storage\CouchDbStorage
|
||||
* @group legacy
|
||||
*/
|
||||
class CouchDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $couchdb;
|
||||
|
||||
/**
|
||||
* @var CouchDbStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$client = $this->getMockBuilder('\Doctrine\CouchDB\HTTP\StreamClient')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->couchdb = $this->getMockBuilder('\Doctrine\CouchDB\CouchDBClient')
|
||||
->setConstructorArgs([
|
||||
$client,
|
||||
'test',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$this->storage = new CouchDbStorage($this->couchdb);
|
||||
}
|
||||
|
||||
public function testSupportsPartialUpdates()
|
||||
{
|
||||
$this->assertFalse($this->storage->supportsPartialUpdates());
|
||||
}
|
||||
|
||||
public function testSupportsCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->storage->supportsCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
public function testRequiresCompositePrimaryKeys()
|
||||
{
|
||||
$this->assertFalse($this->storage->requiresCompositePrimaryKeys());
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = range(0, 10);
|
||||
|
||||
$storedDataset = null;
|
||||
|
||||
$this->couchdb->expects($this->once())
|
||||
->method('putDocument')
|
||||
->will($this->returnCallback(function (array $data, $id) use (&$storedDataset) {
|
||||
$storedDataset = [$id, null];
|
||||
}));
|
||||
|
||||
$storageName = rand();
|
||||
$key = sha1(rand());
|
||||
|
||||
$this->storage->insert($storageName, $key, $data);
|
||||
$this->assertNotNull($storedDataset);
|
||||
|
||||
$this->assertSame([$storageName . '-' . $key, null], $storedDataset);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = range(0, 10);
|
||||
|
||||
$storedDataset = null;
|
||||
|
||||
$this->couchdb->method('putDocument')
|
||||
->will($this->returnCallback(function (array $data, $id) use (&$storedDataset) {
|
||||
$storedDataset = [$id, null];
|
||||
}));
|
||||
|
||||
$storageName = rand();
|
||||
$key = sha1(rand());
|
||||
|
||||
$this->storage->insert($storageName, $key, $data);
|
||||
$this->assertNotNull($storedDataset);
|
||||
|
||||
$this->assertSame([$storageName . '-' . $key, null], $storedDataset);
|
||||
|
||||
$data = range(0, 20);
|
||||
|
||||
$this->storage->insert($storageName, $key, $data);
|
||||
$this->assertNotNull($storedDataset);
|
||||
|
||||
$this->assertSame([$storageName . '-' . $key, null], $storedDataset);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$storedDataset = [
|
||||
'test-foobar' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
],
|
||||
];
|
||||
|
||||
$this->couchdb->expects($this->once())
|
||||
->method('deleteDocument')
|
||||
->will($this->returnCallback(function ($key) use (&$storedDataset) {
|
||||
foreach ($storedDataset as $id => $row) {
|
||||
if ($id === $key) {
|
||||
unset($storedDataset[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
$this->storage->delete('test', 'foobar');
|
||||
|
||||
$this->assertCount(0, $storedDataset);
|
||||
}
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$storedDataset = [
|
||||
'test-foobar' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
],
|
||||
];
|
||||
|
||||
$this->couchdb->expects($this->once())
|
||||
->method('findDocument')
|
||||
->will($this->returnCallback(function ($key) use (&$storedDataset) {
|
||||
if (isset($storedDataset[$key])) {
|
||||
return $storedDataset[$key];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
));
|
||||
|
||||
$data = $this->storage->find('test', 'foobar');
|
||||
|
||||
$this->assertEquals($storedDataset['test-foobar'], $data);
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('couchdb', $this->storage->getName());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,23 @@
|
||||
<?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\CouchbaseStorage;
|
||||
@@ -8,6 +26,9 @@ use Doctrine\KeyValueStore\Storage\CouchbaseStorage;
|
||||
* Couchbase storage testcase
|
||||
*
|
||||
* @author Simon Schick <simonsimcity@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
* @requires extension couchbase
|
||||
*/
|
||||
class CouchbaseStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -23,9 +44,6 @@ class CouchbaseStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('\Couchbase'))
|
||||
$this->markTestSkipped("The PHP extension 'couchbase' is not installed");
|
||||
|
||||
$this->couchbase = $this->getMockBuilder('\Couchbase')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -50,57 +68,57 @@ class CouchbaseStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->couchbase->expects($this->once())
|
||||
->method('add')
|
||||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = array('key' => $key, 'value' => $data);
|
||||
->will($this->returnCallback(function ($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = ['key' => $key, 'value' => $data];
|
||||
}));
|
||||
|
||||
$this->storage->insert('', '1', $data);
|
||||
$this->assertCount(1, $dbDataset);
|
||||
|
||||
$this->assertEquals(array(array('key' => '1', 'value' => $data)), $dbDataset);
|
||||
$this->assertEquals([['key' => '1', 'value' => $data]], $dbDataset);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->couchbase->expects($this->once())
|
||||
->method('replace')
|
||||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) {
|
||||
->will($this->returnCallback(function ($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[$key] = $data;
|
||||
}));
|
||||
|
||||
$this->storage->update('', '1', $data);
|
||||
|
||||
$this->assertEquals(array('1' => $data), $dbDataset);
|
||||
$this->assertEquals(['1' => $data], $dbDataset);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$dataset = array(
|
||||
'foobar' => array(
|
||||
$dataset = [
|
||||
'foobar' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$this->couchbase->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->returnCallback(function($key) use (&$dataset) {
|
||||
->will($this->returnCallback(function ($key) use (&$dataset) {
|
||||
foreach ($dataset as $id => $row) {
|
||||
if ($id === $key) {
|
||||
unset($dataset[$key]);
|
||||
@@ -116,20 +134,20 @@ class CouchbaseStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$dataset = array(
|
||||
'foobar' => array(
|
||||
$dataset = [
|
||||
'foobar' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$this->couchbase->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnCallback(function($key) use (&$dataset) {
|
||||
->will($this->returnCallback(function ($key) use (&$dataset) {
|
||||
if (isset($dataset[$key])) {
|
||||
return $dataset[$key];
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,23 @@
|
||||
<?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\MongoDbStorage;
|
||||
@@ -8,15 +26,14 @@ use Doctrine\KeyValueStore\Storage\MongoDbStorage;
|
||||
* MongoDb storage testcase
|
||||
*
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
*
|
||||
* @group legacy
|
||||
* @requires extension mongo
|
||||
*/
|
||||
class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if ( ! extension_loaded('mongodb')) {
|
||||
$this->markTestSkipped('MongoDB Extension is not installed.');
|
||||
}
|
||||
|
||||
$this->mongo = $this->getMock('\Mongo');
|
||||
|
||||
$this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock();
|
||||
@@ -31,69 +48,69 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
->method('selectCollection')
|
||||
->will($this->returnValue($this->collection));
|
||||
|
||||
$this->storage = new MongoDbStorage($this->mongo, array(
|
||||
$this->storage = new MongoDbStorage($this->mongo, [
|
||||
'collection' => 'test',
|
||||
'database' => 'test'
|
||||
));
|
||||
'database' => 'test',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->collection->expects($this->once())
|
||||
->method('insert')
|
||||
->will($this->returnCallback(function($data) use (&$dbDataset) {
|
||||
->will($this->returnCallback(function ($data) use (&$dbDataset) {
|
||||
$dbDataset[] = $data;
|
||||
}));
|
||||
|
||||
$this->storage->insert('mongodb', '1', $data);
|
||||
$this->assertCount(1, $dbDataset);
|
||||
|
||||
$this->assertEquals(array(array('key' => '1', 'value' => $data)), $dbDataset);
|
||||
$this->assertEquals([['key' => '1', 'value' => $data]], $dbDataset);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->collection->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->returnCallback(function($citeria, $data) use (&$dbDataset) {
|
||||
$dbDataset = array($citeria, $data);
|
||||
->will($this->returnCallback(function ($citeria, $data) use (&$dbDataset) {
|
||||
$dbDataset = [$citeria, $data];
|
||||
}));
|
||||
|
||||
$this->storage->update('mongodb', '1', $data);
|
||||
|
||||
$this->assertEquals(array('key' => '1'), $dbDataset[0]);
|
||||
$this->assertEquals(array('key' => '1', 'value' => $data), $dbDataset[1]);
|
||||
$this->assertEquals(['key' => '1'], $dbDataset[0]);
|
||||
$this->assertEquals(['key' => '1', 'value' => $data], $dbDataset[1]);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$dataset = array(
|
||||
array(
|
||||
'key' => 'foobar',
|
||||
'value' => array(
|
||||
$dataset = [
|
||||
[
|
||||
'key' => 'foobar',
|
||||
'value' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->collection->expects($this->once())
|
||||
->method('remove')
|
||||
->will($this->returnCallback(function($citeria) use (&$dataset) {
|
||||
->will($this->returnCallback(function ($citeria) use (&$dataset) {
|
||||
foreach ($dataset as $key => $row) {
|
||||
if ($row['key'] === $citeria['key']) {
|
||||
unset($dataset[$key]);
|
||||
@@ -109,19 +126,19 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$dataset = array(
|
||||
array(
|
||||
'key' => 'foobar',
|
||||
'value' => array(
|
||||
$dataset = [
|
||||
[
|
||||
'key' => 'foobar',
|
||||
'value' => [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->collection->expects($this->once())
|
||||
->method('findOne')
|
||||
->will($this->returnCallback(function($citeria, $fields) use (&$dataset) {
|
||||
->will($this->returnCallback(function ($citeria, $fields) use (&$dataset) {
|
||||
foreach ($dataset as $key => $row) {
|
||||
if ($row['key'] === $citeria['key']) {
|
||||
return $row;
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
<?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\RedisStorage;
|
||||
|
||||
/**
|
||||
* @author Marcel Araujo <admin@marcelaraujo.me>
|
||||
*
|
||||
* @group legacy
|
||||
* @requires extension redis
|
||||
*/
|
||||
class RedisStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -21,10 +42,6 @@ class RedisStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
if ( ! extension_loaded('redis')) {
|
||||
$this->markTestSkipped('Redis Extension is not installed.');
|
||||
}
|
||||
|
||||
$this->redis = $this->getMockBuilder('\Redis')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -32,7 +49,7 @@ class RedisStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->redis->expects($this->any())
|
||||
->method('connect')
|
||||
->with('127.0.0.1', '6379')
|
||||
->will($this->returnValue(TRUE));
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->storage = new RedisStorage($this->redis);
|
||||
}
|
||||
@@ -54,46 +71,44 @@ class RedisStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe',
|
||||
'title' => 'example book',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->redis->expects($this->once())
|
||||
->method('set')
|
||||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = array('key' => $key, 'value' => $data);
|
||||
->will($this->returnCallback(function ($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = ['key' => $key, 'value' => $data];
|
||||
}));
|
||||
|
||||
$this->storage->insert('redis', '1', $data);
|
||||
|
||||
$this->assertCount(1, $dbDataset);
|
||||
$this->assertEquals(array(array('key' => $this->storage->getKeyName('1'), 'value' => json_encode($data))), $dbDataset);
|
||||
$this->assertEquals([['key' => $this->storage->getKeyName('1'), 'value' => json_encode($data)]], $dbDataset);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
|
||||
$data = array(
|
||||
$data = [
|
||||
'author' => 'John Doe Updated',
|
||||
'title' => 'example book updated',
|
||||
);
|
||||
];
|
||||
|
||||
$dbDataset = array();
|
||||
$dbDataset = [];
|
||||
|
||||
$this->redis->expects($this->once())
|
||||
->method('set')
|
||||
->will($this->returnCallback(function($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = array('key' => $key, 'value' => $data);
|
||||
->will($this->returnCallback(function ($key, $data) use (&$dbDataset) {
|
||||
$dbDataset[] = ['key' => $key, 'value' => $data];
|
||||
}));
|
||||
|
||||
$this->storage->update('redis', '1', $data);
|
||||
|
||||
$this->storage->update('redis', '1', $data);
|
||||
|
||||
$this->assertCount(1, $dbDataset);
|
||||
$this->assertEquals(array(array('key' => $this->storage->getKeyName('1'), 'value' => json_encode($data))), $dbDataset);
|
||||
$this->assertCount(1, $dbDataset);
|
||||
$this->assertEquals([['key' => $this->storage->getKeyName('1'), 'value' => json_encode($data)]], $dbDataset);
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
<?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\RiakStorage;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -25,7 +45,6 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
||||
$this->storage = new RiakStorage($this->riak);
|
||||
}
|
||||
|
||||
@@ -61,17 +80,16 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$objectMock->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
|
||||
$that = $this;
|
||||
$bucket->expects($this->once())
|
||||
->method('newObject')
|
||||
->will($this->returnCallback(function($key, $data) use ($objectMock, $that) {
|
||||
->will($this->returnCallback(function ($key, $data) use ($objectMock, $that) {
|
||||
$that->assertEquals('foobar', $key);
|
||||
$that->assertEquals(array('title' => 'Riak test'), $data);
|
||||
$that->assertEquals(['title' => 'Riak test'], $data);
|
||||
return $objectMock;
|
||||
}));
|
||||
|
||||
$this->storage->insert('riak-test', 'foobar', array('title' => 'Riak test'));
|
||||
$this->storage->insert('riak-test', 'foobar', ['title' => 'Riak test']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
@@ -92,18 +110,17 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
->method('get')
|
||||
->will($this->returnValue($objectMock));
|
||||
|
||||
|
||||
$that = $this;
|
||||
$objectMock->expects($this->once())
|
||||
->method('setData')
|
||||
->will($this->returnCallback(function($data) use ($that) {
|
||||
$that->assertEquals(array('title' => 'Riak cookbook'), $data);
|
||||
->will($this->returnCallback(function ($data) use ($that) {
|
||||
$that->assertEquals(['title' => 'Riak cookbook'], $data);
|
||||
}));
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('store');
|
||||
|
||||
$this->storage->update('riak-test', 'foobar', array('title' => 'Riak cookbook'));
|
||||
$this->storage->update('riak-test', 'foobar', ['title' => 'Riak cookbook']);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
@@ -189,9 +206,9 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$objectMock->expects($this->once())
|
||||
->method('getData')
|
||||
->will($this->returnValue(array('title' => 'Riak Test')));
|
||||
->will($this->returnValue(['title' => 'Riak Test']));
|
||||
|
||||
$this->assertEquals(array('title' => 'Riak Test'), $this->storage->find('riaktest', 'foobar'));
|
||||
$this->assertEquals(['title' => 'Riak Test'], $this->storage->find('riaktest', 'foobar'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,4 +247,4 @@ class RiakStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals('riak', $this->storage->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
<?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\WindowsAzureTable;
|
||||
|
||||
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\SharedKeyLiteAuthorization;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SharedKeyLiteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $auth;
|
||||
@@ -11,31 +32,30 @@ class SharedKeyLiteTest extends \PHPUnit_Framework_TestCase
|
||||
public function setUp()
|
||||
{
|
||||
$this->auth = new SharedKeyLiteAuthorization(
|
||||
"testing",
|
||||
"abcdefg"
|
||||
'testing',
|
||||
'abcdefg'
|
||||
);
|
||||
}
|
||||
|
||||
public function testKeyGeneration1()
|
||||
{
|
||||
$authorization = $this->auth->signRequest('GET', '/', '', '', array(
|
||||
"x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"
|
||||
));
|
||||
$authorization = $this->auth->signRequest('GET', '/', '', '', [
|
||||
'x-ms-date' => 'Wed, 29 Apr 2009 13:12:47 GMT',
|
||||
]);
|
||||
$this->assertEquals(
|
||||
"Authorization: SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=",
|
||||
'Authorization: SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=',
|
||||
$authorization
|
||||
);
|
||||
}
|
||||
|
||||
public function testKeyGeneration2()
|
||||
{
|
||||
$authorization = $this->auth->signRequest('GET', '/test', '', '', array(
|
||||
"x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"
|
||||
));
|
||||
$authorization = $this->auth->signRequest('GET', '/test', '', '', [
|
||||
'x-ms-date' => 'Wed, 29 Apr 2009 13:12:47 GMT',
|
||||
]);
|
||||
$this->assertEquals(
|
||||
"Authorization: SharedKeyLite testing:HJTSiRDtMsQVsFVispSHkcODeFykLO+WEuOepwmh51o=",
|
||||
'Authorization: SharedKeyLite testing:HJTSiRDtMsQVsFVispSHkcODeFykLO+WEuOepwmh51o=',
|
||||
$authorization
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user