* 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; /** * @internal * * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderNameFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderNameFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderNameFixer */ final class PhpUnitDataProviderNameFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixCases(): iterable { yield 'data provider named with different casing' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'provideFooCases(); // do not get fooled that data provider name is already taken } public function provideFooCases() {} }', 'provideFooCases(); // do not get fooled that data provider name is already taken } public function fooDataProvider() {} }', ]; foreach (['abstract', 'final', 'private', 'protected', 'static', '/* private */'] as $modifier) { yield \sprintf('test function with %s modifier', $modifier) => [ \sprintf(' [ 'theBestPrefixFooCases', 'testFoo', ['prefix' => 'theBestPrefix'], ], 'custom suffix' => [ 'provideFooTheBestSuffix', 'testFoo', ['suffix' => 'TheBestSuffix'], ], 'custom prefix and suffix' => [ 'theBestPrefixFooTheBestSuffix', 'testFoo', ['prefix' => 'theBestPrefix', 'suffix' => 'TheBestSuffix'], ], 'empty prefix' => [ 'fooDataProvider', 'testFoo', ['prefix' => '', 'suffix' => 'DataProvider'], ], 'empty suffix' => [ 'dataProviderForFoo', 'testFoo', ['prefix' => 'dataProviderFor', 'suffix' => ''], ], 'prefix and suffix with underscores' => [ 'provide_foo_data', 'test_foo', ['prefix' => 'provide_', 'suffix' => '_data'], ], 'empty prefix and suffix with underscores' => [ 'foo_data_provider', 'test_foo', ['prefix' => '', 'suffix' => '_data_provider'], ], 'prefix with underscores and empty suffix' => [ 'data_provider_foo', 'test_foo', ['prefix' => 'data_provider_', 'suffix' => ''], ], 'prefix with underscores and empty suffix and test function starting with uppercase' => [ 'data_provider_Foo', 'test_Foo', ['prefix' => 'data_provider_', 'suffix' => ''], ], 'prefix and suffix with underscores and test function having multiple consecutive underscores' => [ 'provide_foo_data', 'test___foo', ['prefix' => 'provide_', 'suffix' => '_data'], ], 'uppercase naming' => [ 'PROVIDE_FOO_DATA', 'TEST_FOO', ['prefix' => 'PROVIDE_', 'suffix' => '_DATA'], ], 'camelCase test function and prefix with underscores' => [ 'data_provider_FooBar', 'testFooBar', ['prefix' => 'data_provider_', 'suffix' => ''], ], ] as $name => [$dataProvider, $testFunction, $config] ) { yield $name => [ \sprintf('doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield 'with an attribute between PHPDoc and test method' => [ <<<'PHP'