Skip to content

Commit 51f189e

Browse files
committed
[TEST] test tweaks to appease stricter types
1 parent 5f83b52 commit 51f189e

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Elasticsearch\Common\Exceptions\ServerErrorResponseException;
1515
use Elasticsearch\Common\Exceptions\RoutingMissingException;
1616
use GuzzleHttp\Ring\Future\FutureArrayInterface;
17+
use RecursiveDirectoryIterator;
18+
use RecursiveIteratorIterator;
1719
use Symfony\Component\Finder\Finder;
1820
use Symfony\Component\Finder\SplFileInfo;
1921
use Symfony\Component\Yaml\Exception\ParseException;
@@ -669,7 +671,7 @@ public function operationSkip($operation, $lastOperationResult, $testName)
669671
$version[1] = PHP_INT_MAX;
670672
}
671673

672-
if (version_compare(static::$esVersion, $version[0], '>=') && version_compare(static::$esVersion, $version[1], '<=')) {
674+
if (version_compare(static::$esVersion, (string)$version[0], '>=') && version_compare(static::$esVersion, (string)$version[1], '<=')) {
673675
static::markTestSkipped(sprintf('Skip test "%s", as version %s should be skipped (%s)', $testName, static::$esVersion, $operation->reason));
674676
}
675677
}
@@ -862,7 +864,8 @@ private function formatRegex($regex)
862864
*/
863865
private function splitDocument($file, $path, $filter = null)
864866
{
865-
$fileContent = file_get_contents($file);
867+
868+
$fileContent = $file->getContents();
866869
// cleanup some bad comments
867870
$fileContent = str_replace('"#', '" #', $fileContent);
868871

@@ -999,16 +1002,32 @@ private function clean()
9991002
}
10001003
}
10011004

1002-
// TODO ewwww...
1003-
shell_exec('rm -rf /tmp/test_repo_create_1_loc');
1004-
shell_exec('rm -rf /tmp/test_repo_restore_1_loc');
1005-
shell_exec('rm -rf /tmp/test_cat_repo_1_loc');
1006-
shell_exec('rm -rf /tmp/test_cat_repo_2_loc');
1007-
shell_exec('rm -rf /tmp/test_cat_snapshots_1_loc');
1005+
$this->rmDirRecursively('/tmp/test_repo_create_1_loc');
1006+
$this->rmDirRecursively('/tmp/test_repo_restore_1_loc');
1007+
$this->rmDirRecursively('/tmp/test_cat_repo_1_loc');
1008+
$this->rmDirRecursively('/tmp/test_cat_repo_2_loc');
1009+
$this->rmDirRecursively('/tmp/test_cat_snapshots_1_loc');
10081010

10091011
$this->waitForYellow();
10101012
}
10111013

1014+
private function rmDirRecursively($dir) {
1015+
if (!is_dir($dir )) {
1016+
return;
1017+
}
1018+
$files = new RecursiveIteratorIterator(
1019+
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
1020+
RecursiveIteratorIterator::CHILD_FIRST
1021+
);
1022+
1023+
foreach ($files as $fileinfo) {
1024+
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
1025+
$todo($fileinfo->getRealPath());
1026+
}
1027+
1028+
rmdir($dir);
1029+
}
1030+
10121031
/**
10131032
* Wait for cluster to be in a "YELLOW" state
10141033
*/

0 commit comments

Comments
 (0)