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\CodeQuality\Rector\Class_\VoidMethodWithCallbackToWillReturnCallbackRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\VoidMethodWithCallbackToWillReturnCallbackRector\Source\SomeEntityManager;

final class SkipMultipleWithArguments extends TestCase
{
public function test(): void
{
$this->createMock(SomeEntityManager::class)
->method('persist')
->with(
$this->callback(function ($entity): bool {
$this->assertInstanceOf(\stdClass::class, $entity);

return true;
}),
false
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ public function refactor(Node $node): ?Class_

private function matchCallbackClosure(MethodCall $withMethodCall): ?Closure
{
$withFirstArg = $withMethodCall->getArgs()[0] ?? null;
$withArgs = $withMethodCall->getArgs();

// a 2nd+ ->with() argument matches a further parameter, keep the callback matcher as is
if (count($withArgs) > 1) {
return null;
}

$withFirstArg = $withArgs[0] ?? null;
if (! $withFirstArg instanceof Arg) {
return null;
}
Expand Down
Loading