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

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

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

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

    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 (empty($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)) {
                continue;
            }

            if (file_exists($shortcodeDir.'/in.yaml')) {
                yield $shortcode => self::createTestItem($shortcode, $shortcodeDir);
                continue;
            }

            foreach (glob($shortcodeDir.'/*', \GLOB_ONLYDIR) as $subDir) {
                if (file_exists($subDir.'/in.yaml')) {
                    yield $shortcode.'-'.basename($subDir) => self::createTestItem($shortcode.'-'.basename($subDir), $subDir);
                }
            }
        }
    }


Review comment (suggestion):
We don't use `empty()` in the codebase. This suggestion will work if `glob()` returns false or an empty array:


```suggestion
        if (!$shortcodeDirs) {
```

Code after:
        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)) {
                continue;
            }

            if (file_exists($shortcodeDir.'/in.yaml')) {
                yield $shortcode => self::createTestItem($shortcode, $shortcodeDir);
                continue;
            }

            foreach (glob($shortcodeDir.'/*', \GLOB_ONLYDIR) as $subDir) {
                if (file_exists($subDir.'/in.yaml')) {
                    yield $shortcode.'-'.basename($subDir) => self::createTestItem($shortcode.'-'.basename($subDir), $subDir);
                }
            }
        }
    }

    private static function createTestItem(string $shortcode, string $dir): array
    {