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