Skip to content

Commit

Permalink
Reapply the YAML_FILES_TO_OMIT for Internal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed May 3, 2022
1 parent 70371ee commit c75d7ff
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions util/YamlTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use stdClass;
use Throwable;

use function yaml_parse;

Expand Down Expand Up @@ -147,22 +148,41 @@ private function getAllTests(string $dir): array
$parsed = [];
// Iterate over the Yaml test files
foreach (new RecursiveIteratorIterator($it) as $file) {
if ($file->getExtension() === 'yml') {
$content = file_get_contents($file->getPathname());
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
if ($file->getExtension() !== 'yml') {
continue;
}
$omit = false;
foreach (self::YAML_FILES_TO_OMIT as $fileOmit) {
if (false !== strpos($file->getPathname(), $fileOmit)) {
$omit = true;
break;
}
}
if ($omit) {
continue;
}
$content = file_get_contents($file->getPathname());
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
try {
$test = yaml_parse($content, -1, $ndocs, [
YAML_MAP_TAG => function($value, $tag, $flags) {
return empty($value) ? new stdClass : $value;
}
]);
if (false === $test) {
throw new Exception(sprintf(
"YAML parse error file %s",
$file->getPathname()
));
}
$parsed[$file->getPathname()] = $test;
} catch (Throwable $e) {
throw new Exception(sprintf(
"YAML parse error file %s: %s",
$file->getPathname(),
$e->getMessage()
));
}
if (false === $test) {
throw new Exception(sprintf(
"YAML parse error file %s",
$file->getPathname()
));
}
$parsed[$file->getPathname()] = $test;
}
return $parsed;
}
Expand Down

0 comments on commit c75d7ff

Please sign in to comment.