12
12
use Elasticsearch \Common \Exceptions \ServerErrorResponseException ;
13
13
use Elasticsearch \Common \Exceptions \RoutingMissingException ;
14
14
use GuzzleHttp \Ring \Future \FutureArrayInterface ;
15
+ use stdClass ;
15
16
use Symfony \Component \Finder \Finder ;
16
17
use Symfony \Component \Finder \SplFileInfo ;
17
18
use Symfony \Component \Yaml \Exception \ParseException ;
@@ -57,6 +58,12 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
57
58
'cat.repositories/10_basic.yaml ' => 'Using java regex fails in PHP '
58
59
];
59
60
61
+ /** @var array A list of files to skip completely, due to fatal parsing errors */
62
+ private static $ skippedFiles = [
63
+ 'indices.create/10_basic.yaml ' => 'Temporary: Yaml parser doesnt support "inline" empty keys ' ,
64
+ 'indices.put_mapping/10_basic.yaml ' => 'Temporary: Yaml parser doesnt support "inline" empty keys ' ,
65
+ ];
66
+
60
67
/**
61
68
* Return the elasticsearch host
62
69
*
@@ -98,7 +105,7 @@ public function setUp()
98
105
}
99
106
100
107
/**
101
- * @dataProvider provider
108
+ * @dataProvider yamlProvider
102
109
* @group sync
103
110
*/
104
111
public function testIntegration ($ testProcedure , $ skip , $ setupProcedure , $ fileName )
@@ -120,8 +127,7 @@ public function testIntegration($testProcedure, $skip, $setupProcedure, $fileNam
120
127
}
121
128
122
129
/**
123
- * @dataProvider provider
124
- * @group async
130
+
125
131
*/
126
132
public function testAsyncIntegration ($ testProcedure , $ skip , $ setupProcedure , $ fileName )
127
133
{
@@ -311,7 +317,10 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
311
317
return $ this ->assertException ($ exception , $ expectedError , $ testName );
312
318
}
313
319
314
- throw $ exception ;
320
+ $ msg = $ exception ->getMessage ()
321
+ ."\nException in " .get_class ($ caller )." with [ $ method]. \n Context: \n"
322
+ .var_export ($ endpointParams , true );
323
+ throw new \Exception ($ msg , 0 , $ exception );
315
324
}
316
325
}
317
326
@@ -366,7 +375,8 @@ public function executeAsyncExistRequest($caller, $method, $endpointParams, $exp
366
375
*/
367
376
public function operationIsFalse ($ operation , $ lastOperationResult , &$ context , $ testName )
368
377
{
369
- static ::assertFalse ((bool )$ this ->resolveValue ($ lastOperationResult , $ operation , $ context ), 'Failed to assert that a value is false in test ' . $ testName );
378
+ $ msg = "Failed to assert that a value is false in test \"$ testName \"\n" .var_export ($ lastOperationResult , true );
379
+ static ::assertFalse ((bool )$ this ->resolveValue ($ lastOperationResult , $ operation , $ context ), $ msg );
370
380
371
381
return $ lastOperationResult ;
372
382
}
@@ -382,10 +392,11 @@ public function operationIsTrue($operation, $lastOperationResult, &$context, $te
382
392
{
383
393
$ value = $ this ->resolveValue ($ lastOperationResult , $ operation , $ context );
384
394
385
- static ::assertNotEquals (0 , $ value , 'Failed to assert that a value is true in test ' . $ testName );
386
- static ::assertNotFalse ($ value , 'Failed to assert that a value is true in test ' . $ testName );
387
- static ::assertNotNull ($ value , 'Failed to assert that a value is true in test ' . $ testName );
388
- static ::assertNotEquals ('' , 'Failed to assert that a value is true in test ' . $ testName );
395
+ $ msg = "Failed to assert that a value is true in test \"$ testName \"\n" .var_export ($ lastOperationResult , true );
396
+ static ::assertNotEquals (0 , $ value , $ msg );
397
+ static ::assertNotFalse ($ value , $ msg );
398
+ static ::assertNotNull ($ value , $ msg );
399
+ static ::assertNotEquals ('' , $ msg );
389
400
390
401
return $ lastOperationResult ;
391
402
}
@@ -408,17 +419,19 @@ public function operationMatch($operation, $lastOperationResult, &$context, $tes
408
419
}
409
420
410
421
$ expected = $ this ->replaceWithContext (current ($ operation ), $ context );
422
+ $ msg = "Failed to match in test \"$ testName \". Expected [ "
423
+ .var_export ($ expected , true )."] does not match [ " .var_export ($ match , true )."] \n" .var_export ($ lastOperationResult , true );
411
424
412
425
if ($ expected instanceof \stdClass) {
413
426
// Avoid stdClass / array mismatch
414
427
$ expected = json_decode (json_encode ($ expected ), true );
415
428
$ match = json_decode (json_encode ($ match ), true );
416
429
417
- static ::assertEquals ($ expected , $ match , sprintf ( ' Failed to match in test "%s" ' , $ testName ) );
430
+ static ::assertEquals ($ expected , $ match , $ msg );
418
431
} elseif (is_string ($ expected ) && preg_match ('#^/.+?/$#s ' , $ expected )) {
419
- static ::assertRegExp ($ this ->formatRegex ($ expected ), $ match , sprintf ( ' Failed to match in test "%s" ' , $ testName ) );
432
+ static ::assertRegExp ($ this ->formatRegex ($ expected ), $ match , $ msg );
420
433
} else {
421
- static ::assertEquals ($ expected , $ match , sprintf ( ' Failed to match in test "%s" ' , $ testName ) );
434
+ static ::assertEquals ($ expected , $ match , $ msg );
422
435
}
423
436
424
437
return $ lastOperationResult ;
@@ -575,7 +588,7 @@ private function assertException(\Exception $exception, $expectedError, $testNam
575
588
*
576
589
* @return array
577
590
*/
578
- public function provider ()
591
+ public function yamlProvider ()
579
592
{
580
593
$ this ->yaml = new Yaml ();
581
594
$ path = __DIR__ . '/../../../util/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test ' ;
@@ -730,10 +743,16 @@ private function splitDocument($file, $path, $filter = null)
730
743
$ setupSkip = false ;
731
744
$ fileName = str_replace ($ path . '/ ' , '' , $ file );
732
745
733
- if (null !== $ filter && !preg_match ('/ ' .preg_quote ($ filter , '/ ' ).'/ ' , $ fileName )) {
746
+ if (array_key_exists ($ fileName , static ::$ skippedFiles )) {
747
+ echo "Skipping: $ fileName. " .static ::$ skippedFiles [$ fileName ]."\n" ;
734
748
return [];
735
749
}
736
750
751
+ if (null !== $ filter && !preg_match ('/ ' .preg_quote ($ filter , '/ ' ).'/ ' , $ fileName )) {
752
+ return [];
753
+ }
754
+ $ skip = false ;
755
+ $ documentParsed = null ;
737
756
foreach ($ documents as $ documentString ) {
738
757
try {
739
758
if (!$ setupSkip ) {
@@ -742,7 +761,19 @@ private function splitDocument($file, $path, $filter = null)
742
761
}
743
762
} catch (ParseException $ exception ) {
744
763
$ documentParsed = sprintf (
745
- "Cannot run this test as it cannot be parsed (%s) in file %s " ,
764
+ "[ParseException]Cannot run this test as it cannot be parsed (%s) in file %s " ,
765
+ $ exception ->getMessage (),
766
+ $ fileName
767
+ );
768
+
769
+ if (preg_match ("# \nsetup:#mx " , $ documentString )) {
770
+ $ setupSkip = true ;
771
+ }
772
+
773
+ $ skip = true ;
774
+ } catch (\Exception $ exception ) {
775
+ $ documentParsed = sprintf (
776
+ "[Exception] Cannot run this test as it generated an exception (%s) in file %s " ,
746
777
$ exception ->getMessage (),
747
778
$ fileName
748
779
);
0 commit comments