@@ -37,6 +37,9 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
37
37
/** @var Elasticsearch\client */
38
38
private $ client ;
39
39
40
+ /** @var string */
41
+ private $ log = "" ;
42
+
40
43
/** @var string */
41
44
public static $ esVersion ;
42
45
@@ -55,9 +58,13 @@ public static function getHostEnvVar()
55
58
}
56
59
}
57
60
61
+ private function log ($ text )
62
+ {
63
+ $ this ->log .= $ text ;
64
+ }
65
+
58
66
public static function setUpBeforeClass ()
59
67
{
60
- ob_implicit_flush ();
61
68
$ host = YamlRunnerTest::getHostEnvVar ();
62
69
echo "Test Host: $ host \n" ;
63
70
@@ -85,11 +92,12 @@ public function setUp()
85
92
//$params['logLevel'] = \Psr\Log\LogLevel::DEBUG;
86
93
87
94
$ this ->client = Elasticsearch \ClientBuilder::create ()->setHosts ($ params ['hosts ' ])->build ();
95
+ $ this ->log = "" ;
88
96
}
89
97
90
98
private function clearCluster ()
91
99
{
92
- echo "\n>>>CLEARING<<< \n" ;
100
+ $ this -> log ( "\n>>>CLEARING<<< \n" ) ;
93
101
$ host = YamlRunnerTest::getHostEnvVar ();
94
102
$ ch = curl_init ($ host ."/* " );
95
103
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
@@ -119,19 +127,17 @@ private function clearCluster()
119
127
120
128
private function assertTruthy ($ value , $ settings )
121
129
{
122
- echo "\n |assertTruthy( $ settings): " .json_encode ($ value )."\n" ;
123
- ob_flush ();
130
+ $ this ->log ("\n |assertTruthy( $ settings): " .json_encode ($ value )."\n" );
124
131
if (isset ($ value ) === false || $ value === 0 || $ value === false || $ value === null || $ value === '' ) {
125
- $ this ->fail ("Value is not truthy: " .print_r ($ value , true ));
132
+ $ this ->fail ("Value is not truthy: " .print_r ($ value , true ) . "\n" . $ this -> log );
126
133
}
127
134
}
128
135
129
136
private function assertFalsey ($ value , $ settings )
130
137
{
131
- echo "\n |assertFalsey( $ settings): " .json_encode ($ value )."\n" ;
132
- ob_flush ();
138
+ $ this ->log ("\n |assertFalsey( $ settings): " .json_encode ($ value )."\n" );
133
139
if (!(isset ($ value ) === false || $ value === 0 || $ value === false || $ value === null || $ value === '' || count ($ value ) === 0 )) {
134
- $ this ->fail ("Value is not falsey: " .print_r ($ value , true ));
140
+ $ this ->fail ("Value is not falsey: " .print_r ($ value , true ) . "\n" . $ this -> log );
135
141
}
136
142
}
137
143
@@ -143,11 +149,10 @@ private function assertRegex($pattern, $actual)
143
149
$ pattern = substr ($ pattern , 1 , strlen ($ pattern )-2 );
144
150
$ pattern = str_replace ('/ ' , '\/ ' , $ pattern );
145
151
$ pattern = "/ $ pattern/mx " ;
146
- echo "\n |> actual: $ actual \n" ;
147
- echo "\n |> pattern: $ pattern \n" ;
148
- ob_flush ();
152
+ $ this ->log ("\n |> actual: $ actual \n" );
153
+ $ this ->log ("\n |> pattern: $ pattern \n" );
149
154
$ result = preg_match ($ pattern , $ actual , $ matches );
150
- $ this ->assertEquals (1 , $ result );
155
+ $ this ->assertEquals (1 , $ result, $ this -> log );
151
156
}
152
157
153
158
private function waitForYellow ()
@@ -167,8 +172,8 @@ private function waitForYellow()
167
172
++$ counter ;
168
173
169
174
if ($ counter > 10 ) {
170
- echo "Aborting test due to failure in clearing cluster. \n" ;
171
- print_r ($ response );
175
+ $ this -> log ( "Aborting test due to failure in clearing cluster. \n" ) ;
176
+ $ this -> log ( print_r ($ response, true ) );
172
177
exit ;
173
178
}
174
179
}
@@ -226,9 +231,8 @@ public function testYaml()
226
231
foreach ($ files as $ testFile ) {
227
232
$ counter = YamlRunnerTest::$ testCounter ;
228
233
229
- echo "-------------------------------------------------------------------------- \n" ;
230
- echo "# $ counter : $ testFile \n" ;
231
- ob_flush ();
234
+ $ this ->log ("-------------------------------------------------------------------------- \n" );
235
+ $ this ->log ("# $ counter : $ testFile \n" );
232
236
YamlRunnerTest::$ testCounter += 1 ;
233
237
234
238
if ($ this ->skipTest ($ testFile ) === true ) {
@@ -267,8 +271,7 @@ public function testYaml()
267
271
268
272
foreach ($ yamlDocs as $ doc ) {
269
273
$ ts = date ('c ' );
270
- echo " " .key ($ doc ['values ' ])." [ $ ts] - Future: false \n" ;
271
- ob_flush ();
274
+ $ this ->log (" " .key ($ doc ['values ' ])." [ $ ts] - Future: false \n" );
272
275
273
276
$ this ->clearCluster ();
274
277
@@ -281,8 +284,7 @@ public function testYaml()
281
284
}
282
285
$ this ->executeTestCase ($ doc ['values ' ], $ testFile , false );
283
286
284
- echo "Success \n\n" ;
285
- ob_flush ();
287
+ $ this ->log ("Success \n\n" );
286
288
}
287
289
}
288
290
}
@@ -298,8 +300,7 @@ public function testFutureModeYaml()
298
300
$ files = func_get_args ();
299
301
300
302
foreach ($ files as $ testFile ) {
301
- echo "$ testFile \n" ;
302
- ob_flush ();
303
+ $ this ->log ("$ testFile \n" );
303
304
304
305
if ($ this ->skipTest ($ testFile ) === true ) {
305
306
$ this ->markTestSkipped ('Skipped due to skip-list ' );
@@ -337,14 +338,12 @@ public function testFutureModeYaml()
337
338
338
339
foreach ($ yamlDocs as $ doc ) {
339
340
$ ts = date ('c ' );
340
- echo " " .key ($ doc ['values ' ])." [ $ ts] - Future: true \n" ;
341
+ $ this -> log ( " " .key ($ doc ['values ' ])." [ $ ts] - Future: true \n" ) ;
341
342
342
343
if ($ containsExist !== false ) {
343
344
$ this ->markTestSkipped ('Test contains `exist`, not easily tested in async. Skipping. ' );
344
345
}
345
346
346
- ob_flush ();
347
-
348
347
$ this ->clearCluster ();
349
348
350
349
if ($ setup !== null ) {
@@ -407,36 +406,32 @@ private function executeTestCase($test, $testFile, $future)
407
406
408
407
foreach ($ test [$ key ] as $ operators ) {
409
408
foreach ($ operators as $ operator => $ settings ) {
410
- echo " > $ operator: " ;
411
- ob_flush ();
409
+ $ this ->log (" > $ operator: " );
412
410
if ($ operator === 'do ' ) {
413
411
if (key ($ settings ) === 'catch ' ) {
414
412
$ catch = $ this ->getValue ($ settings , 'catch ' );
415
413
$ expectedError = str_replace ("/ " , "" , $ catch );
416
414
next ($ settings );
417
415
418
- echo "(catch: $ expectedError) " ;
419
- ob_flush ();
416
+ $ this ->log ("(catch: $ expectedError) " );
420
417
} else {
421
418
$ expectedError = null ;
422
419
}
423
420
424
421
$ method = key ($ settings );
425
422
$ hash = $ this ->getValue ($ settings , $ method );
426
423
427
- echo "\n | $ method \n" ;
428
- ob_flush ();
424
+ $ this ->log ("\n | $ method \n" );
429
425
430
426
431
427
$ hash = YamlRunnerTest::replaceWithStash ($ hash , $ stash );
432
428
433
429
434
430
try {
435
- echo " | " .json_encode ($ hash )."\n" ;
431
+ $ this -> log ( " | " .json_encode ($ hash )."\n" ) ;
436
432
ob_flush ();
437
433
$ response = $ this ->callMethod ($ method , $ hash , $ future );
438
- echo " | " .json_encode ($ response )."\n" ;
439
- ob_flush ();
434
+ $ this ->log (" | " .json_encode ($ response )."\n" );
440
435
441
436
//$this->waitForYellow();
442
437
@@ -477,27 +472,27 @@ private function executeTestCase($test, $testFile, $future)
477
472
if ($ this ->checkForRegex ($ expected ) === true ) {
478
473
$ this ->assertRegex ($ expected , $ actual );
479
474
} else {
480
- $ this ->assertEquals ($ expected , $ actual );
475
+ $ this ->assertEquals ($ expected , $ actual, $ this -> log );
481
476
}
482
477
483
478
//$this->assertSame()
484
479
485
- echo "\n" ;
480
+ $ this -> log ( "\n" ) ;
486
481
} elseif ($ operator === "is_true " ) {
487
482
if (empty ($ settings ) === true ) {
488
483
$ response = YamlRunnerTest::replaceWithStash ($ response , $ stash );
489
484
$ this ->assertTruthy ($ response , $ settings );
490
485
} else {
491
486
$ settings = YamlRunnerTest::replaceWithStash ($ settings , $ stash );
492
- echo "settings after replace: " ;
487
+ $ this -> log ( "settings after replace: " ) ;
493
488
//print_r($settings);
494
- echo "\n" ;
489
+ $ this -> log ( "\n" ) ;
495
490
$ actual = $ this ->getNestedVar ($ response , $ settings );
496
491
$ actual = YamlRunnerTest::replaceWithStash ($ actual , $ stash );
497
492
$ this ->assertTruthy ($ actual , $ settings );
498
493
}
499
494
500
- echo "\n" ;
495
+ $ this -> log ( "\n" ) ;
501
496
} elseif ($ operator === "is_false " ) {
502
497
if (empty ($ settings ) === true ) {
503
498
$ response = YamlRunnerTest::replaceWithStash ($ response , $ stash );
@@ -508,36 +503,34 @@ private function executeTestCase($test, $testFile, $future)
508
503
$ this ->assertFalsey ($ actual , $ settings );
509
504
}
510
505
511
- echo "\n" ;
506
+ $ this -> log ( "\n" ) ;
512
507
} elseif ($ operator === 'set ' ) {
513
508
$ stashKey = $ this ->getValue ($ settings , key ($ settings ));
514
- echo " $ stashKey \n" ;
509
+ $ this -> log ( " $ stashKey \n" ) ;
515
510
$ stash ["$ $ stashKey " ] = $ this ->getNestedVar ($ response , key ($ settings ));
516
- echo "Stash updated. Total stash now: \n" ;
511
+ $ this -> log ( "Stash updated. Total stash now: \n" ) ;
517
512
//print_r($stash);
518
- echo "\n" ;
519
- ob_flush ();
513
+ $ this ->log ("\n" );
520
514
} elseif ($ operator === "length " ) {
521
515
$ expectedCount = $ this ->getValue ($ settings , key ($ settings ));
522
- $ this ->assertCount ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )));
523
- echo "\n" ;
516
+ $ this ->assertCount ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )), $ this -> log );
517
+ $ this -> log ( "\n" ) ;
524
518
} elseif ($ operator === "lt " ) {
525
519
$ expectedCount = $ this ->getValue ($ settings , key ($ settings ));
526
- $ this ->assertLessThan ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )));
527
- echo "\n" ;
520
+ $ this ->assertLessThan ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )), $ this -> log );
521
+ $ this -> log ( "\n" ) ;
528
522
} elseif ($ operator === "gt " ) {
529
523
$ expectedCount = $ this ->getValue ($ settings , key ($ settings ));
530
- $ this ->assertGreaterThan ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )));
531
- echo "\n" ;
524
+ $ this ->assertGreaterThan ($ expectedCount , $ this ->getNestedVar ($ response , key ($ settings )), $ this -> log );
525
+ $ this -> log ( "\n" ) ;
532
526
} elseif ($ operator === "skip " ) {
533
527
if (isset ($ settings ['version ' ]) === true ) {
534
528
$ version = $ settings ['version ' ];
535
529
$ version = str_replace (" " , "" , $ version );
536
530
$ version = explode ("- " , $ version );
537
531
538
532
if (isset ($ version [0 ]) && $ version [0 ] == 'all ' ) {
539
- echo "Skipping: all \n" ;
540
- ob_flush ();
533
+ $ this ->log ("Skipping: all \n" );
541
534
if ($ key == 'setup ' ) {
542
535
throw new SetupSkipException ();
543
536
}
@@ -551,7 +544,7 @@ private function executeTestCase($test, $testFile, $future)
551
544
}
552
545
if (version_compare (YamlRunnerTest::$ esVersion , $ version [0 ]) >= 0
553
546
&& version_compare ($ version [1 ], YamlRunnerTest::$ esVersion ) >= 0 ) {
554
- echo "Skipping: " .$ settings ['reason ' ]."\n" ;
547
+ $ this -> log ( "Skipping: " .$ settings ['reason ' ]."\n" ) ;
555
548
556
549
if ($ key == 'setup ' ) {
557
550
throw new SetupSkipException ();
@@ -564,13 +557,12 @@ private function executeTestCase($test, $testFile, $future)
564
557
$ whitelist = array ();
565
558
566
559
if (array_search ($ feature , $ whitelist ) === false ) {
567
- echo "Unsupported optional feature: $ feature \n" ;
560
+ $ this -> log ( "Unsupported optional feature: " . print_r ( $ feature, true ) . " \n") ;
568
561
569
562
return ;
570
563
}
571
564
}
572
565
}
573
- ob_flush ();
574
566
}
575
567
}
576
568
}
@@ -613,7 +605,7 @@ private function handleCaughtException(\Exception $exception, $expectedError)
613
605
}
614
606
615
607
if ($ passed === true ) {
616
- $ this ->assertTrue (true );
608
+ $ this ->assertTrue (true , $ this -> log );
617
609
if ($ exception ->getPrevious () !== null ) {
618
610
return json_decode ($ exception ->getPrevious ()->getMessage (), true );
619
611
}
@@ -689,8 +681,8 @@ private function getNestedVar(&$context, $name)
689
681
$ piece = str_replace ('\. ' , '. ' , $ piece );
690
682
if (!is_array ($ context ) || !array_key_exists ($ piece , $ context )) {
691
683
// error occurred
692
- echo "Could not find nested property [ $ piece] in context " ;//.print_r($context, true);
693
- echo "\nReturning null... " ;
684
+ $ this -> log ( "Could not find nested property [ $ piece] in context " ) ;//.print_r($context, true);
685
+ $ this -> log ( "\nReturning null... " ) ;
694
686
return null ;
695
687
}
696
688
$ context = &$ context [$ piece ];
0 commit comments