Skip to content

Commit d8d577c

Browse files
committed
[TEST] Add support for teardowns in yaml tests
1 parent 8362ede commit d8d577c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function setUp()
136136
* @dataProvider yamlProvider
137137
* @group sync
138138
*/
139-
public function testIntegration($testProcedure, bool $skip, $setupProcedure, string $fileName)
139+
public function testIntegration($testProcedure, bool $skip, $setupProcedure, $teardownProcedure, string $fileName)
140140
{
141141
if ($skip) {
142142
static::markTestIncomplete($testProcedure);
@@ -151,14 +151,21 @@ public function testIntegration($testProcedure, bool $skip, $setupProcedure, str
151151
$this->waitForYellow();
152152
}
153153

154-
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName);
154+
try {
155+
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName);
156+
} finally {
157+
if (null !== $teardownProcedure) {
158+
$this->processProcedure(current($teardownProcedure), 'teardown', $fileName);
159+
$this->waitForYellow();
160+
}
161+
}
155162
}
156163

157164
/**
158165
* @dataProvider yamlProvider
159166
* @group async
160167
*/
161-
public function testAsyncIntegration($testProcedure, bool $skip, $setupProcedure, string $fileName)
168+
public function testAsyncIntegration($testProcedure, bool $skip, $setupProcedure, $teardownProcedure, string $fileName)
162169
{
163170
if ($skip) {
164171
static::markTestIncomplete($testProcedure);
@@ -173,7 +180,14 @@ public function testAsyncIntegration($testProcedure, bool $skip, $setupProcedure
173180
$this->waitForYellow();
174181
}
175182

176-
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName, true);
183+
try {
184+
$this->processProcedure(current($testProcedure), key($testProcedure), $fileName, true);
185+
} finally {
186+
if (null !== $teardownProcedure) {
187+
$this->processProcedure(current($teardownProcedure), 'teardown', $fileName);
188+
$this->waitForYellow();
189+
}
190+
}
177191
}
178192

179193
/**
@@ -917,6 +931,7 @@ private function splitDocument(SplFileInfo $file, string $path, string $filter =
917931
$documentsParsed = [];
918932
$setup = null;
919933
$setupSkip = false;
934+
$teardown = null;
920935
$fileName = str_replace($path . '/', '', $file);
921936

922937
if (array_key_exists($fileName, static::$fatalFiles)) {
@@ -964,8 +979,10 @@ private function splitDocument(SplFileInfo $file, string $path, string $filter =
964979
if (!$skip && key($documentParsed) === 'setup') {
965980
$setup = $documentParsed;
966981
$setupSkip = $skip;
967-
} else {
968-
$documentsParsed[] = [$documentParsed, $skip || $setupSkip, $setup, $fileName];
982+
} else if (!$skip && key($documentParsed) === 'teardown') {
983+
$teardown = $documentParsed;
984+
} else {
985+
$documentsParsed[] = [$documentParsed, $skip || $setupSkip, $setup, $teardown, $fileName];
969986
}
970987
}
971988

0 commit comments

Comments
 (0)