From 359b60aa922fc0681233ba5e66c08b1bf68e7f33 Mon Sep 17 00:00:00 2001 From: Christopher Mancini Date: Thu, 7 May 2015 15:41:02 -0400 Subject: [PATCH 1/5] update composer.json, add assertion to check for deleted objects tombstone context, updated docblock desc. --- composer.json | 16 ++++++++++++++-- src/Riak/Command/Bucket/Delete.php | 2 +- src/Riak/Command/Bucket/Store.php | 2 +- src/Riak/Command/Builder/UpdateMap.php | 5 +++++ tests/functional/ObjectOperationsTest.php | 8 +++----- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 583ef73..699a67b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "basho/riak", "description": "Official Riak client for PHP", + "type": "library", "keywords": [ "basho", "riak", @@ -17,8 +18,16 @@ "license": "Apache-2.0", "authors": [ { - "name": "Riak Team & Contributors", - "homepage": "https://github.com/basho/riak-php-client/contributors" + "name": "Christopher Mancini", + "email": "cmancini@basho.com", + "homepage": "https://github.com/christophermancini", + "role": "Lead Developer" + }, + { + "name": "Alex Moore", + "email": "amoore@basho.com", + "homepage": "https://github.com/alexmoore", + "role": "Developer" } ], "autoload": { @@ -27,6 +36,9 @@ "autoload-dev": { "psr-4": {"Basho\\Tests\\": "tests/"} }, + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues" + }, "repositories": [ { "type": "package", diff --git a/src/Riak/Command/Bucket/Delete.php b/src/Riak/Command/Bucket/Delete.php index b09b666..5c7723a 100644 --- a/src/Riak/Command/Bucket/Delete.php +++ b/src/Riak/Command/Bucket/Delete.php @@ -21,7 +21,7 @@ use Basho\Riak\CommandInterface; /** - * Used to remove an object from Riak + * Used to remove a bucket property from a Riak bucket * * @author Christopher Mancini */ diff --git a/src/Riak/Command/Bucket/Store.php b/src/Riak/Command/Bucket/Store.php index 2817351..899853c 100644 --- a/src/Riak/Command/Bucket/Store.php +++ b/src/Riak/Command/Bucket/Store.php @@ -21,7 +21,7 @@ use Basho\Riak\CommandInterface; /** - * Riak key value object store + * Used to set a bucket property on a bucket * * @author Christopher Mancini */ diff --git a/src/Riak/Command/Builder/UpdateMap.php b/src/Riak/Command/Builder/UpdateMap.php index e558808..7253d62 100644 --- a/src/Riak/Command/Builder/UpdateMap.php +++ b/src/Riak/Command/Builder/UpdateMap.php @@ -221,6 +221,11 @@ public function validate() throw new Exception('At least one add, remove, or update operation needs to be defined.'); } + if ($count_remove) { + $this->required('Location'); + $this->required('Context'); + } + // if we are performing a remove on a nested set, Location and context are required if ($count_sets) { foreach ($this->sets as $set) { diff --git a/tests/functional/ObjectOperationsTest.php b/tests/functional/ObjectOperationsTest.php index 663da75..c83be31 100644 --- a/tests/functional/ObjectOperationsTest.php +++ b/tests/functional/ObjectOperationsTest.php @@ -33,11 +33,6 @@ class ObjectOperationsTest extends TestCase */ private static $object = NULL; - /** - * @var array|null - */ - private static $vclock = NULL; - public static function setUpBeforeClass() { // make completely random key based on time @@ -180,6 +175,9 @@ public function testFetchDeleted($riak) $response = $command->execute(); $this->assertEquals('404', $response->getStatusCode()); + + // deleted key's still leave behind a tombstone with their causal context, aka vclock + $this->assertNotEmpty($response->getVclock()); } /** From 6f64a324f6544b8df5077c303b9cadf29a4fffa1 Mon Sep 17 00:00:00 2001 From: Christopher Mancini Date: Tue, 19 May 2015 09:23:23 -0400 Subject: [PATCH 2/5] Add default value for returnTerms so explicitly defining true in the method call is not needed --- src/Riak/Command/Builder/IndexTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Riak/Command/Builder/IndexTrait.php b/src/Riak/Command/Builder/IndexTrait.php index f12e21c..78d80d5 100644 --- a/src/Riak/Command/Builder/IndexTrait.php +++ b/src/Riak/Command/Builder/IndexTrait.php @@ -277,7 +277,7 @@ public function withMaxResults($maxResults) * * @return $this */ - public function withReturnTerms($returnTerms) + public function withReturnTerms($returnTerms = true) { $this->returnTerms = $returnTerms; return $this; From 5b84cbe6d90fa77cad4c31c6e2733c9e63c684e2 Mon Sep 17 00:00:00 2001 From: Christopher Mancini Date: Tue, 19 May 2015 11:37:24 -0400 Subject: [PATCH 3/5] adjust this to handle some of PHPs obscurity with type evaluation. just force an int index to be type int, not "string-int". --- src/Riak/Object.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Riak/Object.php b/src/Riak/Object.php index 3f26d74..982500e 100644 --- a/src/Riak/Object.php +++ b/src/Riak/Object.php @@ -99,7 +99,6 @@ public function addValueToIndex($indexName, $value) private function validateIndexNameAndValue($indexName, $value) { - $type = gettype($value); $isIntIndex = SecondaryIndexHeaderTranslator::isIntIndex($indexName); $isStringIndex = SecondaryIndexHeaderTranslator::isStringIndex($indexName); @@ -108,14 +107,14 @@ private function validateIndexNameAndValue($indexName, $value) "'index. Expecting '*_int' for an integer index, or '*_bin' for a string index."); } - if ($isIntIndex && $type != 'integer') { + if ($isIntIndex && !is_int($value)) { throw new \InvalidArgumentException("Invalid type for '" . $indexName . - "'index. Expecting 'integer', value was '" . $type . "''"); + "'index. Expecting 'integer', value was '" . gettype($value) . "''"); } - if ($isStringIndex && $type != 'string') { + if ($isStringIndex && !is_scalar($value)) { throw new \InvalidArgumentException("Invalid type for '" . $indexName . - "'index. Expecting 'string', value was '" . $type . "''"); + "'index. Expecting 'string', value was '" . gettype($value) . "''"); } } From 3f04d12855db2c4be6eaeab5f81d000e92040310 Mon Sep 17 00:00:00 2001 From: Christopher Mancini Date: Tue, 19 May 2015 11:54:02 -0400 Subject: [PATCH 4/5] Add early exit by using is_scalar, swap is_scalar with is_int for string check to keep it consistent to explicit type requirements --- src/Riak/Object.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Riak/Object.php b/src/Riak/Object.php index 982500e..9c20b30 100644 --- a/src/Riak/Object.php +++ b/src/Riak/Object.php @@ -99,6 +99,11 @@ public function addValueToIndex($indexName, $value) private function validateIndexNameAndValue($indexName, $value) { + if (!is_scalar($value)) { + throw new \InvalidArgumentException("Invalid index type for '" . $indexName . + "'index. Expecting '*_int' for an integer index, or '*_bin' for a string index."); + } + $isIntIndex = SecondaryIndexHeaderTranslator::isIntIndex($indexName); $isStringIndex = SecondaryIndexHeaderTranslator::isStringIndex($indexName); @@ -112,7 +117,7 @@ private function validateIndexNameAndValue($indexName, $value) "'index. Expecting 'integer', value was '" . gettype($value) . "''"); } - if ($isStringIndex && !is_scalar($value)) { + if ($isStringIndex && is_int($value)) { throw new \InvalidArgumentException("Invalid type for '" . $indexName . "'index. Expecting 'string', value was '" . gettype($value) . "''"); } From dca55fd42d85cb63e4c6bcf59e7143ac756c766f Mon Sep 17 00:00:00 2001 From: Christopher Mancini Date: Thu, 21 May 2015 11:54:42 -0400 Subject: [PATCH 5/5] use is_string instead to reduce chances for unexpected behavior. --- src/Riak/Object.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Riak/Object.php b/src/Riak/Object.php index 9c20b30..db06d57 100644 --- a/src/Riak/Object.php +++ b/src/Riak/Object.php @@ -117,7 +117,7 @@ private function validateIndexNameAndValue($indexName, $value) "'index. Expecting 'integer', value was '" . gettype($value) . "''"); } - if ($isStringIndex && is_int($value)) { + if ($isStringIndex && !is_string($value)) { throw new \InvalidArgumentException("Invalid type for '" . $indexName . "'index. Expecting 'string', value was '" . gettype($value) . "''"); }