|
@@ -24,10 +24,7 @@ use PhpCsFixer\Tokenizer\Tokens;
|
|
|
*/
|
|
|
final class PhpUnitTestCaseIndicatorTest extends TestCase
|
|
|
{
|
|
|
- /**
|
|
|
- * @var null|PhpUnitTestCaseIndicator
|
|
|
- */
|
|
|
- private $indicator;
|
|
|
+ private ?PhpUnitTestCaseIndicator $indicator;
|
|
|
|
|
|
protected function setUp(): void
|
|
|
{
|
|
@@ -51,75 +48,94 @@ final class PhpUnitTestCaseIndicatorTest extends TestCase
|
|
|
static::assertSame($expected, $this->indicator->isPhpUnitClass($tokens, $index));
|
|
|
}
|
|
|
|
|
|
- public function provideIsPhpUnitClassCases(): array
|
|
|
+ public function provideIsPhpUnitClassCases(): iterable
|
|
|
{
|
|
|
- return [
|
|
|
- 'Test class' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php final class MyTest {}'),
|
|
|
- 3,
|
|
|
- ],
|
|
|
- 'TestCase class' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php final class SomeTestCase {}'),
|
|
|
- 3,
|
|
|
- ],
|
|
|
- 'Extends Test' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php final class foo extends Test {}'),
|
|
|
- 3,
|
|
|
- ],
|
|
|
- 'Extends TestCase' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php final class bar extends TestCase {}'),
|
|
|
- 3,
|
|
|
- ],
|
|
|
- 'Implements AbstractFixerTest' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php
|
|
|
+ yield 'Test class' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php final class MyTest extends A {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'TestCase class' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php final class SomeTestCase extends A {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Extends Test' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php final class foo extends Test {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Extends TestCase' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php final class bar extends TestCase {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Implements AbstractFixerTest' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php
|
|
|
class A extends Foo implements PhpCsFixer\Tests\Fixtures\Test\AbstractFixerTest
|
|
|
{
|
|
|
}
|
|
|
'),
|
|
|
- 1,
|
|
|
- ],
|
|
|
- 'Extends TestCase implements Foo' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php
|
|
|
+ 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Extends TestCase implements Foo' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php
|
|
|
class A extends TestCase implements Foo
|
|
|
{
|
|
|
}
|
|
|
'),
|
|
|
- 1,
|
|
|
- ],
|
|
|
- 'Implements TestInterface' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php
|
|
|
-class Foo implements SomeTestInterface
|
|
|
+ 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Implements TestInterface' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php
|
|
|
+class Foo extends A implements SomeTestInterface
|
|
|
{
|
|
|
}
|
|
|
'),
|
|
|
- 1,
|
|
|
- ],
|
|
|
- 'Implements TestInterface, SomethingElse' => [
|
|
|
- true,
|
|
|
- Tokens::fromCode('<?php
|
|
|
-class Foo implements TestInterface, SomethingElse
|
|
|
+ 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Implements TestInterface, SomethingElse' => [
|
|
|
+ true,
|
|
|
+ Tokens::fromCode('<?php
|
|
|
+class Foo extends A implements TestInterface, SomethingElse
|
|
|
{
|
|
|
}
|
|
|
'),
|
|
|
- 1,
|
|
|
- ],
|
|
|
- [
|
|
|
- false,
|
|
|
- Tokens::fromCode('<?php final class MyClass {}'),
|
|
|
- 3,
|
|
|
- ],
|
|
|
- 'Anonymous class' => [
|
|
|
- false,
|
|
|
- Tokens::fromCode('<?php $a = new class {};'),
|
|
|
- 7,
|
|
|
- ],
|
|
|
+ 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield [
|
|
|
+ false,
|
|
|
+ Tokens::fromCode('<?php final class MyClass {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Anonymous class' => [
|
|
|
+ false,
|
|
|
+ Tokens::fromCode('<?php $a = new class {};'),
|
|
|
+ 7,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'Test class that does not extends' => [
|
|
|
+ false,
|
|
|
+ Tokens::fromCode('<?php final class MyTest {}'),
|
|
|
+ 3,
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'TestCase class that does not extends' => [
|
|
|
+ false,
|
|
|
+ Tokens::fromCode('<?php final class SomeTestCase implements PhpCsFixer\Tests\Fixtures\Test\AbstractFixerTest {}'),
|
|
|
+ 3,
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -148,64 +164,68 @@ class Foo implements TestInterface, SomethingElse
|
|
|
static::assertSame($expectedIndexes, $classes);
|
|
|
}
|
|
|
|
|
|
- public function provideFindPhpUnitClassesCases(): array
|
|
|
+ public function provideFindPhpUnitClassesCases(): iterable
|
|
|
{
|
|
|
- return [
|
|
|
- 'empty' => [
|
|
|
- [],
|
|
|
- '',
|
|
|
- ],
|
|
|
- 'empty script' => [
|
|
|
- [],
|
|
|
- "<?php\n",
|
|
|
- ],
|
|
|
- 'no test class' => [
|
|
|
- [],
|
|
|
- '<?php class Foo{}',
|
|
|
- ],
|
|
|
- 'single test class' => [
|
|
|
- [
|
|
|
- [6, 7],
|
|
|
- ],
|
|
|
- '<?php
|
|
|
- class MyTest {}
|
|
|
- ',
|
|
|
- ],
|
|
|
- 'two PHPUnit classes' => [
|
|
|
- [
|
|
|
- [13, 26],
|
|
|
- [6, 7],
|
|
|
- ],
|
|
|
- '<?php
|
|
|
- class My1Test {}
|
|
|
- class My2Test { public function A() {} }
|
|
|
- ',
|
|
|
+ yield 'empty' => [
|
|
|
+ [],
|
|
|
+ '',
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'empty script' => [
|
|
|
+ [],
|
|
|
+ "<?php\n",
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'no test class' => [
|
|
|
+ [],
|
|
|
+ '<?php class Foo{}',
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'single test class' => [
|
|
|
+ [
|
|
|
+ [10, 11],
|
|
|
],
|
|
|
- 'mixed classes' => [
|
|
|
- [
|
|
|
- [63, 76],
|
|
|
- [25, 38],
|
|
|
- ],
|
|
|
- '<?php
|
|
|
- class Foo1 { public function A() {} }
|
|
|
- class My1Test { public function A() {} }
|
|
|
- class Foo2 { public function A() {} }
|
|
|
- class My2Test { public function A() {} }
|
|
|
- class Foo3 { public function A() { return function (){}; } }
|
|
|
- ',
|
|
|
+ '<?php
|
|
|
+ class MyTest extends Foo {}
|
|
|
+ ',
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'two PHPUnit classes' => [
|
|
|
+ [
|
|
|
+ [21, 34],
|
|
|
+ [10, 11],
|
|
|
],
|
|
|
- 'class with anonymous class inside' => [
|
|
|
- [],
|
|
|
- '<?php
|
|
|
- class Foo
|
|
|
+ '<?php
|
|
|
+ class My1Test extends Foo1 {}
|
|
|
+ class My2Test extends Foo2 { public function A8() {} }
|
|
|
+ ',
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'mixed classes' => [
|
|
|
+ [
|
|
|
+ [71, 84],
|
|
|
+ [29, 42],
|
|
|
+ ],
|
|
|
+ '<?php
|
|
|
+ class Foo1 { public function A1() {} }
|
|
|
+ class My1Test extends Foo1 { public function A2() {} }
|
|
|
+ class Foo2 { public function A3() {} }
|
|
|
+ class My2Test extends Foo2 { public function A4() {} }
|
|
|
+ class Foo3 { public function A5() { return function (){}; } }
|
|
|
+ ',
|
|
|
+ ];
|
|
|
+
|
|
|
+ yield 'class with anonymous class inside' => [
|
|
|
+ [],
|
|
|
+ '<?php
|
|
|
+ class Foo
|
|
|
+ {
|
|
|
+ public function getClass()
|
|
|
{
|
|
|
- public function getClass()
|
|
|
- {
|
|
|
- return new class {};
|
|
|
- }
|
|
|
+ return new class {};
|
|
|
}
|
|
|
- ',
|
|
|
- ],
|
|
|
+ }
|
|
|
+ ',
|
|
|
];
|
|
|
}
|
|
|
}
|