Skip to content

Commit 4dfb448

Browse files
[AssertCompareToSpecificMethodRector ] Remove inversion of parameters in Assert calls (#423)
* Remove inversion of parameters * Refacto
1 parent 9fe16ab commit 4dfb448

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

rules-tests/CodeQuality/Rector/MethodCall/AssertCompareToSpecificMethodRector/Fixture/get_class.php.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ final class GetClass extends \PHPUnit\Framework\TestCase
99
public function test()
1010
{
1111
$something = new stdClass();
12-
$this->assertSame(get_class($something), 'stdClass');
1312
self::assertSame('stdClass', get_class($something));
1413
}
1514
}
@@ -27,7 +26,6 @@ final class GetClass extends \PHPUnit\Framework\TestCase
2726
public function test()
2827
{
2928
$something = new stdClass();
30-
$this->assertInstanceOf('stdClass', $something);
3129
self::assertInstanceOf('stdClass', $something);
3230
}
3331
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCompareToSpecificMethodRector\Fixture;
4+
5+
final class SkipFirstParam extends \PHPUnit\Framework\TestCase
6+
{
7+
public function test()
8+
{
9+
$this->assertSame(count($something), 5);
10+
$this->assertSame(get_class($something), 'stdClass');
11+
}
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCompareToSpecificMethodRector\Fixture;
19+
20+
final class SkipFirstParam extends \PHPUnit\Framework\TestCase
21+
{
22+
public function test()
23+
{
24+
$this->assertSame(count($something), 5);
25+
$this->assertSame(get_class($something), 'stdClass');
26+
}
27+
}
28+
29+
?>

rules/CodeQuality/Rector/MethodCall/AssertCompareToSpecificMethodRector.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getRuleDefinition(): RuleDefinition
5757
'$this->assertCount(10, $anything, "message");'
5858
),
5959
new CodeSample(
60-
'$this->assertNotEquals(get_class($value), SomeInstance::class);',
60+
'$this->assertNotEquals(SomeInstance::class, get_class($value));',
6161
'$this->assertNotInstanceOf(SomeInstance::class, $value);'
6262
),
6363
]
@@ -95,18 +95,12 @@ public function refactor(Node $node): ?Node
9595

9696
$firstArgument = $node->getArgs()[0];
9797
$secondArgument = $node->getArgs()[1];
98-
99-
$firstArgumentValue = $firstArgument->value;
10098
$secondArgumentValue = $secondArgument->value;
10199

102100
if ($secondArgumentValue instanceof FuncCall) {
103101
return $this->processFuncCallArgumentValue($node, $secondArgumentValue, $firstArgument);
104102
}
105103

106-
if ($firstArgumentValue instanceof FuncCall) {
107-
return $this->processFuncCallArgumentValue($node, $firstArgumentValue, $secondArgument);
108-
}
109-
110104
return null;
111105
}
112106

0 commit comments

Comments
 (0)