class YamlValidationTest

Same name and namespace in other branches
  1. 3.x tests/src/Unit/YamlValidationTest.php \Drupal\Tests\examples\Unit\YamlValidationTest

Validate requirements for config YAML.

YAML in modules' config/ directory should not have a uuid: key. We'll use this test to check whether that's the case.

@group examples

Hierarchy

  • class \Drupal\Tests\examples\Unit\YamlValidationTest implements \PHPUnit\Framework\TestCase

Expanded class hierarchy of YamlValidationTest

File

tests/src/Unit/YamlValidationTest.php, line 16

Namespace

Drupal\Tests\examples\Unit
View source
class YamlValidationTest extends TestCase {
  
  /**
   * Find all the config YAML files and provide them to the test.
   *
   * @return array[]
   *   An array of arrays of strings, suitable as a data provider. Strings are
   *   paths to YAML files in config directories.
   */
  public function provideYamls() {
    $yaml_paths = [];
    $examples_project_path = realpath(__DIR__ . '/../../..');
    $paths = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($examples_project_path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
    foreach ($paths as $path) {
      $pathname = $path->getPathname();
      if (strpos($pathname, '.yml') !== FALSE) {
        if (strpos($pathname, '/config/') !== FALSE) {
          $yaml_paths[] = [
            $pathname,
          ];
        }
      }
    }
    return $yaml_paths;
  }
  
  /**
   * @dataProvider provideYamls
   */
  public function testNoUuidsInConfig($yaml_path) {
    $yaml = Yaml::parse(file_get_contents($yaml_path));
    $this->assertArrayNotHasKey('uuid', $yaml, "YAML in this file contains a uuid key: {$yaml_path}");
  }

}

Members

Title Sort descending Modifiers Object type Summary
YamlValidationTest::provideYamls public function Find all the config YAML files and provide them to the test.
YamlValidationTest::testNoUuidsInConfig public function @dataProvider provideYamls