Permalink
Browse files

Simplify response header logic, update unit tests.

  • Loading branch information...
Rusty Klophaus
Rusty Klophaus committed Mar 9, 2010
1 parent 7384c2c commit 8d560e571dfbdff83fef43a07259e93eee6643af
Showing with 29 additions and 31 deletions.
  1. +15 −13 client_lib/php/riak.php
  2. +14 −18 client_lib/php/unit_tests.php
View
@@ -334,8 +334,9 @@ function run($timeout=NULL) {
$query = array();
for ($i = 0; $i < $num_phases; $i++) {
$phase = $this->phases[$i];
- if ($i == ($num_phases - 1) && !$keep_flag)
+ if ($i == ($num_phases - 1) && !$keep_flag)
$phase->keep = TRUE;
+ if ($phase->keep) $keep_flag = TRUE;
$query[] = $phase->to_array();
}
@@ -885,7 +886,7 @@ function exists() {
* @return string
*/
function getContentType() {
- return $this->headers['content_type'];
+ return $this->headers['content-type'];
}
/**
@@ -894,7 +895,7 @@ function getContentType() {
* @return $this
*/
function setContentType($content_type) {
- $this->headers['content_type'] = $content_type;
+ $this->headers['content-type'] = $content_type;
return $this;
}
@@ -1066,8 +1067,8 @@ private function clear() {
* @return string
*/
private function vclock() {
- if (array_key_exists('X-Riak-Vclock', $this->headers)) {
- return $this->headers['X-Riak-Vclock'];
+ if (array_key_exists('x-riak-vclock', $this->headers)) {
+ return $this->headers['x-riak-vclock'];
} else {
return NULL;
}
@@ -1114,8 +1115,8 @@ function populate($response, $expected_statuses) {
$this->exists = TRUE;
# Parse the link header...
- if (array_key_exists("Link", $this->headers)) {
- $this->populateLinks($this->headers["Link"]);
+ if (array_key_exists("link", $this->headers)) {
+ $this->populateLinks($this->headers["link"]);
}
# If 300 (Siblings), then load the first sibling, and
@@ -1363,17 +1364,18 @@ public static function httpRequest($method, $url, $request_headers = array(), $o
try {
# Run the request.
curl_exec($ch);
- $curl_headers = curl_getinfo($ch);
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
- # Merge the headers...
+ # Get the headers...
$parsed_headers = RiakUtils::parseHttpHeaders($response_headers_io->contents());
- $response_headers = array_merge($curl_headers, $parsed_headers);
+ $response_headers = array("http_code"=>$http_code);
+ foreach ($parsed_headers as $key=>$value) {
+ $response_headers[strtolower($key)] = $value;
+ }
- # Pull out the body...
+ # Get the body...
$response_body = $response_body_io->contents();
- $array = array();
- $success = mb_parse_str($response_body, $array);
# Return a new RiakResponse object.
return array($response_headers, $response_body);
@@ -70,7 +70,7 @@ function testBinaryStoreAndGet() {
$obj = $bucket->newObject('foo2', $data);
$obj->store();
$obj = $bucket->getBinary('foo2');
- assert($data == json_decode($obj->getData()));
+ test_assert($data == json_decode($obj->getData()));
}
function testMissingObject() {
@@ -138,14 +138,14 @@ function testSiblings() {
# Test getSibling()/getSiblings()...
$siblings = $obj->getSiblings();
$obj3 = $obj->getSibling(3);
- assert($siblings[3]->getData() == $obj3->getData());
+ test_assert($siblings[3]->getData() == $obj3->getData());
# Resolve the conflict, and then do a get...
$obj3 = $obj->getSibling(3);
$obj3->store();
$obj->reload();
- assert($obj->getData() == $obj3->getData());
+ test_assert($obj->getData() == $obj3->getData());
# Clean up for next test...
$obj->delete();
@@ -162,7 +162,7 @@ function testJavascriptSourceMap() {
add("bucket", "foo")->
map("function (v) { return [JSON.parse(v.values[0].data)]; }") ->
run();
- assert($result == array(2));
+ test_assert($result == array(2));
}
function testJavascriptNamedMap() {
@@ -176,7 +176,7 @@ function testJavascriptNamedMap() {
add("bucket", "foo")->
map("Riak.mapValuesJson") ->
run();
- assert($result == array(2));
+ test_assert($result == array(2));
}
function testJavascriptSourceMapReduce() {
@@ -195,7 +195,7 @@ function testJavascriptSourceMapReduce() {
map("function (v) { return [1]; }") ->
reduce("function (v) { return v.length; }")->
run();
- assert($result == 3);
+ test_assert($result == 3);
}
function testJavascriptNamedMapReduce() {
@@ -214,7 +214,7 @@ function testJavascriptNamedMapReduce() {
map("Riak.mapValuesJson") ->
reduce("Riak.reduceSum")->
run();
- assert($result == array(9));
+ test_assert($result == array(9));
}
function testJavascriptBucketMapReduce() {
@@ -231,7 +231,7 @@ function testJavascriptBucketMapReduce() {
map("Riak.mapValuesJson") ->
reduce("Riak.reduceSum")->
run();
- assert($result == array(9));
+ test_assert($result == array(9));
}
function testJavascriptArgMapReduce() {
@@ -250,7 +250,7 @@ function testJavascriptArgMapReduce() {
map("function(v, arg) { return [arg]; }")->
reduce("Riak.reduceSum")->
run();
- assert($result == array(10));
+ test_assert($result == array(10));
}
function testErlangMapReduce() {
@@ -269,8 +269,7 @@ function testErlangMapReduce() {
map(array("riak_mapreduce", "map_object_value")) ->
reduce(array("riak_mapreduce", "reduce_set_union"))->
run();
-
- assert(count($result) == 2);
+ test_assert(count($result) == 2);
}
function testMapReduceFromObject() {
@@ -281,7 +280,7 @@ function testMapReduceFromObject() {
$obj = $bucket->get("foo");
$result = $obj->map("Riak.mapValuesJson")->run();
- assert($result = array(2));
+ test_assert($result = array(2));
}
@@ -297,7 +296,7 @@ function testStoreAndGetLinks() {
$obj = $bucket->get("foo");
$links = $obj->getLinks();
- assert(count($links) == 3);
+ test_assert(count($links) == 3);
}
function testLinkWalking() {
@@ -312,17 +311,14 @@ function testLinkWalking() {
$obj = $bucket->get("foo");
$results = $obj->link("bucket")->run();
- assert(count($results) == 3);
+ test_assert(count($results) == 3);
$results = $obj->link("bucket", "tag")->run();
- assert(count($results) == 1);
+ test_assert(count($results) == 1);
}
/* BEGIN UNIT TEST FRAMEWORK */
-
-assert_options(ASSERT_ACTIVE, true);
-assert_options(ASSERT_BAIL, true);
$test_pass = 0; $test_fail = 0;
function test($method) {

0 comments on commit 8d560e5

Please sign in to comment.