Skip to content

Commit 57b5489

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 3a3a5ab commit 57b5489

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

+25-3
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 */
@@ -248,6 +248,7 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
248248
{
249249
$expectedError = null;
250250
$expectedWarnings = null;
251+
$headers = null;
251252

252253
// Check if a error must be caught
253254
if ('catch' === key($operation)) {
@@ -261,6 +262,12 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
261262
next($operation);
262263
}
263264

265+
// Any specific headers to add?
266+
if ('headers' === key($operation)) {
267+
$headers = current($operation);
268+
next($operation);
269+
}
270+
264271
$endpointInfo = explode('.', key($operation));
265272
$endpointParams = $this->replaceWithContext(current($operation), $context);
266273
$caller = $this->client;
@@ -287,6 +294,10 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
287294
$endpointParams->client['future'] = true;
288295
}
289296

297+
if ($headers != null) {
298+
$endpointParams->client['headers'] = $headers;
299+
}
300+
290301
list($method, $namespace) = $this->mapEndpoint($method, $namespace);
291302

292303
if (null !== $namespace) {
@@ -629,8 +640,16 @@ public function operationSkip($operation, $lastOperationResult, $testName)
629640
return $lastOperationResult;
630641
}
631642

632-
if (property_exists($operation, 'features') && !in_array($operation->features, static::$supportedFeatures, true)) {
633-
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
643+
if (property_exists($operation, 'features')) {
644+
if (is_array($operation->features)) {
645+
if (count(array_intersect($operation->features, static::$supportedFeatures)) != count($operation->features)) {
646+
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
647+
}
648+
} else {
649+
if (!in_array($operation->features, static::$supportedFeatures, true)) {
650+
static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName));
651+
}
652+
}
634653
}
635654

636655
if (property_exists($operation, 'version')) {
@@ -844,6 +863,9 @@ private function formatRegex($regex)
844863
private function splitDocument($file, $path, $filter = null)
845864
{
846865
$fileContent = file_get_contents($file);
866+
// cleanup some bad comments
867+
$fileContent = str_replace('"#', '" #', $fileContent);
868+
847869
$documents = explode("---\n", $fileContent);
848870
$documents = array_filter($documents, function ($item) {
849871
return trim($item) !== '';

0 commit comments

Comments
 (0)