From e36b6df3771bc6dfe6c48a53d41ecf3c92aa2997 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 21 Jan 2014 12:25:07 -0500 Subject: [PATCH] Setups should be run for every yaml "doc" 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. --- tests/Elasticsearch/Tests/YamlRunnerTest.php | 50 ++++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/tests/Elasticsearch/Tests/YamlRunnerTest.php b/tests/Elasticsearch/Tests/YamlRunnerTest.php index 6d60d76bc..d61dd3a76 100644 --- a/tests/Elasticsearch/Tests/YamlRunnerTest.php +++ b/tests/Elasticsearch/Tests/YamlRunnerTest.php @@ -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); } @@ -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); + + } + + } @@ -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());