Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpUnitTestCaseIndicator - Check if PHPUnit-test class extends anothe… #6295

Merged
merged 1 commit into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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