Skip to content

Commit b193eb6

Browse files
committed
covert tearDown in NoSetupWithParentCallOverrideRector as well
1 parent 7a914ca commit b193eb6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\NoSetupWithParentCallOverrideRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class CoverTearDown extends TestCase
8+
{
9+
#[\Override]
10+
protected function tearDown(): void
11+
{
12+
parent::tearDown();
13+
14+
$some = 'value';
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\NoSetupWithParentCallOverrideRector\Fixture;
23+
24+
use PHPUnit\Framework\TestCase;
25+
26+
final class CoverTearDown extends TestCase
27+
{
28+
protected function tearDown(): void
29+
{
30+
parent::tearDown();
31+
$some = 'value';
32+
}
33+
}
34+
35+
?>

rules/CodeQuality/Rector/ClassMethod/NoSetupWithParentCallOverrideRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Rector\PHPUnit\CodeQuality\NodeAnalyser\ParentCallDetector;
1111
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1212
use Rector\Rector\AbstractRector;
13+
use Rector\ValueObject\MethodName;
1314
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1415
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1516

@@ -28,7 +29,7 @@ public function __construct(
2829
public function getRuleDefinition(): RuleDefinition
2930
{
3031
return new RuleDefinition(
31-
'Remove override, if setUp() references parent::setUp() call to improve readability',
32+
'Remove override attribute, if setUp()/tearDown() references parent call to improve readability',
3233
[
3334
new CodeSample(
3435
<<<'CODE_SAMPLE'
@@ -82,7 +83,7 @@ public function refactor(Node $node): ?Node
8283
return null;
8384
}
8485

85-
if (! $this->isName($node, 'setUp')) {
86+
if (! $this->isNames($node, ['setUp', 'tearDown'])) {
8687
return null;
8788
}
8889

0 commit comments

Comments
 (0)