Skip to content

Commit db71441

Browse files
authored
[CodeQuality] Skip assertEquals() on integer to numeric string on MatchAssertSameExpectedTypeRector (#522)
1 parent 57a7e1d commit db71441

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getRuleDefinition(): RuleDefinition
3636
3737
class SomeTest extends TestCase
3838
{
39-
public function run()
39+
public function test()
4040
{
4141
$this->assertSame('123', $this->getOrderId());
4242
}
@@ -53,7 +53,7 @@ private function getOrderId(): int
5353
5454
class SomeTest extends TestCase
5555
{
56-
public function run()
56+
public function test()
5757
{
5858
$this->assertSame(123, $this->getOrderId());
5959
}
@@ -115,6 +115,10 @@ public function refactor(Node $node): ?Node
115115
}
116116

117117
if ($expectedType->isInteger()->yes() && $directVariableType->isString()->yes()) {
118+
if ($this->isName($node->name, 'assertEquals')) {
119+
return null;
120+
}
121+
118122
// update expected type to provided type
119123
$expectedArg->value = new String_((string) $expectedArg->value->value);
120124

tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\Issues\AssertEqualsSame;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
class SkipAssertEqualsIntegerToString extends TestCase
10+
{
11+
public function test()
12+
{
13+
$this->assertEquals(123, $this->getOrderId());
14+
}
15+
16+
private function getOrderId(): string
17+
{
18+
return '0000000000000000000123';
19+
}
20+
}

0 commit comments

Comments
 (0)