Skip to content

Commit 194db7b

Browse files
Merge pull request #84 from basho/1.4.x
Fix 5.3 incompatibility & improve test suite
2 parents 97aa569 + a83f6f8 commit 194db7b

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

.travis.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
language: "php"
2-
3-
script: "php -q tests/integration/test.php"
4-
2+
install:
3+
- composer install
54
notifications:
65
webhooks: http://basho-engbot.herokuapp.com/travis?key=8d594c660ec46f616e37e24fd941c0ea1fc67963
7-
8-
irc: "irc.freenode.org#riak-php-client"
9-
6+
107
php:
118
- "5.3"
129
- "5.4"
13-
1410
services:
1511
- "riak"
12+
script: "php -q tests/integration/test.php"

src/Basho/Riak/Object.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public function store($w = null, $dw = null, $returnbody = 'true')
602602
$w = $this->bucket->getW($w);
603603
$dw = $this->bucket->getDW($w);
604604

605-
$status_codes = [200, 201, 300];
605+
$status_codes = array(200, 201, 300);
606606
$method = 'POST';
607607

608608
# Construct the URL...

tests/integration/TestSuite.php

+32-18
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,41 @@ private function _test($method)
5252
try {
5353
$this->$method();
5454
$this->_passed++;
55-
print " [.] TEST PASSED: $method\n";
55+
$this->_printLine(" [+] TEST PASSED: $method");
5656
} catch (Exception $e) {
5757
$this->_failed++;
58-
print " [X] TEST FAILED: $method\n";
59-
if (self::VERBOSE) {
60-
throw $e;
61-
}
58+
$this->_printLine("[-] TEST FAILED: $method.", false);
59+
$this->_printLine("{$e->getMessage()}", false);
60+
$this->_printLine("{$e->getTraceAsString()}\n", false);
6261
}
6362
}
6463

6564
private function _summary()
6665
{
67-
if ($this->_failed == 0) {
68-
print "\nSUCCESS: Passed all $this->_passed tests.\n";
66+
if (!$this->_failed) {
67+
$this->_printLine("\nSUCCESS: Passed all $this->_passed tests.");
6968
} else {
7069
$test_total = $this->_passed + $this->_failed;
71-
print "\nFAILURE: Failed $this->_failed of $this->_passed tests!";
70+
$this->_printLine("\nFAILURE: Failed $this->_failed of $this->_passed tests!", false);
71+
72+
// exit with a 1 to signal to Travis CI that the tests failed
73+
exit(1);
7274
}
7375
}
7476

77+
public function _printLine($msg, $pass = true)
78+
{
79+
$color = $pass ? '0;32' : '0;31';
80+
echo "\033[{$color}m{$msg}\033[0m\n";
81+
}
82+
7583
public function run()
7684
{
7785
print("Starting Unit Tests\n---\n");
7886

7987
$this->_test('testIsAlive');
80-
$this->_test('testNotHasKey');
81-
$this->_test('testHasKey');
88+
$this->_test('testNotHasKey');
89+
$this->_test('testHasKey');
8290
$this->_test('testStoreAndGet');
8391
$this->_test('testStoreAndGetWithoutKey');
8492
$this->_test('testBinaryStoreAndGet');
@@ -470,32 +478,38 @@ public function testLinkWalking()
470478

471479
public function testSearchIntegration()
472480
{
473-
# Create some objects to search across...
481+
// bucket to use
482+
$bucket_name = 'searchbucket';
483+
484+
// spin up client & grab bucket
474485
$client = new Riak(self::HOST, self::PORT);
475-
$bucket = $client->bucket("searchbucket");
486+
$bucket = $client->bucket($bucket_name);
476487

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

491+
// create searchable objects
479492
$bucket->newObject("one", array("foo" => "one", "bar" => "red"))->store();
480493
$bucket->newObject("two", array("foo" => "two", "bar" => "green"))->store();
481494
$bucket->newObject("three", array("foo" => "three", "bar" => "blue"))->store();
482495
$bucket->newObject("four", array("foo" => "four", "bar" => "orange"))->store();
483496
$bucket->newObject("five", array("foo" => "five", "bar" => "yellow"))->store();
484497

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

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

501515
public function testSecondaryIndexes()
@@ -667,10 +681,10 @@ public function testHasKey()
667681
$this->_assert($exists);
668682
}
669683

670-
private function _assert($bool)
684+
private function _assert($bool, $msg = '')
671685
{
672686
if (!$bool) {
673-
throw new Exception("Test failed.");
687+
throw new Exception($msg);
674688
}
675689
}
676690
}

0 commit comments

Comments
 (0)