Skip to content

Commit

Permalink
[CodeQuality] Skip compare to mixed on AssertEqualsToSameRector (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Dec 25, 2024
1 parent e01f748 commit 674248c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;

final class AssertSameConstantArray extends TestCase
{
public function test($result)
public function test(array $result)
{
$expected = [1 => 2];
$this->assertEquals($expected, $result);
Expand All @@ -23,7 +23,7 @@ use PHPUnit\Framework\TestCase;

final class AssertSameConstantArray extends TestCase
{
public function test($result)
public function test(array $result)
{
$expected = [1 => 2];
$this->assertSame($expected, $result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\

final class ClassConstant extends TestCase
{
public function test($result)
public function test(string $result)
{
$this->assertEquals(SimpleConstantList::BOTTOM, $result);
}
Expand All @@ -26,7 +26,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\

final class ClassConstant extends TestCase
{
public function test($result)
public function test(string $result)
{
$this->assertSame(SimpleConstantList::BOTTOM, $result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\

final class Php80Enum extends TestCase
{
public function test($result)
public function test(string $result)
{
$this->assertEquals(SimpleEnum::LEFT, $result);
}
Expand All @@ -24,7 +24,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\

final class Php80Enum extends TestCase
{
public function test($result)
public function test(string $result)
{
$this->assertSame(SimpleEnum::LEFT, $result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use PHPUnit\Framework\TestCase;

final class SkipCompareMixed extends TestCase
{
public function test(mixed $result)
{
$this->assertEquals('test', $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public function refactor(Node $node): ?Node
$secondArgType = TypeCombinator::removeNull($this->nodeTypeResolver->getNativeType($args[1]->value));

// loose comparison
if ($firstArgType instanceof IntegerType && ($secondArgType instanceof FloatType || $secondArgType instanceof MixedType)) {
if ($firstArgType instanceof IntegerType && $secondArgType instanceof FloatType) {
return null;
}

if ($firstArgType instanceof FloatType && ($secondArgType instanceof IntegerType || $secondArgType instanceof MixedType)) {
if ($firstArgType instanceof FloatType && $secondArgType instanceof IntegerType) {
return null;
}

Expand All @@ -121,6 +121,11 @@ public function refactor(Node $node): ?Node
)) {
return null;
}

// compare to mixed type is can be anything
if ($secondArgType instanceof MixedType) {
return null;
}
}

$hasChanged = $this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);
Expand Down

0 comments on commit 674248c

Please sign in to comment.