Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

final class SkipPropertyFetch extends TestCase
{
private MockObject $item;

public function testThat()
{
$this->item = $this->createMock(\stdClass::class);
}

public function testUsedMock()
{
$this->item->expects($this->atLeastOnce())->method('someMethod')->willReturn(123);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\PHPUnit\PHPUnit120\Rector\CallLike;

use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
Expand All @@ -14,9 +15,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\PHPStan\ScopeFetcher;
use Rector\PHPUnit\CodeQuality\NodeAnalyser\MockObjectExprDetector;
use Rector\PHPUnit\Enum\PHPUnitClassName;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -90,13 +89,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): MethodCall|StaticCall|New_|ArrayItem|ClassMethod|null
{
$scope = ScopeFetcher::fetch($node);
if (! $scope->isInClass()) {
return null;
}

$classReflection = $scope->getClassReflection();
if (! $classReflection->is(PHPUnitClassName::TEST_CASE)) {
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}

Expand Down Expand Up @@ -165,6 +158,12 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
}

$assign = $stmt->expr;

// handled in another rule
if ($assign->var instanceof PropertyFetch) {
continue;
}

$createMockMethodCall = $this->matchCreateMockMethodCall($assign->expr);

if (! $createMockMethodCall instanceof MethodCall) {
Expand Down