* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Tokenizer\Analyzer; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Analyzer\Analysis\DataProviderAnalysis; use PhpCsFixer\Tokenizer\Analyzer\DataProviderAnalyzer; use PhpCsFixer\Tokenizer\Tokens; /** * @internal * * @covers \PhpCsFixer\Tokenizer\Analyzer\DataProviderAnalyzer */ final class DataProviderAnalyzerTest extends TestCase { /** * @param list $expected * * @dataProvider provideGettingDataProvidersCases */ public function testGettingDataProviders(array $expected, string $code, int $startIndex = 0, ?int $endIndex = null): void { $tokens = Tokens::fromCode($code); if (null === $endIndex) { $endIndex = $tokens->count() - 1; } $analyzer = new DataProviderAnalyzer(); self::assertSame(serialize($expected), serialize($analyzer->getDataProviders($tokens, $startIndex, $endIndex))); } /** * @return iterable, string}> */ public static function provideGettingDataProvidersCases(): iterable { yield 'single data provider' => [ [new DataProviderAnalysis('provider', 28, [[11, 23]])], ' [ [new DataProviderAnalysis('dataProvider', 28, [[11, 23]])], ' [ [new DataProviderAnalysis('provider', 30, [[11, 23]])], ' [ [ new DataProviderAnalysis('provider1', 28, [[11, 23]]), new DataProviderAnalysis('provider2', 39, [[11, 66]]), new DataProviderAnalysis('provider3', 50, [[11, 109]]), ], ' [ [ new DataProviderAnalysis('provider', 28, [[11, 23], [35, 23]]), ], ' [ [ new DataProviderAnalysis('provider1', 54, [[37, 4]]), new DataProviderAnalysis('provider2', 65, [[11, 4]]), new DataProviderAnalysis('provider3', 76, [[24, 4]]), ], \sprintf(' [ [], ' [ [], ' [ [ new DataProviderAnalysis('provider2', 93, [[65, 27]]), ], ' $expected * * @requires PHP ^8.0 * * @dataProvider provideGettingDataProviders80Cases */ public function testGettingDataProviders80(array $expected, string $code, int $startIndex = 0, ?int $endIndex = null): void { $this->testGettingDataProviders($expected, $code, $startIndex, $endIndex); } /** * @return iterable, string}> */ public static function provideGettingDataProviders80Cases(): iterable { yield 'with an attribute between PHPDoc and test method' => [ [new DataProviderAnalysis('provideFooCases', 35, [[11, 11]])], <<<'PHP'