Skip to content

Commit

Permalink
Merge pull request #84 from basho/1.4.x
Browse files Browse the repository at this point in the history
Fix 5.3 incompatibility & improve test suite
  • Loading branch information
christophermancini committed Dec 30, 2014
2 parents 97aa569 + a83f6f8 commit 194db7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
language: "php"

script: "php -q tests/integration/test.php"

install:
- composer install
notifications:
webhooks: http://basho-engbot.herokuapp.com/travis?key=8d594c660ec46f616e37e24fd941c0ea1fc67963
email: "[email protected]"
irc: "irc.freenode.org#riak-php-client"

email: "[email protected]"
php:
- "5.3"
- "5.4"

services:
- "riak"
script: "php -q tests/integration/test.php"
2 changes: 1 addition & 1 deletion src/Basho/Riak/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function store($w = null, $dw = null, $returnbody = 'true')
$w = $this->bucket->getW($w);
$dw = $this->bucket->getDW($w);

$status_codes = [200, 201, 300];
$status_codes = array(200, 201, 300);
$method = 'POST';

# Construct the URL...
Expand Down
50 changes: 32 additions & 18 deletions tests/integration/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,41 @@ private function _test($method)
try {
$this->$method();
$this->_passed++;
print " [.] TEST PASSED: $method\n";
$this->_printLine(" [+] TEST PASSED: $method");
} catch (Exception $e) {
$this->_failed++;
print " [X] TEST FAILED: $method\n";
if (self::VERBOSE) {
throw $e;
}
$this->_printLine("[-] TEST FAILED: $method.", false);
$this->_printLine("{$e->getMessage()}", false);
$this->_printLine("{$e->getTraceAsString()}\n", false);
}
}

private function _summary()
{
if ($this->_failed == 0) {
print "\nSUCCESS: Passed all $this->_passed tests.\n";
if (!$this->_failed) {
$this->_printLine("\nSUCCESS: Passed all $this->_passed tests.");
} else {
$test_total = $this->_passed + $this->_failed;
print "\nFAILURE: Failed $this->_failed of $this->_passed tests!";
$this->_printLine("\nFAILURE: Failed $this->_failed of $this->_passed tests!", false);

// exit with a 1 to signal to Travis CI that the tests failed
exit(1);
}
}

public function _printLine($msg, $pass = true)
{
$color = $pass ? '0;32' : '0;31';
echo "\033[{$color}m{$msg}\033[0m\n";
}

public function run()
{
print("Starting Unit Tests\n---\n");

$this->_test('testIsAlive');
$this->_test('testNotHasKey');
$this->_test('testHasKey');
$this->_test('testNotHasKey');
$this->_test('testHasKey');
$this->_test('testStoreAndGet');
$this->_test('testStoreAndGetWithoutKey');
$this->_test('testBinaryStoreAndGet');
Expand Down Expand Up @@ -470,32 +478,38 @@ public function testLinkWalking()

public function testSearchIntegration()
{
# Create some objects to search across...
// bucket to use
$bucket_name = 'searchbucket';

// spin up client & grab bucket
$client = new Riak(self::HOST, self::PORT);
$bucket = $client->bucket("searchbucket");
$bucket = $client->bucket($bucket_name);

// turn on search for this bucket
$bucket->setProperty('search', true);

// create searchable objects
$bucket->newObject("one", array("foo" => "one", "bar" => "red"))->store();
$bucket->newObject("two", array("foo" => "two", "bar" => "green"))->store();
$bucket->newObject("three", array("foo" => "three", "bar" => "blue"))->store();
$bucket->newObject("four", array("foo" => "four", "bar" => "orange"))->store();
$bucket->newObject("five", array("foo" => "five", "bar" => "yellow"))->store();

# Run some operations...
$results = $client->search("searchbucket", "foo:one OR foo:two")->run();
// search test 1
$results = $client->search($bucket_name, "foo:one OR foo:two")->run();
if (count($results) == 0) {
print "\n\nNot running tests \"testSearchIntegration()\".\n";
print "Please ensure that you have installed the Riak Search hook on bucket \"searchbucket\" by running \"bin/search-cmd install searchbucket\".\n\n";
return;
}
$this->_assert(count($results) == 2);
$this->_assert(count($results) == 2, "Search integration result = " . count($results) . ' but should be 2.');

// search test 2
$results = $client->search(
"searchbucket",
"(foo:one OR foo:two OR foo:three OR foo:four) AND (NOT bar:green)"
)->run();
$this->_assert(count($results) == 3);
$this->_assert(count($results) == 3, "Search integration result = " . count($results) . ' but should be 3.');
}

public function testSecondaryIndexes()
Expand Down Expand Up @@ -667,10 +681,10 @@ public function testHasKey()
$this->_assert($exists);
}

private function _assert($bool)
private function _assert($bool, $msg = '')
{
if (!$bool) {
throw new Exception("Test failed.");
throw new Exception($msg);
}
}
}

0 comments on commit 194db7b

Please sign in to comment.