Skip to content

Commit

Permalink
Add regex assertion support to yaml test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 11, 2014
1 parent 2f8b936 commit 6d28b88
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ private function assertFalsey($value)
}
}

private function assertRegex($pattern, $actual) {
$pattern .= "mx";
$result = preg_match($pattern, $actual, $matches);
$this->assertEquals(1, $result);

}

private function waitForYellow()
{
$host = YamlRunnerTest::getHostEnvVar();
Expand Down Expand Up @@ -325,6 +332,7 @@ private function executeTestCase($test, $testFile)
}
$response = array();


} catch (Conflict409Exception $exception) {
if ($expectedError === 'conflict') {
$this->assertTrue(true);
Expand Down Expand Up @@ -378,6 +386,8 @@ private function executeTestCase($test, $testFile)
$expected = $settings[key($settings)];
if (key($settings) === '') {
$actual = $response;
} else if (key($settings) === '$body') {
$actual = $response;
} else {
$actual = $this->getNestedVar($response, key($settings));

Expand All @@ -388,7 +398,13 @@ private function executeTestCase($test, $testFile)
if (is_object($expected) === true) {
$expected = (array)$expected;
}
$this->assertEquals($expected, $actual);

if ($this->checkForRegex($expected) === true) {
$this->assertRegex($expected, $actual);
} else {
$this->assertEquals($expected, $actual);
}

//$this->assertSame()

echo "\n";
Expand Down Expand Up @@ -521,6 +537,19 @@ private function checkForTimestamp($file, $document)

}

private function checkForRegex($value) {
if (is_string($value) !== true) {
return false;
}

$value = trim($value);
if (substr($value, 0, 1) === '/' && substr($value, strlen($value) - 1, 1) === '/') {
return true;
} else {
return false;
}
}

private function getTimestampRegex()
{
return <<<EOF
Expand Down

0 comments on commit 6d28b88

Please sign in to comment.