File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector
rules/CodeQuality/Rector/MethodCall Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \AssertEqualsToSameRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \AssertEqualsToSameRector \Source \SimpleStringable ;
7+
8+ final class SkipStringableObject extends TestCase
9+ {
10+ public function test ()
11+ {
12+ $ this ->assertEquals ('value ' , new SimpleStringable ());
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \AssertEqualsToSameRector \Source ;
4+
5+ use Stringable ;
6+
7+ final class SimpleStringable implements Stringable
8+ {
9+ public function __toString ()
10+ {
11+ return 'value ' ;
12+ }
13+ }
Original file line number Diff line number Diff line change 1616use PHPStan \Type \FloatType ;
1717use PHPStan \Type \IntegerType ;
1818use PHPStan \Type \MixedType ;
19+ use PHPStan \Type \ObjectType ;
1920use PHPStan \Type \StringType ;
2021use PHPStan \Type \Type ;
2122use PHPStan \Type \TypeCombinator ;
@@ -49,7 +50,7 @@ final class AssertEqualsToSameRector extends AbstractRector
4950
5051 public function __construct (
5152 private readonly IdentifierManipulator $ identifierManipulator ,
52- private readonly TestsNodeAnalyzer $ testsNodeAnalyzer
53+ private readonly TestsNodeAnalyzer $ testsNodeAnalyzer,
5354 ) {
5455 }
5556
@@ -113,6 +114,13 @@ public function refactor(Node $node): ?Node
113114 if ($ firstArgType instanceof FloatType && ($ secondArgType instanceof IntegerType || $ secondArgType instanceof MixedType)) {
114115 return null ;
115116 }
117+
118+ if ($ firstArgType instanceof StringType && $ secondArgType instanceof ObjectType && $ this ->isObjectType (
119+ $ node ->args [1 ]->value ,
120+ new ObjectType ('Stringable ' )
121+ )) {
122+ return null ;
123+ }
116124 }
117125
118126 $ hasChanged = $ this ->identifierManipulator ->renameNodeWithMap ($ node , self ::RENAME_METHODS_MAP );
You can’t perform that action at this time.
0 commit comments