Skip to content

Commit

Permalink
minor #6295 PhpUnitTestCaseIndicator - Check if PHPUnit-test class ex…
Browse files Browse the repository at this point in the history
…tends anothe… (SpacePossum)

This PR was merged into the master branch.

Discussion
----------

PhpUnitTestCaseIndicator - Check if PHPUnit-test class extends anothe…

…r class

closes #6016

Commits
-------

7d4b0b0 PhpUnitTestCaseIndicator - Check if PHPUnit-test class extends another class
  • Loading branch information
SpacePossum committed Feb 21, 2022
2 parents 7df9f15 + 7d4b0b0 commit 7528a4e
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 132 deletions.
6 changes: 6 additions & 0 deletions src/Indicator/PhpUnitTestCaseIndicator.php
Expand Up @@ -34,6 +34,12 @@ public function isPhpUnitClass(Tokens $tokens, int $index): bool
return false;
}

$extendsIndex = $tokens->getNextTokenOfKind($index, ['{', [T_EXTENDS]]);

if (!$tokens[$extendsIndex]->isGivenKind(T_EXTENDS)) {
return false;
}

if (0 !== Preg::match('/(?:Test|TestCase)$/', $tokens[$index]->getContent())) {
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php
Expand Up @@ -276,7 +276,7 @@ class Test extends TestCase
'By default it will not mark an abstract class as internal' => [
'<?php
abstract class Test
abstract class Test extends TestCase
{
}
',
Expand All @@ -287,13 +287,13 @@ abstract class Test
/**
* @internal
*/
abstract class Test
abstract class Test extends TestCase
{
}
',
'<?php
abstract class Test
abstract class Test extends TestCase
{
}
',
Expand All @@ -304,7 +304,7 @@ abstract class Test
'If final is not added as an option, final classes will not be marked internal' => [
'<?php
final class Test
final class Test extends TestCase
{
}
',
Expand All @@ -316,7 +316,7 @@ final class Test
'If normal is not added as an option, normal classes will not be marked internal' => [
'<?php
class Test
class Test extends TestCase
{
}
',
Expand All @@ -331,11 +331,11 @@ class Test
/**
* @internal
*/
class Test
class Test extends TestCase
{
}
abstract class Test
abstract class Test2 extends TestCase
{
}
Expand All @@ -352,11 +352,11 @@ class Test extends TestCase
',
'<?php
class Test
class Test extends TestCase
{
}
abstract class Test
abstract class Test2 extends TestCase
{
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php
Expand Up @@ -273,11 +273,11 @@ abstract class Test
/**
* @small
*/
class Test
class Test extends TestCase
{
}
abstract class Test
abstract class Test2 extends TestCase
{
}
Expand All @@ -288,25 +288,25 @@ class FooBar
/**
* @small
*/
class Test extends TestCase
class Test3 extends TestCase
{
}
',
'<?php
class Test
class Test extends TestCase
{
}
abstract class Test
abstract class Test2 extends TestCase
{
}
class FooBar
{
}
class Test extends TestCase
class Test3 extends TestCase
{
}
',
Expand Down
Expand Up @@ -4,15 +4,15 @@ Integration of fixers: php_unit_test_annotation,no_empty_phpdoc.
{"php_unit_test_annotation": true, "no_empty_phpdoc" : true}
--EXPECT--
<?php
class Test
class Test extends TestCase
{

public function testFooBar() {}
}

--INPUT--
<?php
class Test
class Test extends TestCase
{
/**
* @test
Expand Down
Expand Up @@ -4,7 +4,7 @@ Integration of fixers: php_unit_test_annotation,php_unit_method_casing.
{"php_unit_test_annotation": true, "php_unit_method_casing" : {"case": "snake_case"}}
--EXPECT--
<?php
class Test
class Test extends TestCase
{
/**
* It does thing for foo and bar
Expand All @@ -15,7 +15,7 @@ class Test

--INPUT--
<?php
class Test
class Test extends TestCase
{
/**
* It does thing for foo and bar
Expand Down
Expand Up @@ -4,7 +4,7 @@ Integration of fixers: php_unit_test_annotation,phpdoc_trim.
{"php_unit_test_annotation": true, "phpdoc_trim" : true}
--EXPECT--
<?php
class Test
class Test extends TestCase
{
/**
* It does thing for foo and bar
Expand All @@ -14,7 +14,7 @@ class Test

--INPUT--
<?php
class Test
class Test extends TestCase
{
/**
* It does thing for foo and bar
Expand Down

0 comments on commit 7528a4e

Please sign in to comment.