Skip to content

Commit cb1956b

Browse files
committed
[TEST] output tweaks for better debugging, add temporary blacklist for fatal parsing files
1 parent 35b7087 commit cb1956b

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Elasticsearch\Common\Exceptions\ServerErrorResponseException;
1313
use Elasticsearch\Common\Exceptions\RoutingMissingException;
1414
use GuzzleHttp\Ring\Future\FutureArrayInterface;
15+
use stdClass;
1516
use Symfony\Component\Finder\Finder;
1617
use Symfony\Component\Finder\SplFileInfo;
1718
use Symfony\Component\Yaml\Exception\ParseException;
@@ -57,6 +58,12 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
5758
'cat.repositories/10_basic.yaml' => 'Using java regex fails in PHP'
5859
];
5960

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+
6067
/**
6168
* Return the elasticsearch host
6269
*
@@ -98,7 +105,7 @@ public function setUp()
98105
}
99106

100107
/**
101-
* @dataProvider provider
108+
* @dataProvider yamlProvider
102109
* @group sync
103110
*/
104111
public function testIntegration($testProcedure, $skip, $setupProcedure, $fileName)
@@ -120,8 +127,7 @@ public function testIntegration($testProcedure, $skip, $setupProcedure, $fileNam
120127
}
121128

122129
/**
123-
* @dataProvider provider
124-
* @group async
130+
125131
*/
126132
public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fileName)
127133
{
@@ -311,7 +317,10 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
311317
return $this->assertException($exception, $expectedError, $testName);
312318
}
313319

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);
315324
}
316325
}
317326

@@ -366,7 +375,8 @@ public function executeAsyncExistRequest($caller, $method, $endpointParams, $exp
366375
*/
367376
public function operationIsFalse($operation, $lastOperationResult, &$context, $testName)
368377
{
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);
370380

371381
return $lastOperationResult;
372382
}
@@ -382,10 +392,11 @@ public function operationIsTrue($operation, $lastOperationResult, &$context, $te
382392
{
383393
$value = $this->resolveValue($lastOperationResult, $operation, $context);
384394

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);
389400

390401
return $lastOperationResult;
391402
}
@@ -408,17 +419,19 @@ public function operationMatch($operation, $lastOperationResult, &$context, $tes
408419
}
409420

410421
$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);
411424

412425
if ($expected instanceof \stdClass) {
413426
// Avoid stdClass / array mismatch
414427
$expected = json_decode(json_encode($expected), true);
415428
$match = json_decode(json_encode($match), true);
416429

417-
static::assertEquals($expected, $match, sprintf('Failed to match in test "%s"', $testName));
430+
static::assertEquals($expected, $match, $msg);
418431
} 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);
420433
} else {
421-
static::assertEquals($expected, $match, sprintf('Failed to match in test "%s"', $testName));
434+
static::assertEquals($expected, $match, $msg);
422435
}
423436

424437
return $lastOperationResult;
@@ -575,7 +588,7 @@ private function assertException(\Exception $exception, $expectedError, $testNam
575588
*
576589
* @return array
577590
*/
578-
public function provider()
591+
public function yamlProvider()
579592
{
580593
$this->yaml = new Yaml();
581594
$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)
730743
$setupSkip = false;
731744
$fileName = str_replace($path . '/', '', $file);
732745

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";
734748
return [];
735749
}
736750

751+
if (null !== $filter && !preg_match('/'.preg_quote($filter, '/').'/', $fileName)) {
752+
return [];
753+
}
754+
$skip = false;
755+
$documentParsed = null;
737756
foreach ($documents as $documentString) {
738757
try {
739758
if (!$setupSkip) {
@@ -742,7 +761,19 @@ private function splitDocument($file, $path, $filter = null)
742761
}
743762
} catch (ParseException $exception) {
744763
$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",
746777
$exception->getMessage(),
747778
$fileName
748779
);

0 commit comments

Comments
 (0)