Skip to content

Commit 27a5607

Browse files
authored
skip setup method (#623)
1 parent 21baafa commit 27a5607

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\MethodCall\ExplicitMockExpectsCallRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipAlreadyFilled extends TestCase
8+
{
9+
public function testMethod(): void
10+
{
11+
$someClass = $this->createMock(\stdClass::class);
12+
13+
$someClass->expects($this->once())->method('some');
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\MethodCall\ExplicitMockExpectsCallRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipSetupAsCanBeAny extends TestCase
8+
{
9+
protected function setUp(): void
10+
{
11+
$someClass = $this->createMock(\stdClass::class);
12+
13+
$someClass->method('some');
14+
}
15+
}

rules/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use PhpParser\Node\Expr\PropertyFetch;
1111
use PhpParser\Node\Expr\Variable;
1212
use PHPStan\Type\ObjectType;
13+
use Rector\PHPStan\ScopeFetcher;
1314
use Rector\PHPUnit\Enum\PHPUnitClassName;
1415
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1516
use Rector\Rector\AbstractRector;
17+
use Rector\ValueObject\MethodName;
1618
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1719
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1820

@@ -80,6 +82,11 @@ public function refactor(Node $node): Node|null
8082
return null;
8183
}
8284

85+
$scope = ScopeFetcher::fetch($node);
86+
if ($scope->getFunctionName() === MethodName::SET_UP) {
87+
return null;
88+
}
89+
8390
if (! $node->var instanceof Variable && ! $node->var instanceof PropertyFetch) {
8491
return null;
8592
}

0 commit comments

Comments
 (0)