function YamlTest::testYamlFiles

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Serialization/YamlTest.php \Drupal\Tests\Component\Serialization\YamlTest::testYamlFiles()

Tests all YAML files are decoded in the same way with Symfony and PECL.

This test is a little bit slow but it tests that we do not have any bugs in our YAML that might not be decoded correctly in any of our implementations.

@todo This should exist as an integration test not part of our unit tests. https://www.drupal.org/node/2597730

@requires extension yaml @dataProvider providerYamlFilesInCore

File

core/tests/Drupal/Tests/Component/Serialization/YamlTest.php, line 68

Class

YamlTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Serialization%21Yaml.php/class/Yaml/8.9.x" title="Provides a YAML serialization implementation." class="local">\Drupal\Component\Serialization\Yaml</a> @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testYamlFiles($file) {
    $data = file_get_contents($file);
    try {
        $this->assertEquals(YamlSymfony::decode($data), YamlPecl::decode($data), $file);
    } catch (InvalidDataTypeException $e) {
        // Provide file context to the failure so the exception message is useful.
        $this->fail("Exception thrown parsing {$file}:\n" . $e->getMessage());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.