diff --git a/.travis.yml b/.travis.yml index e11d306..9ade01b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: "eng@basho.com" - irc: "irc.freenode.org#riak-php-client" - + email: "clients@basho.com" php: - "5.3" - "5.4" - services: - "riak" +script: "php -q tests/integration/test.php" \ No newline at end of file diff --git a/src/Basho/Riak/Object.php b/src/Basho/Riak/Object.php index 7562b93..0ba6db8 100644 --- a/src/Basho/Riak/Object.php +++ b/src/Basho/Riak/Object.php @@ -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... diff --git a/tests/integration/TestSuite.php b/tests/integration/TestSuite.php index eb19e15..bc9ef48 100755 --- a/tests/integration/TestSuite.php +++ b/tests/integration/TestSuite.php @@ -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'); @@ -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() @@ -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); } } }