@@ -52,33 +52,41 @@ private function _test($method)
52
52
try {
53
53
$ this ->$ method ();
54
54
$ this ->_passed ++;
55
- print " [. ] TEST PASSED: $ method\n" ;
55
+ $ this -> _printLine ( " [+ ] TEST PASSED: $ method" ) ;
56
56
} catch (Exception $ e ) {
57
57
$ 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 );
62
61
}
63
62
}
64
63
65
64
private function _summary ()
66
65
{
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. " ) ;
69
68
} else {
70
69
$ 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 );
72
74
}
73
75
}
74
76
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
+
75
83
public function run ()
76
84
{
77
85
print ("Starting Unit Tests \n--- \n" );
78
86
79
87
$ this ->_test ('testIsAlive ' );
80
- $ this ->_test ('testNotHasKey ' );
81
- $ this ->_test ('testHasKey ' );
88
+ $ this ->_test ('testNotHasKey ' );
89
+ $ this ->_test ('testHasKey ' );
82
90
$ this ->_test ('testStoreAndGet ' );
83
91
$ this ->_test ('testStoreAndGetWithoutKey ' );
84
92
$ this ->_test ('testBinaryStoreAndGet ' );
@@ -470,32 +478,38 @@ public function testLinkWalking()
470
478
471
479
public function testSearchIntegration ()
472
480
{
473
- # Create some objects to search across...
481
+ // bucket to use
482
+ $ bucket_name = 'searchbucket ' ;
483
+
484
+ // spin up client & grab bucket
474
485
$ client = new Riak (self ::HOST , self ::PORT );
475
- $ bucket = $ client ->bucket (" searchbucket " );
486
+ $ bucket = $ client ->bucket ($ bucket_name );
476
487
488
+ // turn on search for this bucket
477
489
$ bucket ->setProperty ('search ' , true );
478
490
491
+ // create searchable objects
479
492
$ bucket ->newObject ("one " , array ("foo " => "one " , "bar " => "red " ))->store ();
480
493
$ bucket ->newObject ("two " , array ("foo " => "two " , "bar " => "green " ))->store ();
481
494
$ bucket ->newObject ("three " , array ("foo " => "three " , "bar " => "blue " ))->store ();
482
495
$ bucket ->newObject ("four " , array ("foo " => "four " , "bar " => "orange " ))->store ();
483
496
$ bucket ->newObject ("five " , array ("foo " => "five " , "bar " => "yellow " ))->store ();
484
497
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 ();
487
500
if (count ($ results ) == 0 ) {
488
501
print "\n\nNot running tests \"testSearchIntegration() \". \n" ;
489
502
print "Please ensure that you have installed the Riak Search hook on bucket \"searchbucket \" by running \"bin/search-cmd install searchbucket \". \n\n" ;
490
503
return ;
491
504
}
492
- $ this ->_assert (count ($ results ) == 2 );
505
+ $ this ->_assert (count ($ results ) == 2 , " Search integration result = " . count ( $ results ) . ' but should be 2. ' );
493
506
507
+ // search test 2
494
508
$ results = $ client ->search (
495
509
"searchbucket " ,
496
510
"(foo:one OR foo:two OR foo:three OR foo:four) AND (NOT bar:green) "
497
511
)->run ();
498
- $ this ->_assert (count ($ results ) == 3 );
512
+ $ this ->_assert (count ($ results ) == 3 , " Search integration result = " . count ( $ results ) . ' but should be 3. ' );
499
513
}
500
514
501
515
public function testSecondaryIndexes ()
@@ -667,10 +681,10 @@ public function testHasKey()
667
681
$ this ->_assert ($ exists );
668
682
}
669
683
670
- private function _assert ($ bool )
684
+ private function _assert ($ bool, $ msg = '' )
671
685
{
672
686
if (!$ bool ) {
673
- throw new Exception (" Test failed. " );
687
+ throw new Exception ($ msg );
674
688
}
675
689
}
676
690
}
0 commit comments