Skip to content

Commit 5590a88

Browse files
committed
[TEST] Support headers in yaml runner, do some bad-comment cleaning
Also fixes the feature whitelist checker to support arrays of features.
1 parent 1621094 commit 5590a88

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
4242

4343
/** @var array A list of supported features */
4444
private static $supportedFeatures = [
45-
'stash_in_path', 'warnings'
45+
'stash_in_path', 'warnings', 'headers', 'yaml'
4646
];
4747

4848
/** @var array A mapping for endpoint when there is a reserved keywords for the method / namespace name */
@@ -252,6 +252,7 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
252252
{
253253
$expectedError = null;
254254
$expectedWarnings = null;
255+
$headers = null;
255256

256257
// Check if a error must be caught
257258
if ('catch' === key($operation)) {
@@ -265,6 +266,12 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
265266
next($operation);
266267
}
267268

269+
// Any specific headers to add?
270+
if ('headers' === key($operation)) {
271+
$headers = current($operation);
272+
next($operation);
273+
}
274+
268275
$endpointInfo = explode('.', key($operation));
269276
$endpointParams = $this->replaceWithContext(current($operation), $context);
270277
$caller = $this->client;
@@ -291,6 +298,10 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
291298
$endpointParams->client['future'] = true;
292299
}
293300

301+
if ($headers != null) {
302+
$endpointParams->client['headers'] = $headers;
303+
}
304+
294305
list($method, $namespace) = $this->mapEndpoint($method, $namespace);
295306

296307
if (null !== $namespace) {
@@ -633,8 +644,16 @@ public function operationSkip($operation, $lastOperationResult, $testName)
633644
return $lastOperationResult;
634645
}
635646

636-
if (property_exists($operation, 'features') && !in_array($operation->features, static::$supportedFeatures, true)) {
637-
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
647+
if (property_exists($operation, 'features')) {
648+
if (is_array($operation->features)) {
649+
if (count(array_intersect($operation->features, static::$supportedFeatures)) != count($operation->features)) {
650+
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
651+
}
652+
} else {
653+
if (!in_array($operation->features, static::$supportedFeatures, true)) {
654+
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
655+
}
656+
}
638657
}
639658

640659
if (property_exists($operation, 'version')) {
@@ -848,6 +867,9 @@ private function formatRegex($regex)
848867
private function splitDocument($file, $path, $filter = null)
849868
{
850869
$fileContent = file_get_contents($file);
870+
// cleanup some bad comments
871+
$fileContent = str_replace('"#', '" #', $fileContent);
872+
851873
$documents = explode("---\n", $fileContent);
852874
$documents = array_filter($documents, function ($item) {
853875
return trim($item) !== '';

0 commit comments

Comments
 (0)