* 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\PhpUnit; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; /** * @author Gert de Pagter * * @internal * * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer */ final class PhpUnitTestAnnotationFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases * * @param string $expected * @param null|string $input */ public function testFix($expected, $input = null, array $config = []) { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return array */ public function provideFixCases() { return [ 'Annotation is used, and it should not be' => [ ' 'prefix'], ], 'Annotation is not used, but should be' => [ ' 'annotation'], ], 'Annotation is not used, but should be, class is extra indented' => [ ' 'annotation'], ], 'Annotation is not used, but should be, and there is already a docBlock' => [ ' 'annotation'], ], 'Annotation is used, but should not be, and it depends on other tests' => [ ' 'prefix'], ], 'Annotation is not used, but should be, and it depends on other tests' => [ ' 'annotation'], ], 'Annotation is removed, the function is one word and we want it to use camel case' => [ ' [ ' 'annotation'], ], 'Annotation gets added, it has an @depends, and we use snake case' => [ ' 'annotation'], ], 'Class has both camel and snake case, annotated functions and not, and wants to add annotations' => [ ' 'annotation'], ], 'Annotation has to be added to multiple functions' => [ ' 'annotation'], ], 'Class with big doc blocks and multiple functions has to remove annotations' => [ ' [ ' [ ' 'annotation'], ], 'Test annotation has to be added, but there is already a one line doc block which is a sentence' => [ ' 'annotation'], ], 'Test annotation has to be added, but there is already a one line comment present' => [ ' 'annotation'], ], 'Test annotation has to be added, there is a one line doc block which is an @depends tag' => [ ' 'annotation'], ], 'Annotation gets removed, but the function has a @testWith' => [ 'assertSame( $expected, $builder->build($file)->getCommandLine() ); } }', 'assertSame( $expected, $builder->build($file)->getCommandLine() ); } }', ], 'Annotation gets added, but there is already an @testWith in the doc block' => [ 'assertSame( $expected, $builder->build($file)->getCommandLine() ); } }', 'assertSame( $expected, $builder->build($file)->getCommandLine() ); } }', ['style' => 'annotation'], ], 'Annotation gets properly removed, even when it is in a weird place' => [ ' [ ' 'annotation'], ], 'Annotation gets removed when a single line doc block has the tag, but there are other things as well' => [ ' [ ' 'annotation'], ], 'Annotation is not used, and should not be' => [ ' [ ' 'annotation'], ], 'Docblock does not get converted to a multi line doc block if it already has @test annotation' => [ ' 'annotation'], ], 'Annotation does not get added if class is not a test' => [ ' 'annotation'], ], 'Annotation does not get removed if class is not a test' => [ ' [ ' 'annotation'], ], 'Abstract test gets annotation removed' => [ ' 'prefix'], ], 'Annotation present, but method already have test prefix' => [ ' 'prefix'], ], 'Annotation present, but method is test prefix' => [ ' 'prefix'], ], 'Abstract test gets annotation added' => [ ' 'annotation'], ], 'Annotation gets added, but there is a number after the testprefix so it keeps the prefix' => [ ' 'annotation'], ], 'Annotation missing, but there is a lowercase character after the test prefix so it keeps the prefix' => [ ' 'annotation'], ], 'Annotation present, but there is a lowercase character after the test prefix so it keeps the prefix' => [ ' 'annotation'], ], 'Annotation missing, method qualifies as test, but test prefix cannot be removed' => [ ' 'annotation'], ], 'Annotation missing, method qualifies as test, but test_ prefix cannot be removed' => [ ' 'annotation'], ], 'Annotation present, method qualifies as test, but test_ prefix cannot be removed' => [ ' 'annotation'], ], 'Annotation missing, method after fix still has "test" prefix' => [ ' 'annotation'], ], ]; } /** * @param string $expected * @param null|string $input * * @dataProvider provideMessyWhitespacesCases */ public function testMessyWhitespaces($expected, $input = null, array $config = []) { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($config); $this->doTest($expected, $input); } public function provideMessyWhitespacesCases() { return [ [ '