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

Code before:

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

class YamlTestSuiteTest extends TestCase
{
    private static array $skip = [
        '26DV', '27NA', '2AUY', '2G84-00', '2G84-01', '2JQS', '2LFX', '2SXE', '2XXW', '33X3', '35KP', '4ABK', '4FJ6', '4JVG', '4RWC',
        '565N', '57H4', '5LLU', '5TRB', '5TYM', '5U3A', '5WE3', '6BFJ', '6CA3', '6CK3', '6JWB', '6LVF', '6M2F', '6VJK', '6WLZ', '6XDY',
        '6ZKB', '735Y', '74H7', '7FWL', '7T8X', '7W2P', '7Z25', '87E4', '8G76', '93JH', '98YD', '9BXH', '9C9N', '9DXL', '9JBA', '9KAX',
        '9MAG', '9MMA', '9MMW', '9MQT-01', '9WXW', '9YRD', 'A2M4', 'AVM7', 'B63P', 'BEC7', 'BF9H', 'BS4K', 'BU8L', 'C4HZ', 'CC74', 'CFD4',
        'CML9', 'CN3R', 'CTN5', 'CUP7', 'CVW2', 'CXX2', 'DFF7', 'DK4H', 'DK95-00', 'DK95-01', 'DK95-03', 'DK95-04', 'DK95-07', 'DWX9',
        'E76Z', 'EB22', 'EHF6', 'F2C7', 'FH7J', 'FRK4', 'G5U8', 'G992', 'GH63', 'H7TQ', 'HMQ5', 'HS5T', 'JHB9', 'JTV5', 'K527', 'K54U',
        'KK5P', 'L94M', 'LE5A', 'LQZ7', 'LX3P', 'M29M', 'M2N8-00', 'M5C3', 'M5DY', 'M9B4', 'MJS9', 'MUS6-00', 'MUS6-02', 'MUS6-03',
        'MUS6-04', 'MUS6-05', 'MUS6-06', 'MYW6', 'N782', 'NKF9', 'P76L', 'P94K', 'PUW8', 'PW8X', 'Q5MG', 'Q9WF', 'QB6E', 'RR7F', 'RXY3',
        'RZP5', 'RZT7', 'S3PD', 'S4T7', 'S98Z', 'S9E8', 'SKE5', 'SR86', 'SU5Z', 'SU74', 'SY6V', 'T26H', 'T833', 'TS54', 'U3C3', 'U3XV',
        'U9NS', 'UKK6-02', 'UT92', 'V9D5', 'W4TN', 'W9L4', 'WZ62', 'X38W', 'X8DW', 'XW4D', 'Y79Y-003', 'Y79Y-004', 'Y79Y-005', 'Y79Y-006',
        'Y79Y-008', 'Y79Y-009', 'YJV2', 'Z9M4', 'ZWK4',
    ];

    #[DataProvider('yamlTestSuiteProvider')]
    public function testYamlTestSuite(string $shortcode, string $dir)
    {
        if (\in_array($shortcode, self::$skip, true)) {
            $testname = is_file($dir.\DIRECTORY_SEPARATOR.'===') ? trim(file_get_contents($dir.\DIRECTORY_SEPARATOR.'===')) : $shortcode;
            $this->markTestSkipped('Test case "'.$testname.'" ('.$shortcode.') is skipped.');
        }

        $file = $dir.\DIRECTORY_SEPARATOR.'in.yaml';

        $isErrorExpected = false;
        if (file_exists($dir.\DIRECTORY_SEPARATOR.'error')) {
            $isErrorExpected = true;
            $this->expectException(\Exception::class);
        }

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

        if (!$isErrorExpected) {
            $this->assertTrue(\is_scalar($yaml) || \is_array($yaml));
        }
    }

    public static function yamlTestSuiteProvider(): array
    {
        if (!file_exists(__DIR__.\DIRECTORY_SEPARATOR.'yaml-test-suite'.\DIRECTORY_SEPARATOR.'data')) {
            self::markTestSkipped('The YAML test suite is not available.');
        }

        $dataDir = __DIR__.\DIRECTORY_SEPARATOR.'yaml-test-suite'.\DIRECTORY_SEPARATOR.'data';

Review comment (suggestion):
I suggest reading the relevant files in the data provider, so that the test name is part of the provided data.

Code after:

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

class YamlTestSuiteTest extends TestCase
{
    private const SKIP = [
        // Test cases that are known to fail or are not supported
        '26DV',
        '27NA',
        '2AUY',
        '2G84-00',
        '2G84-01',
        '2JQS',
        '2LFX',
        '2SXE',
        '2XXW',
        '33X3',
        '35KP',
        '36F6',
        '4ABK',
        '4FJ6',
        '4JVG',
        '4RWC',
        '565N',
        '57H4',
        '5LLU',
        '5TRB',
        '5TYM',
        '5U3A',
        '5WE3',
        '6BFJ',
        '6CA3',
        '6CK3',
        '6JWB',
        '6LVF',
        '6M2F',
        '6VJK',
        '6WLZ',
        '6XDY',
        '6ZKB',
        '735Y',
        '74H7',
        '7FWL',
        '7T8X',
        '7W2P',
        '7Z25',
        '87E4',
        '8G76',