Repository: symfony/symfony
File: src/Symfony/Component/Yaml/Tests/YamlTestSuiteTest.php (PHP)

Code before:
        'UGM3',
        'UKK6-00',
        'Z67P',
        'ZH7C',
    ];

    #[DataProvider('yamlTestSuiteProvider')]
    public function testYamlTestSuite(string $testName, string $shortcode, string $dir, bool $isError, mixed $expected)
    {
        if ('' === $dir) {
            $this->markTestSkipped('The YAML test suite is not available: '.$testName);
        }

        if (\in_array($shortcode, self::SKIP, true)) {
            $this->markTestSkipped('Test case "'.$testName.'" ('.$shortcode.') is skipped.');
        }

        $file = $dir.'/in.yaml';

        $isErrorExpected = false;
        if ($isError) {
            $isErrorExpected = true;
            $this->expectException(ParseException::class);
        }

        $yaml = Yaml::parseFile($file);

        if (!$isErrorExpected) {
            $this->assertEquals($expected, $yaml, 'Test case "'.$testName.'" ('.$shortcode.') failed.');
        }
    }

    public static function yamlTestSuiteProvider(): \Generator
    {
        $dataDir = __DIR__.'/yaml-test-suite';

        if (!file_exists($dataDir)) {
            yield 'yaml-test-suite-missing' => ['YAML Test Suite Missing', '', '', false, null];

            return;
        }

        $shortcodeDirs = glob($dataDir.'/*', \GLOB_ONLYDIR);

        if (empty($shortcodeDirs)) {
            yield 'yaml-test-suite-empty' => ['YAML Test Suite Empty', '', '', false, null];

            return;
        }

        foreach ($shortcodeDirs as $shortcodeDir) {

Review comment (suggestion):
I would call it `$data` here. The output of parsing is not YAML (the meaningful content of a variable named `$yaml` would be the content of the file)

Code after:
        'TL85',
        'UGM3',
        'UKK6-00',
        'Z67P',
        'ZH7C',
    ];

    #[DataProvider('yamlTestSuiteProvider')]
    public function testYamlTestSuite(string $testName, string $shortcode, string $file, bool $isErrorExpected, mixed $expected)
    {
        if ('' === $file) {
            $this->markTestSkipped(\sprintf('The YAML test suite is not available: %s', $testName));
        }

        if (\in_array($shortcode, self::SKIP, true)) {
            $this->markTestSkipped(\sprintf('Test case "%s" (%s) is skipped.', $testName, $shortcode));
        }

        if ($isErrorExpected) {
            $this->expectException(ParseException::class);
        }

        $data = Yaml::parseFile($file);

        if (!$isErrorExpected) {
            $this->assertEquals($expected, $data, \sprintf('Test case "%s" (%s) failed.', $testName, $shortcode));
        }
    }

    public static function yamlTestSuiteProvider(): \Generator
    {
        $dataDir = self::getTestSuitePath();

        if (null === $dataDir) {
            yield 'yaml-test-suite-missing' => ['YAML Test Suite Missing', '', '', false, null];

            return;
        }

        $shortcodeDirs = glob($dataDir.'/*', \GLOB_ONLYDIR);

        if (!$shortcodeDirs) {
            yield 'yaml-test-suite-empty' => ['YAML Test Suite Empty', '', '', false, null];

            return;
        }

        foreach ($shortcodeDirs as $shortcodeDir) {
            $shortcode = basename($shortcodeDir);

            if (\in_array($shortcode, ['name', 'tags'], true)) {