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,23 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipPropertyUsedInClosure extends TestCase
{
private \PHPUnit\Framework\MockObject\MockObject $someMock;

protected function setUp(): void
{
$this->someMock = $this->createMock(\stdClass::class);
}

public function testThis()
{
$builder = $this->createMock(\stdClass::class);
$builder->method('addEventListener')->willReturnCallback(function () {
$this->someMock->expects($this->once())->method('something');
});
}
}
5 changes: 3 additions & 2 deletions rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public function isPropertyUsedForMocking(Class_ $class, string $propertyName): b
return true;
}

// find out, how many are used in call likes as args
// find out, how many are used in call likes as args;
// not scoped on purpose, as expects() can be nested in closures, e.g. willReturnCallback()
/** @var array<Expr\MethodCall> $methodCalls */
$methodCalls = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), [MethodCall::class]);
$methodCalls = $this->betterNodeFinder->findInstancesOf($class->getMethods(), [MethodCall::class]);

foreach ($methodCalls as $methodCall) {
if (! $methodCall->var instanceof PropertyFetch) {
Expand Down
Loading