* 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\BlocksAnalyzer; use PhpCsFixer\Tokenizer\Tokens; /** * @author Kuba Werłos * * @internal * * @covers \PhpCsFixer\Tokenizer\Analyzer\BlocksAnalyzer */ final class BlocksAnalyzerTest extends TestCase { /** * @dataProvider provideBlocksCases */ public function testBlocks(string $code, int $openIndex, int $closeIndex): void { $tokens = Tokens::fromCode($code); $analyzer = new BlocksAnalyzer(); self::assertTrue($analyzer->isBlock($tokens, $openIndex, $closeIndex)); } /** * @return iterable */ public static function provideBlocksCases(): iterable { yield [' $x + 10;', 6, 8]; } /** * @dataProvider provideNonBlocksCases */ public function testNonBlocks(string $code, int $openIndex, int $closeIndex): void { $tokens = Tokens::fromCode($code); $analyzer = new BlocksAnalyzer(); self::assertFalse($analyzer->isBlock($tokens, $openIndex, $closeIndex)); } /** * @return iterable */ public static function provideNonBlocksCases(): iterable { yield ['expectException(\InvalidArgumentException::class); $analyzer->isBlock($tokens, $openIndex, $closeIndex); } /** * @return iterable */ public static function provideInvalidIndexCases(): iterable { yield ['