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,19 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;

use PHPUnit\Framework\TestCase;

final class MySkipTest extends TestCase
{
public function test()
{
$null = null;
$expectedNull = null;
$this->assertEquals($expectedNull, $null);

$bool = true;
$expectedBool = true;
$this->assertEquals($expectedBool, $bool);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\FlipAssertRector\Fixture;

final class NotSame extends \PHPUnit\Framework\TestCase
{
public function test()
{
$result = '...';
$this->assertNotSame($result, 'expected');
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\FlipAssertRector\Fixture;

final class NotSame extends \PHPUnit\Framework\TestCase
{
public function test()
{
$result = '...';
$this->assertNotSame('expected', $result);
}
}

?>
12 changes: 8 additions & 4 deletions rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/
final class FlipAssertRector extends AbstractRector
{
/**
* @var string[]
*/
private const METHOD_NAMES = [
'assertSame', 'assertNotSame', 'assertNotEquals', 'assertEquals', 'assertStringContainsString',
];

public function __construct(
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
) {
Expand Down Expand Up @@ -78,10 +85,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames(
$node,
['assertSame', 'assertEquals', 'assertStringContainsString']
)) {
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, self::METHOD_NAMES)) {
return null;
}

Expand Down