From 57b548968c4de946683f4562c8cc51e6e87ed737 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 20 Jul 2017 13:13:22 -0400 Subject: [PATCH] [TEST] Support headers in yaml runner, do some bad-comment cleaning Also fixes the feature whitelist checker to support arrays of features. --- tests/Elasticsearch/Tests/YamlRunnerTest.php | 28 +++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/Elasticsearch/Tests/YamlRunnerTest.php b/tests/Elasticsearch/Tests/YamlRunnerTest.php index 30a566ae8..1c2e8cc9c 100644 --- a/tests/Elasticsearch/Tests/YamlRunnerTest.php +++ b/tests/Elasticsearch/Tests/YamlRunnerTest.php @@ -42,7 +42,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase /** @var array A list of supported features */ private static $supportedFeatures = [ - 'stash_in_path', 'warnings' + 'stash_in_path', 'warnings', 'headers', 'yaml' ]; /** @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 { $expectedError = null; $expectedWarnings = null; + $headers = null; // Check if a error must be caught if ('catch' === key($operation)) { @@ -261,6 +262,12 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa next($operation); } + // Any specific headers to add? + if ('headers' === key($operation)) { + $headers = current($operation); + next($operation); + } + $endpointInfo = explode('.', key($operation)); $endpointParams = $this->replaceWithContext(current($operation), $context); $caller = $this->client; @@ -287,6 +294,10 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa $endpointParams->client['future'] = true; } + if ($headers != null) { + $endpointParams->client['headers'] = $headers; + } + list($method, $namespace) = $this->mapEndpoint($method, $namespace); if (null !== $namespace) { @@ -629,8 +640,16 @@ public function operationSkip($operation, $lastOperationResult, $testName) return $lastOperationResult; } - if (property_exists($operation, 'features') && !in_array($operation->features, static::$supportedFeatures, true)) { - static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName)); + if (property_exists($operation, 'features')) { + if (is_array($operation->features)) { + if (count(array_intersect($operation->features, static::$supportedFeatures)) != count($operation->features)) { + static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName)); + } + } else { + if (!in_array($operation->features, static::$supportedFeatures, true)) { + static::markTestSkipped(sprintf('Feature(s) %s not supported in test "%s"', json_encode($operation->features), $testName)); + } + } } if (property_exists($operation, 'version')) { @@ -844,6 +863,9 @@ private function formatRegex($regex) private function splitDocument($file, $path, $filter = null) { $fileContent = file_get_contents($file); + // cleanup some bad comments + $fileContent = str_replace('"#', '" #', $fileContent); + $documents = explode("---\n", $fileContent); $documents = array_filter($documents, function ($item) { return trim($item) !== '';