Skip to content

Commit

Permalink
[TEST] Allow skipping individual tests inside of test file
Browse files Browse the repository at this point in the history
Adds smaller granularity so we can skip individual tests,
rather than just the entire file.
  • Loading branch information
polyfractal committed Aug 21, 2017
1 parent 061f100 commit 51b9b9b
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
],
];

private static $skippedTests = [
'cluster.put_settings/10_basic.yml#Test get a default settings' => 'Tested attribute does not exist normally, followup with core.'
];

/** @var array A list of skipped test with their reasons */
private static $skippedTest = [
private static $skippedFiles = [
'cat.aliases/20_headers.yml' => 'Using java regex fails in PHP',
'cat.aliases/20_headers.yaml' => 'Using java regex fails in PHP',

Expand All @@ -74,7 +78,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
];

/** @var array A list of files to skip completely, due to fatal parsing errors */
private static $skippedFiles = [
private static $fatalFiles = [
'indices.create/10_basic.yml' => 'Temporary: Yaml parser doesnt support "inline" empty keys',
'indices.create/10_basic.yaml' => 'Temporary: Yaml parser doesnt support "inline" empty keys',

Expand Down Expand Up @@ -140,16 +144,16 @@ public function testIntegration($testProcedure, $skip, $setupProcedure, $fileNam
static::markTestIncomplete($testProcedure);
}

if (array_key_exists($fileName, static::$skippedTest)) {
static::markTestSkipped(static::$skippedTest[$fileName]);
if (array_key_exists($fileName, static::$skippedFiles)) {
static::markTestSkipped(static::$skippedFiles[$fileName]);
}

if (null !== $setupProcedure) {
$this->processProcedure(current($setupProcedure), 'setup');
$this->processProcedure(current($setupProcedure), 'setup', $fileName);
$this->waitForYellow();
}

$this->processProcedure(current($testProcedure), key($testProcedure));
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName);
}

/**
Expand All @@ -162,16 +166,16 @@ public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fi
static::markTestIncomplete($testProcedure);
}

if (array_key_exists($fileName, static::$skippedTest)) {
static::markTestSkipped(static::$skippedTest[$fileName]);
if (array_key_exists($fileName, static::$skippedFiles)) {
static::markTestSkipped(static::$skippedFiles[$fileName]);
}

if (null !== $setupProcedure) {
$this->processProcedure(current($setupProcedure), 'setup');
$this->waitForYellow();
}

$this->processProcedure(current($testProcedure), key($testProcedure), true);
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName, true);
}

/**
Expand All @@ -181,11 +185,15 @@ public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fi
* @param $name
* @param bool $async
*/
public function processProcedure($procedure, $name, $async = false)
public function processProcedure($procedure, $name, $fileName, $async = false)
{
$lastOperationResult = null;
$context = [];

if (array_key_exists("$fileName#$name", static::$skippedTests)) {
static::markTestSkipped(static::$skippedTests["$fileName#$name"]);
}

foreach ($procedure as $operation) {
$lastOperationResult = $this->processOperation($operation, $lastOperationResult, $context, $name, $async);
}
Expand Down Expand Up @@ -902,8 +910,8 @@ private function splitDocument($file, $path, $filter = null)
$setupSkip = false;
$fileName = str_replace($path . '/', '', $file);

if (array_key_exists($fileName, static::$skippedFiles)) {
echo "Skipping: $fileName. ".static::$skippedFiles[$fileName]."\n";
if (array_key_exists($fileName, static::$fatalFiles)) {
echo "Skipping: $fileName. ".static::$fatalFiles[$fileName]."\n";
return [];
}

Expand Down

0 comments on commit 51b9b9b

Please sign in to comment.