Skip to content

Commit

Permalink
[TEST] Support headers in yaml runner, do some bad-comment cleaning
Browse files Browse the repository at this point in the history
Also fixes the feature whitelist checker to support arrays of
features.
  • Loading branch information
polyfractal committed Jul 20, 2017
1 parent 3a3a5ab commit 57b5489
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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) !== '';
Expand Down

0 comments on commit 57b5489

Please sign in to comment.