* 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\Indicator; use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Tokens; /** * @internal * * @covers \PhpCsFixer\Indicator\PhpUnitTestCaseIndicator */ final class PhpUnitTestCaseIndicatorTest extends TestCase { private ?PhpUnitTestCaseIndicator $indicator; protected function setUp(): void { $this->indicator = new PhpUnitTestCaseIndicator(); parent::setUp(); } protected function tearDown(): void { $this->indicator = null; parent::tearDown(); } /** * @dataProvider provideIsPhpUnitClassCases */ public function testIsPhpUnitClass(bool $expected, Tokens $tokens, int $index): void { self::assertSame($expected, $this->indicator->isPhpUnitClass($tokens, $index)); } public static function provideIsPhpUnitClassCases(): iterable { yield 'Test class' => [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ true, Tokens::fromCode(' [ false, Tokens::fromCode(' [ false, Tokens::fromCode(' [ false, Tokens::fromCode('expectException(\LogicException::class); $this->expectExceptionMessageMatches('/^No "T_CLASS" at given index 1, got "T_ECHO"\.$/'); $this->indicator->isPhpUnitClass($tokens, 1); } /** * @param array $expectedIndexes * * @dataProvider provideFindPhpUnitClassesCases */ public function testFindPhpUnitClasses(array $expectedIndexes, string $code): void { $tokens = Tokens::fromCode($code); $classes = $this->indicator->findPhpUnitClasses($tokens); $classes = iterator_to_array($classes); self::assertSame($expectedIndexes, $classes); } public static function provideFindPhpUnitClassesCases(): iterable { yield 'empty' => [ [], '', ]; yield 'empty script' => [ [], " [ [], ' [ [ [10, 11], ], ' [ [ [21, 34], [10, 11], ], ' [ [ [71, 84], [29, 42], ], ' [ [], '