Skip to content

Commit 0238d9c

Browse files
include assert not same not equals (#445)
* include assert not same not equals * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent b987cad commit 0238d9c

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class MySkipTest extends TestCase
8+
{
9+
public function test()
10+
{
11+
$null = null;
12+
$expectedNull = null;
13+
$this->assertEquals($expectedNull, $null);
14+
15+
$bool = true;
16+
$expectedBool = true;
17+
$this->assertEquals($expectedBool, $bool);
18+
}
19+
}
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\FlipAssertRector\Fixture;
4+
5+
final class NotSame extends \PHPUnit\Framework\TestCase
6+
{
7+
public function test()
8+
{
9+
$result = '...';
10+
$this->assertNotSame($result, 'expected');
11+
}
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\FlipAssertRector\Fixture;
19+
20+
final class NotSame extends \PHPUnit\Framework\TestCase
21+
{
22+
public function test()
23+
{
24+
$result = '...';
25+
$this->assertNotSame('expected', $result);
26+
}
27+
}
28+
29+
?>

rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
*/
2121
final class FlipAssertRector extends AbstractRector
2222
{
23+
/**
24+
* @var string[]
25+
*/
26+
private const METHOD_NAMES = [
27+
'assertSame', 'assertNotSame', 'assertNotEquals', 'assertEquals', 'assertStringContainsString',
28+
];
29+
2330
public function __construct(
2431
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
2532
) {
@@ -78,10 +85,7 @@ public function getNodeTypes(): array
7885
*/
7986
public function refactor(Node $node): ?Node
8087
{
81-
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames(
82-
$node,
83-
['assertSame', 'assertEquals', 'assertStringContainsString']
84-
)) {
88+
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, self::METHOD_NAMES)) {
8589
return null;
8690
}
8791

0 commit comments

Comments
 (0)