Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AssertEqualsToSameRector #5800

Merged
merged 5 commits into from
Mar 9, 2021
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
16 changes: 2 additions & 14 deletions rules/phpunit/src/Rector/MethodCall/AssertEqualsToSameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
namespace Rector\PHPUnit\Rector\MethodCall;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\Scope;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\StaticInstanceOf;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Renaming\NodeManipulator\IdentifierManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -38,7 +34,7 @@ final class AssertEqualsToSameRector extends AbstractRector
* - bool because this is taken care of AssertEqualsParameterToSpecificMethodsTypeRector
* - null because this is taken care of AssertEqualsParameterToSpecificMethodsTypeRector
*
* @var array<class-string<Type>>
* @var array<class-string<\PHPStan\Type\Type>>
*/
private const SCALAR_TYPES = [FloatType::class, IntegerType::class, StringType::class];

Expand Down Expand Up @@ -102,7 +98,7 @@ public function refactor(Node $node): ?Node
}

$valueNode = $node->args[0];
$valueNodeType = $this->getNodeType($valueNode->value);
$valueNodeType = $this->nodeTypeResolver->resolve($valueNode->value);
if (! StaticInstanceOf::isOneOf($valueNodeType, self::SCALAR_TYPES)) {
return null;
}
Expand All @@ -111,12 +107,4 @@ public function refactor(Node $node): ?Node

return $node;
}

private function getNodeType(Expr $expr): Type
{
/** @var Scope $nodeScope */
$nodeScope = $expr->getAttribute(AttributeKey::SCOPE);

return $nodeScope->getType($expr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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

use PHPUnit\Framework\TestCase;

final class TestIncomplete extends TestCase
{
public function test()
{
$this->markTestIncomplete('incomplete');

$this->assertEquals('foo', 'foo');
$this->assertEquals(123, 123);
$this->assertEquals(1.23, 1.23);
}
}

?>
-----
<?php

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

use PHPUnit\Framework\TestCase;

final class TestIncomplete extends TestCase
{
public function test()
{
$this->markTestIncomplete('incomplete');

$this->assertSame('foo', 'foo');
$this->assertSame(123, 123);
$this->assertSame(1.23, 1.23);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

use PHPUnit\Framework\TestCase;

final class TestSkipped extends TestCase
{
public function test()
{
$this->markTestSkipped('skipped');
$this->assertEquals('foo', 'foo');
$this->assertEquals(123, 123);
$this->assertEquals(1.23, 1.23);
}
}

?>
-----
<?php

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

use PHPUnit\Framework\TestCase;

final class TestSkipped extends TestCase
{
public function test()
{
$this->markTestSkipped('skipped');
$this->assertSame('foo', 'foo');
$this->assertSame(123, 123);
$this->assertSame(1.23, 1.23);
}
}

?>