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\MethodCall\CallbackSingleAssertToSimplerRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipReferencedUse extends TestCase
{
public function test()
{
$download = null;

$builder = $this->getMockBuilder('AnyType')->getMock();

$builder->expects($this->once())
->method('detach')
->with($this->callback(function ($downloadDetach) use (&$download): bool {
$this->assertSame($downloadDetach, $download);

return true;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ private function matchCallbackSoleAssertSameExpected(Expr $expr): ?Expr
return null;
}

// skip closures capturing by reference, as the referenced value is likely modified above
foreach ($innerClosure->uses as $use) {
if ($use->byRef) {
return null;
}
}

// exactly assertSame() expression + "return true;"
$closureStmts = $innerClosure->getStmts();
if (count($closureStmts) !== 2) {
Expand Down
Loading