* 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\Fixer\ClassNotation; use PhpCsFixer\Test\AbstractFixerTestCase; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\WhitespacesFixerConfig; /** * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\MethodSeparationFixer */ final class MethodSeparationFixerTest extends AbstractFixerTestCase { /** * @param int $expected * @param string $code * @param int $index * * @dataProvider provideCommentBlockStartDetectionCases */ public function testCommentBlockStartDetection($expected, $code, $index) { Tokens::clearCache(); $tokens = Tokens::fromCode($code); $method = new \ReflectionMethod($this->fixer, 'findCommentBlockStart'); $method->setAccessible(true); if ($expected !== $result = $method->invoke($this->fixer, $tokens, $index)) { $this->fail(sprintf('Expected index %d (%s) got index %d (%s).', $expected, $tokens[$expected]->toJson(), $result, $tokens[$result]->toJson())); } } public function provideCommentBlockStartDetectionCases() { return array( array( 4, 'doTest($expected, $input); } public function provideFixClassesCases() { $cases = array(); $cases[] = array('filter( function (\SplFileInfo $file) use ($files) { return !in_array($file->getRelativePathname(), $files, true); } ); } } private $a; public static function method145() { } abstract protected function method245(); // comment final private function method345() { } } function test1(){ echo 1;} function test2(){ echo 2;}', 'filter( function (\SplFileInfo $file) use ($files) { return !in_array($file->getRelativePathname(), $files, true); } ); } } private $a; public static function method145() { } abstract protected function method245(); // comment final private function method345() { } } function test1(){ echo 1;} function test2(){ echo 2;}', ); $cases[] = array( ' * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Linter; /** * Dummy linter. No linting is performed. No error is raised. * * @author Dariusz Rumiński * * @internal */ final class NullLinter implements LinterInterface { /** * {@inheritdoc} */ public function lintFile($path) { unset($path); } /** * {@inheritdoc} */ public function lintSource($source) { unset($source); } } ', ); // do not touch anonymous functions (since PHP doesn't allow // for class attributes being functions :(, we only have to test // those used within methods) $cases[] = array( 'doTest($expected, $input); } public function provideFixTraitsCases() { $cases = array(); // do not touch well formatted traits $cases[] = array( 'doTest($expected, $input); } public function provideFixInterfaces() { $cases = array(); $cases[] = array( 'fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->doTest($expected, $input); } public function provideMessyWhitespacesCases() { return array( array( "