Skip to content

Commit dc0c0a7

Browse files
committed
skip setup method in DecorateWillReturnMapWithExpectsMockRector
1 parent 157258e commit dc0c0a7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Expression\DecorateWillReturnMapWithExpectsMockRector\Fixture;
6+
7+
final class SkipFromSetup extends \PHPUnit\Framework\TestCase
8+
{
9+
protected function setUp(): void
10+
{
11+
$someMock = $this->createMock(\stdClass::class);
12+
$someMock->method('some')->willReturnMap([1, 2]);
13+
}
14+
}

rules/CodeQuality/Rector/Expression/DecorateWillReturnMapWithExpectsMockRector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use PhpParser\Node\Identifier;
1313
use PhpParser\Node\Scalar\Int_;
1414
use PhpParser\Node\Stmt\Expression;
15+
use Rector\PHPStan\ScopeFetcher;
1516
use Rector\Rector\AbstractRector;
17+
use Rector\ValueObject\MethodName;
1618
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1719
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1820

@@ -92,6 +94,13 @@ public function refactor(Node $node)
9294
return null;
9395
}
9496

97+
$scope = ScopeFetcher::fetch($node);
98+
99+
// allowed as can be flexible
100+
if ($scope->getFunctionName() === MethodName::SET_UP) {
101+
return null;
102+
}
103+
95104
$topmostCall = $this->resolveTopmostCall($methodCall);
96105

97106
// already covered

0 commit comments

Comments
 (0)