123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <?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;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderMethodOrderFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderMethodOrderFixer>
- *
- * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderMethodOrderFixer
- */
- final class PhpUnitDataProviderMethodOrderFixerTest 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<array{0: string, 1?: null|string, 2?: array<string, string>}>
- */
- public static function provideFixCases(): iterable
- {
- yield 'simple - placement after' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- }
- PHP,
- ];
- yield 'simple - placement before' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- }
- PHP,
- ['placement' => 'before'],
- ];
- yield 'empty test class' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {}
- PHP,
- ];
- yield 'data provider named with different casing' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function PROVIDEFOOCASES(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function PROVIDEFOOCASES(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- }
- PHP,
- ];
- yield 'with test method annotated' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /**
- * @test
- * @dataProvider provideFooCases
- */
- public function foo(): void {}
- public function provideFooCases(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /**
- * @test
- * @dataProvider provideFooCases
- */
- public function foo(): void {}
- }
- PHP,
- ];
- yield 'data provider not found' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /** @dataProvider notExistingFunction */
- public function testFoo(): void {}
- }
- PHP,
- ];
- yield 'data provider used multiple times - placement after' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo2(): void {}
- public function provideFooCases(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo2(): void {}
- }
- PHP,
- ];
- yield 'data provider used multiple times - placement after - do not move provider if already after first test where used' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testBar(): void {}
- }
- PHP,
- ];
- yield 'data provider used multiple times - placement before' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo2(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo2(): void {}
- public function provideFooCases(): iterable {}
- }
- PHP,
- ['placement' => 'before'],
- ];
- yield 'multiple data providers for one test method' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /**
- * @dataProvider provideFooCases
- * @dataProvider provideFooCases3
- * @dataProvider provideFooCases2
- */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- public function provideFooCases3(): iterable {}
- public function provideFooCases2(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- /**
- * @dataProvider provideFooCases
- * @dataProvider provideFooCases3
- * @dataProvider provideFooCases2
- */
- public function testFoo(): void {}
- public function provideFooCases2(): iterable {}
- public function provideFooCases3(): iterable {}
- }
- PHP,
- ];
- yield 'data provider used multiple times II - placement after' => [
- <<<'PHP'
- <?php
- class FooTest {
- /** @dataProvider provideACases */
- public function testA1(): void {}
- /** @dataProvider provideBCases */
- public function testB(): void {}
- public static function provideBCases(): iterable {}
- /** @dataProvider provideACases */
- public function testA2(): void {}
- public static function provideACases(): iterable {}
- }
- PHP,
- ];
- yield 'data provider used multiple times II - placement before' => [
- <<<'PHP'
- <?php
- class FooTest {
- public static function provideACases(): iterable {}
- /** @dataProvider provideACases */
- public function testA2(): void {}
- public static function provideBCases(): iterable {}
- /** @dataProvider provideBCases */
- public function testB(): void {}
- /** @dataProvider provideACases */
- public function testA1(): void {}
- }
- PHP,
- null,
- ['placement' => 'before'],
- ];
- yield 'with other methods - placement after' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- public function testB(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function testB(): void {}
- }
- PHP,
- ];
- yield 'with other methods - placement before' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- public function provideFooCases(): iterable {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function testB(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- public function testB(): void {}
- }
- PHP,
- ['placement' => 'before'],
- ];
- yield 'with other methods II' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- public function testB(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function provideFooCases(): iterable {}
- public function testC(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function testA(): void {}
- public function provideFooCases(): iterable {}
- public function testB(): void {}
- /** @dataProvider provideFooCases */
- public function testFoo(): void {}
- public function testC(): void {}
- }
- PHP,
- ];
- }
- /**
- * @requires PHP ^8.0
- *
- * @param _AutogeneratedInputConfiguration $configuration
- *
- * @dataProvider provideFix80Cases
- */
- public function testFix80(string $expected, ?string $input = null, array $configuration = []): void
- {
- $this->fixer->configure($configuration);
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string, 2?: array<string, string>}>
- */
- public static function provideFix80Cases(): iterable
- {
- yield 'with an attribute between PHPDoc and data provider/test method - placement after' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /**
- * @dataProvider provideFooCases
- */
- #[CustomTestAttribute]
- public function testFoo(): void {}
- #[CustomProviderAttribute]
- public function provideFooCases(): iterable {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- #[CustomProviderAttribute]
- public function provideFooCases(): iterable {}
- /**
- * @dataProvider provideFooCases
- */
- #[CustomTestAttribute]
- public function testFoo(): void {}
- }
- PHP,
- ];
- yield 'with an attribute between PHPDoc and data provider/test method - placement before' => [
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- #[CustomProviderAttribute]
- public function provideFooCases(): iterable {}
- /**
- * @dataProvider provideFooCases
- */
- #[CustomTestAttribute]
- public function testFoo(): void {}
- }
- PHP,
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- /**
- * @dataProvider provideFooCases
- */
- #[CustomTestAttribute]
- public function testFoo(): void {}
- #[CustomProviderAttribute]
- public function provideFooCases(): iterable {}
- }
- PHP,
- ['placement' => 'before'],
- ];
- yield 'data provider defined by an attribute' => [ // update expected once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/8197 is merged
- <<<'PHP'
- <?php
- class FooTest extends TestCase {
- public function provideFooCases(): iterable {}
- #[DataProvider('provideFooCases')]
- public function testFoo(): void {}
- }
- PHP,
- ];
- }
- }
|