Skip to content

Commit

Permalink
Setups should be run for every yaml "doc"
Browse files Browse the repository at this point in the history
Previously, setups were run once per yaml file.  But a yaml file
may have multiple "docs" (separated by --- ), and setup needs to
be reun before each test.

This commit preparses the entire yaml file and saves the setup if
it exists, which is then run before each test case.
  • Loading branch information
polyfractal committed Jan 21, 2014
1 parent 2453a7e commit e36b6df
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function setUp()

$params['hosts'] = array($uri['host'].':'.$uri['port']);
$params['connectionParams']['timeout'] = 10000;
$params['logging'] = true;
$params['logLevel'] = \Psr\Log\LogLevel::DEBUG;
$this->client = new Elasticsearch\Client($params);

}
Expand Down Expand Up @@ -198,33 +200,43 @@ public function testYaml()
foreach ($files as $testFile) {
echo "$testFile\n";
ob_flush();
$this->clearCluster();

$fileData = file_get_contents($testFile);
$documents = array_filter(explode("---", $fileData));

$yamlDocs = array();
$setup = null;
foreach ($documents as $document) {
try {
$document = $this->checkForTimestamp($testFile, $document);
$values = $this->yaml->parse($document, false, false, false);
$tDoc = array();
$tDoc['document'] = $this->checkForTimestamp($testFile, $document);
$tDoc['values'] = $this->yaml->parse($tDoc['document'], false, true, false);

echo " ".key($values)."\n";
ob_flush();
try {
$ret = $this->executeTestCase($values, $testFile);
} catch (SetupSkipException $exception) {
// @TODO refactor this! This is a gross hack
// This allows executeTestCase to signal that it encountered
// a skip in a setup

break; //skip all remaining tests in this file
if (key($tDoc['values']) === 'setup') {
$setup = $tDoc['values'];
} else {
$yamlDocs[] = $tDoc;
}


} catch (ParseException $e) {
printf("Unable to parse the YAML string: %s", $e->getMessage());
}
}

foreach ($yamlDocs as $doc) {
echo " ".key($doc['values'])."\n";
ob_flush();

$this->clearCluster();

if ($setup !== null) {
$this->executeTestCase($setup, $testFile);
}
$this->executeTestCase($doc['values'], $testFile);

}


}


Expand Down Expand Up @@ -334,6 +346,16 @@ private function executeTestCase($test, $testFile)
}
$response = array();

} catch (Elasticsearch\Common\Exceptions\RuntimeException $exception){
if ($expectedError === 'param') {
$this->assertTrue(true);
} elseif (isset($expectedError) === true && preg_match("/$expectedError/", $exception->getMessage()) === 1) {
$this->assertTrue(true);
} else {
$this->fail($exception->getMessage());
}
$response = array();

} catch (\Exception $exception) {
if ($expectedError === null) {
$this->fail($exception->getMessage());
Expand Down

0 comments on commit e36b6df

Please sign in to comment.