123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * 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
- {
- /**
- * @param array<string, mixed> $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' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- public function testItDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itDoesSomething() {}
- }',
- ['style' => 'prefix'],
- ];
- yield 'Annotation is not used, but should be' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testItDoesSomething() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation is not used, but should be, class is extra indented' => [
- '<?php
- if (1) {
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itDoesSomething() {}
- }
- }',
- '<?php
- if (1) {
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testItDoesSomething() {}
- }
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation is not used, but should be, and there is already a docBlock' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @dataProvider blabla
- *
- * @test
- */
- public function itDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @dataProvider blabla
- */
- public function testItDoesSomething() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation is used, but should not be, and it depends on other tests' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- public function testAaa () {}
- public function helperFunction() {}
- /**
- * @depends testAaa
- *
- *
- */
- public function testBbb () {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function aaa () {}
- public function helperFunction() {}
- /**
- * @depends aaa
- *
- * @test
- */
- public function bbb () {}
- }',
- ['style' => 'prefix'],
- ];
- yield 'Annotation is not used, but should be, and it depends on other tests' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function aaa () {}
- /**
- * @depends aaa
- *
- * @test
- */
- public function bbb () {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testAaa () {}
- /**
- * @depends testAaa
- */
- public function testBbb () {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation is removed, the function is one word and we want it to use camel case' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- public function testWorks() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function works() {}
- }',
- ];
- yield 'Annotation is added, and it is snake case' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function it_has_snake_case() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test_it_has_snake_case() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation gets added, it has an @depends, and we use snake case' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function works_fine () {}
- /**
- * @depends works_fine
- *
- * @test
- */
- public function works_fine_too() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test_works_fine () {}
- /**
- * @depends test_works_fine
- */
- public function test_works_fine_too() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Class has both camel and snake case, annotated functions and not, and wants to add annotations' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function snake_cased () {}
- /**
- * @test
- */
- public function camelCased () {}
- /**
- * Description.
- *
- * @depends camelCased
- *
- * @test
- */
- public function depends_on_someone () {}
- //It even has a comment
- public function a_helper_function () {}
- /**
- * @depends depends_on_someone
- *
- * @test
- */
- public function moreDepends() {}
- /**
- * @depends depends_on_someone
- *
- * @test
- */
- public function alreadyAnnotated() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test_snake_cased () {}
- public function testCamelCased () {}
- /**
- * Description.
- *
- * @depends testCamelCased
- */
- public function test_depends_on_someone () {}
- //It even has a comment
- public function a_helper_function () {}
- /**
- * @depends test_depends_on_someone
- */
- public function testMoreDepends() {}
- /**
- * @depends test_depends_on_someone
- *
- * @test
- */
- public function alreadyAnnotated() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation has to be added to multiple functions' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itWorks() {}
- /**
- * @test
- */
- public function itDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testItWorks() {}
- public function testItDoesSomething() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Class with big doc blocks and multiple functions has to remove annotations' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * This test is part of the database group and has a provider.
- *
- * @param int $paramOne
- * @param bool $paramTwo
- *
- *
- * @dataProvider provides
- * @group Database
- */
- public function testDatabase ($paramOne, $paramTwo) {}
- /**
- * Provider for the database test function
- *
- * @return array
- */
- public function provides() {}
- /**
- * I am just a helper function but I have test in my name.
- * I also have a doc Block
- *
- * @return Foo\Bar
- */
- public function help_test() {}
- protected function setUp() {}
- /**
- * I depend on the database function, but I already
- * had test in my name and a docblock
- *
- * @depends testDatabase
- */
- public function testDepends () {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * This test is part of the database group and has a provider.
- *
- * @param int $paramOne
- * @param bool $paramTwo
- *
- * @test
- * @dataProvider provides
- * @group Database
- */
- public function database ($paramOne, $paramTwo) {}
- /**
- * Provider for the database test function
- *
- * @return array
- */
- public function provides() {}
- /**
- * I am just a helper function but I have test in my name.
- * I also have a doc Block
- *
- * @return Foo\Bar
- */
- public function help_test() {}
- protected function setUp() {}
- /**
- * I depend on the database function, but I already
- * had test in my name and a docblock
- *
- * @depends database
- */
- public function testDepends () {}
- }',
- ];
- yield 'Test Annotation has to be removed, but its just one line' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** */
- public function testItWorks() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** @test */
- public function itWorks() {}
- }',
- ];
- yield 'Test annotation has to be added, but there is already a one line doc block' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @group Database
- *
- * @test
- */
- public function itTestsDatabase() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** @group Database */
- public function testItTestsDatabase() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Test annotation has to be added, but there is already a one line doc block which is a sentence' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * I really like this test, it helps a lot
- *
- * @test
- */
- public function itTestsDatabase() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** I really like this test, it helps a lot */
- public function testItTestsDatabase() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Test annotation has to be added, but there is already a one line comment present' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- //I really like this test, it helps a lot
- /**
- * @test
- */
- public function itTestsDatabase() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- //I really like this test, it helps a lot
- public function testItTestsDatabase() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Test annotation has to be added, there is a one line doc block which is an @depends tag' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itTestsDatabase() {}
- /**
- * @depends itTestsDatabase
- *
- * @test
- */
- public function itDepends() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testItTestsDatabase() {}
- /** @depends testItTestsDatabase */
- public function testItDepends() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation gets removed, but the function has a @testWith' => [
- '<?php
- final class ProcessLinterProcessBuilderTest extends TestCase
- {
- /**
- *
- * @param string $executable
- * @param string $file
- * @param string $expected
- *
- * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
- * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
- * @requires OS Linux|Darwin
- */
- public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
- {
- $builder = new ProcessLinterProcessBuilder($executable);
- $this->assertSame(
- $expected,
- $builder->build($file)->getCommandLine()
- );
- }
- }',
- '<?php
- final class ProcessLinterProcessBuilderTest extends TestCase
- {
- /**
- * @test
- * @param string $executable
- * @param string $file
- * @param string $expected
- *
- * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
- * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
- * @requires OS Linux|Darwin
- */
- public function prepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
- {
- $builder = new ProcessLinterProcessBuilder($executable);
- $this->assertSame(
- $expected,
- $builder->build($file)->getCommandLine()
- );
- }
- }',
- ];
- yield 'Annotation gets added, but there is already an @testWith in the doc block' => [
- '<?php
- final class ProcessLinterProcessBuilderTest extends TestCase
- {
- /**
- * @param string $executable
- * @param string $file
- * @param string $expected
- *
- * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
- * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
- * @requires OS Linux|Darwin
- *
- * @test
- */
- public function prepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
- {
- $builder = new ProcessLinterProcessBuilder($executable);
- $this->assertSame(
- $expected,
- $builder->build($file)->getCommandLine()
- );
- }
- }',
- '<?php
- final class ProcessLinterProcessBuilderTest extends TestCase
- {
- /**
- * @param string $executable
- * @param string $file
- * @param string $expected
- *
- * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
- * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
- * @requires OS Linux|Darwin
- */
- public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
- {
- $builder = new ProcessLinterProcessBuilder($executable);
- $this->assertSame(
- $expected,
- $builder->build($file)->getCommandLine()
- );
- }
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation gets properly removed, even when it is in a weird place' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * I am a comment about the function
- */
- public function testIHateMyTestSuite() {}
- /**
- * I am another comment about a function
- */
- public function testThisMakesNoSense() {}
- /**
- * This comment has more issues
- */
- public function testItUsesTabs() {}
- /**
- * @depends testItUsesTabs
- */
- public function testItDependsReally() {}
- /**
- * @depends testItUsesTabs
- */
- public function testItDependsSomeMore() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * I am a comment @test about the function
- */
- public function iHateMyTestSuite() {}
- /**
- * I am another comment about a function @test
- */
- public function thisMakesNoSense() {}
- /**
- * This comment has @test more issues
- */
- public function itUsesTabs() {}
- /**
- * @depends itUsesTabs @test
- */
- public function itDependsReally() {}
- /**
- * @test @depends itUsesTabs
- */
- public function itDependsSomeMore() {}
- }',
- ];
- yield 'Annotation gets added when a single line has doc block has multiple tags already' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * There is some text here @group Database @group Integration
- *
- * @test
- */
- public function whyDoThis() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** There is some text here @group Database @group Integration */
- public function testWhyDoThis() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation gets removed when a single line doc block has the tag, but there are other things as well' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** There is some text here @group Database @group Integration */
- public function testWhyDoThis() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** There is some @test text here @group Database @group Integration */
- public function testWhyDoThis() {}
- }',
- ];
- yield 'Annotation is used, and should be' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function itDoesSomething() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Annotation is not used, and should not be' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testItDoesSomethingWithoutPhpDoc() {}
- /**
- * No annotation, just text
- */
- public function testItDoesSomethingWithPhpDoc() {}
- public function testingItDoesSomethingWithoutPhpDoc() {}
- /**
- * No annotation, just text
- */
- public function testingItDoesSomethingWithPhpDoc() {}
- }',
- ];
- yield 'Annotation is added when it is already present in a weird place' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * I am a comment @test about the function
- *
- * @test
- */
- public function iHateMyTestSuite() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * I am a comment @test about the function
- */
- public function iHateMyTestSuite() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Docblock does not get converted to a multi line doc block if it already has @test annotation' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /** @test */
- public function doesSomeThings() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Annotation does not get added if class is not a test' => [
- '<?php
- class Waterloo
- {
- public function testDoesSomeThings() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Annotation does not get removed if class is not a test' => [
- '<?php
- class Waterloo
- {
- /**
- * @test
- */
- public function doesSomeThings() {}
- }',
- ];
- yield 'Annotation does not get added if there are no tests in the test class' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function setUp() {}
- public function itHelpsSomeTests() {}
- public function someMoreChanges() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Abstract test gets annotation removed' => [
- '<?php
- abstract class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- abstract function testFooBar();
- }',
- '<?php
- abstract class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- abstract function fooBar();
- }',
- ['style' => 'prefix'],
- ];
- yield 'Annotation present, but method already have test prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- public function testarossaIsFromItaly() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function testarossaIsFromItaly() {}
- }',
- ['style' => 'prefix'],
- ];
- yield 'Annotation present, but method is test prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- *
- */
- public function test() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test() {}
- }',
- ['style' => 'prefix'],
- ];
- yield 'Abstract test gets annotation added' => [
- '<?php
- abstract class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- abstract function fooBar();
- }',
- '<?php
- abstract class Test extends \PhpUnit\FrameWork\TestCase
- {
- abstract function testFooBar();
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation gets added, but there is a number after the testprefix so it keeps the prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test123fooBar() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test123fooBar() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation missing, but there is a lowercase character after the test prefix so it keeps the prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function testarossaIsFromItaly() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function testarossaIsFromItaly() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation present, but there is a lowercase character after the test prefix so it keeps the prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function testarossaIsFromItaly() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Annotation missing, method qualifies as test, but test prefix cannot be removed' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation missing, method qualifies as test, but test_ prefix cannot be removed' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test_() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test_() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'Annotation present, method qualifies as test, but test_ prefix cannot be removed' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test_() {}
- }',
- null,
- ['style' => 'annotation'],
- ];
- yield 'Annotation missing, method after fix still has "test" prefix' => [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- public function test_foo() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- public function test_test_foo() {}
- }',
- ['style' => 'annotation'],
- ];
- yield 'do not touch single line @depends annotation when already correct' => [
- '<?php class FooTest extends \PHPUnit\Framework\TestCase
- {
- public function testOne() {}
- /** @depends testOne */
- public function testTwo() {}
- /** @depends testTwo */
- public function testThree() {}
- }',
- ];
- }
- /**
- * @param array<string, mixed> $config
- *
- * @dataProvider provideMessyWhitespacesCases
- */
- public function testMessyWhitespaces(string $expected, ?string $input = null, array $config = []): void
- {
- $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
- $this->fixer->configure($config);
- $this->doTest($expected, $input);
- }
- public static function provideMessyWhitespacesCases(): iterable
- {
- yield [
- '<?php
- class FooTest extends \PHPUnit_Framework_TestCase {
- /**
- *
- */
- public function testFooTest() {}
- }
- ',
- '<?php
- class FooTest extends \PHPUnit_Framework_TestCase {
- /**
- * @test
- */
- public function fooTest() {}
- }
- ',
- ];
- }
- /**
- * @dataProvider provideFix80Cases
- *
- * @param array<string, string> $config
- *
- * @requires PHP 8.0
- */
- public function testFix80(string $expected, string $input, array $config): void
- {
- $this->fixer->configure($config);
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<(array<string, string>|string)[]>
- */
- public static function provideFix80Cases(): iterable
- {
- yield [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- #[OneTest]
- public function itWorks() {}
- /**
- * @test
- */
- #[TwoTest]
- public function itDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- #[OneTest]
- public function testItWorks() {}
- #[TwoTest]
- public function testItDoesSomething() {}
- }',
- ['style' => 'annotation'],
- ];
- yield [
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- /**
- * @test
- */
- #[OneTest]
- #[Internal]
- public function itWorks() {}
- /**
- * @test
- */
- #[TwoTest]
- #[Internal]
- public function itDoesSomething() {}
- }',
- '<?php
- class Test extends \PhpUnit\FrameWork\TestCase
- {
- #[OneTest]
- #[Internal]
- public function testItWorks() {}
- #[TwoTest]
- #[Internal]
- public function testItDoesSomething() {}
- }',
- ['style' => 'annotation'],
- ];
- }
- }
|