Skip to content

Commit

Permalink
[TEST] Fix teardown in yaml runner
Browse files Browse the repository at this point in the history
Also include a quick fix for some malformed upstream yaml tests
  • Loading branch information
polyfractal committed Jan 7, 2019
1 parent 46d5a7a commit 098030e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function setUp()
* @dataProvider yamlProvider
* @group sync
*/
public function testIntegration($testProcedure, $skip, $setupProcedure, $fileName)
public function testIntegration($testProcedure, bool $skip, $setupProcedure, $teardownProcedure, string $fileName)
{
if ($skip) {
static::markTestIncomplete($testProcedure);
Expand All @@ -157,14 +157,21 @@ public function testIntegration($testProcedure, $skip, $setupProcedure, $fileNam
$this->waitForYellow();
}

$this->processProcedure(current($testProcedure), key($testProcedure), $fileName);
try {
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName);
} finally {
if (null !== $teardownProcedure) {
$this->processProcedure(current($teardownProcedure), 'teardown', $fileName);
$this->waitForYellow();
}
}
}

/**
* @dataProvider yamlProvider
* @group async
*/
public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fileName)
public function testAsyncIntegration($testProcedure, bool $skip, $setupProcedure, $teardownProcedure, string $fileName)
{
if ($skip) {
static::markTestIncomplete($testProcedure);
Expand All @@ -179,7 +186,14 @@ public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fi
$this->waitForYellow();
}

$this->processProcedure(current($testProcedure), key($testProcedure), $fileName, true);
try {
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName, true);
} finally {
if (null !== $teardownProcedure) {
$this->processProcedure(current($teardownProcedure), 'teardown', $fileName);
$this->waitForYellow();
}
}
}

/**
Expand Down Expand Up @@ -918,6 +932,7 @@ private function splitDocument($file, $path, $filter = null)
$documentsParsed = [];
$setup = null;
$setupSkip = false;
$teardown = null;
$fileName = str_replace($path . '/', '', $file);

if (array_key_exists($fileName, static::$fatalFiles)) {
Expand All @@ -931,6 +946,8 @@ private function splitDocument($file, $path, $filter = null)
$skip = false;
$documentParsed = null;
foreach ($documents as $documentString) {
// TODO few bad instances of teardown, should be fixed in upstream but this is a quick fix locally
$documentString = str_replace(" teardown:", "teardown:", $documentString);
try {
if (!$setupSkip) {
$documentParsed = $this->yaml->parse($documentString, false, false, true);
Expand Down Expand Up @@ -965,8 +982,10 @@ private function splitDocument($file, $path, $filter = null)
if (!$skip && key($documentParsed) === 'setup') {
$setup = $documentParsed;
$setupSkip = $skip;
} elseif (!$teardown && key($documentParsed) === 'teardown') {
$teardown = $documentParsed;
} else {
$documentsParsed[] = [$documentParsed, $skip || $setupSkip, $setup, $fileName];
$documentsParsed[] = [$documentParsed, $skip || $setupSkip, $setup, $teardown, $fileName];
}
}

Expand Down

0 comments on commit 098030e

Please sign in to comment.