Skip to content

Commit 5861458

Browse files
committed
skip this variable
1 parent 3368ed4 commit 5861458

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipThis extends TestCase
8+
{
9+
private $expectedValue;
10+
11+
public function test()
12+
{
13+
$expectedValue = 100;
14+
$someMock = $this->getMockBuilder('AnyType')->getMock();
15+
16+
$someMock->expects($this->any())
17+
->method('trans')
18+
->with(
19+
$this->callback(fn ($args): bool => count($args) === 5 && $args[0] === $this->expectedValue)
20+
);
21+
}
22+
}
23+
24+
?>
25+
-----
26+
<?php
27+
28+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector\Fixture;
29+
30+
use PHPUnit\Framework\TestCase;
31+
32+
final class SkipThis extends TestCase
33+
{
34+
private $expectedValue;
35+
36+
public function test()
37+
{
38+
$expectedValue = 100;
39+
$someMock = $this->getMockBuilder('AnyType')->getMock();
40+
41+
$someMock->expects($this->any())
42+
->method('trans')
43+
->with(
44+
$this->callback(function ($args): void {
45+
$this->assertCount(5, $args);
46+
$this->assertSame($this->expectedValue, $args[0]);
47+
})
48+
);
49+
}
50+
}
51+
52+
?>

rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private function resolveExternalClosureUses(ArrowFunction $arrowFunction): array
251251
}
252252

253253
$externalVariableNames = array_unique($externalVariableNames);
254+
$externalVariableNames = array_diff($externalVariableNames, ['this']);
254255

255256
$closureUses = [];
256257
foreach ($externalVariableNames as $externalVariableName) {

0 commit comments

Comments
 (0)