Skip to content
Snippets Groups Projects
Commit c0399b94 authored by Alberto Paderno's avatar Alberto Paderno
Browse files

Merge branch '3458387-fix-YamlValidationTest-failures' into '4.0.x'

Issue #3458387: Avoid YamlValidationTest::provideYamls() returns .yml files that are not part of the Examples project

See merge request !59
parents 63ddbacf d94ec6e8
No related branches found
No related tags found
No related merge requests found
Pipeline #213748 passed with warnings
...@@ -6,45 +6,54 @@ ...@@ -6,45 +6,54 @@
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
/** /**
* Validate requirements for config YAML. * Verifies the configuration files are valid.
* *
* YAML in modules' config/ directory should not have a uuid: key. We'll use * Configuration files are considered valid if they do not contain a uuid key.
* this test to check whether that's the case.
* *
* @group examples * @group examples
*/ */
class YamlValidationTest extends TestCase { class YamlValidationTest extends TestCase {
/** /**
* Find all the config YAML files and provide them to the test. * Finds all the config YAML files and provide them to the test.
* *
* @return array[] * @return array[]
* An array of arrays of strings, suitable as a data provider. Strings are * An array of arrays of filenames for YAML files in config directories.
* paths to YAML files in config directories.
*/ */
public function provideYamls() { public function provideYamls() {
$yaml_paths = []; $path = realpath(__DIR__ . '/../../..') . '/modules';
$yaml_files = [];
$examples_project_path = realpath(__DIR__ . '/../../..');
$directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
$paths = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($examples_project_path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); $filter = new \RecursiveCallbackFilterIterator($directory, function ($current, $key, $iterator) {
foreach ($paths as $path) { if ($current->isFile()) {
$pathname = $path->getPathname(); // Only accept files whose extension is .yml which are contained in a
if (strpos($pathname, '.yml') !== FALSE) { // config directory.
if (strpos($pathname, '/config/') !== FALSE) { if ($current->getExtension() === 'yml' && strpos($current->getPathName(), '/config/') !== FALSE) {
$yaml_paths[] = [$pathname]; return TRUE;
} }
return FALSE;
} }
// Always accept a directory.
return TRUE;
});
$iterator = new \RecursiveIteratorIterator($filter);
foreach ($iterator as $info) {
$yaml_files[] = [$info->getPathname()];
} }
return $yaml_paths;
return $yaml_files;
} }
/** /**
* @dataProvider provideYamls * @dataProvider provideYamls
*/ */
public function testNoUuidsInConfig($yaml_path) { public function testNoUuidsInConfig($yaml_file) {
$yaml = Yaml::parse(file_get_contents($yaml_path)); $yaml = Yaml::parse(file_get_contents($yaml_file));
$this->assertArrayNotHasKey('uuid', $yaml, "YAML in this file contains a uuid key: $yaml_path"); $this->assertArrayNotHasKey('uuid', $yaml, "$yaml_file contains a uuid key.");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment