* 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\Linter; use PhpCsFixer\Linter\LinterInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use PHPUnit\Framework\TestCase; /** * @author Dariusz Rumiński * * @internal */ abstract class AbstractLinterTestCase extends TestCase { abstract public function testIsAsync(); public function testLintingAfterTokenManipulation() { $linter = $this->createLinter(); $tokens = Tokens::fromCode("insertAt(1, new Token(array(T_NS_SEPARATOR, '\\'))); $this->setExpectedException('\PhpCsFixer\Linter\LintingException'); $linter->lintSource($tokens->generateCode())->check(); } /** * @param string $file * @param null|string $errorRegExp * * @dataProvider provideLintFileCases */ public function testLintFile($file, $errorRegExp = null) { if (null !== $errorRegExp) { $this->setExpectedExceptionRegExp('\PhpCsFixer\Linter\LintingException', $errorRegExp); } $linter = $this->createLinter(); $this->assertNull($linter->lintFile($file)->check()); } /** * @return array */ public function provideLintFileCases() { return array( array( __DIR__.'/../Fixtures/Linter/valid.php', ), array( __DIR__.'/../Fixtures/Linter/invalid.php', '/syntax error, unexpected.*T_ECHO.*line 5/', ), ); } /** * @param string $source * @param null|string $errorRegExp * * @dataProvider provideLintSourceCases */ public function testLintSource($source, $errorRegExp = null) { if (null !== $errorRegExp) { $this->setExpectedExceptionRegExp('\PhpCsFixer\Linter\LintingException', $errorRegExp); } $linter = $this->createLinter(); $this->assertNull($linter->lintSource($source)->check()); } /** * @return array */ public function provideLintSourceCases() { return array( array( '