File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ final class CoverEqual extends TestCase
8+ {
9+ public function test ($ type )
10+ {
11+ $ this ->createMock ('SomeType ' )
12+ ->method ('someMethod ' )
13+ ->with ($ this ->callback (
14+ fn ($ item ): bool => $ item instanceof $ type &&
15+ $ item ->getName () == 'name '
16+ ));
17+ }
18+ }
19+
20+ ?>
21+ -----
22+ <?php
23+
24+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
25+
26+ use PHPUnit \Framework \TestCase ;
27+
28+ final class CoverEqual extends TestCase
29+ {
30+ public function test ($ type )
31+ {
32+ $ this ->createMock ('SomeType ' )
33+ ->method ('someMethod ' )
34+ ->with ($ this ->callback (
35+ function ($ item ) use ($ type ): bool {
36+ $ this ->assertInstanceOf ($ type , $ item );
37+ $ this ->assertEquals ('name ' , $ item ->getName ());
38+ return true ;
39+ }
40+ ));
41+ }
42+ }
43+
44+ ?>
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public function create(array $exprs): ?array
8484 continue ;
8585 }
8686
87- if ($ expr instanceof Identical) {
87+ if ($ expr instanceof Identical || $ expr instanceof Expr \ BinaryOp \Equal ) {
8888 if ($ expr ->left instanceof FuncCall && $ this ->nodeNameResolver ->isName ($ expr ->left , 'count ' )) {
8989 if ($ expr ->right instanceof Int_) {
9090 $ countedExpr = $ expr ->left ->getArgs ()[0 ]
@@ -107,7 +107,7 @@ public function create(array $exprs): ?array
107107 // create assertSame()
108108 $ assertMethodCalls [] = $ this ->nodeFactory ->createMethodCall (
109109 'this ' ,
110- 'assertSame ' ,
110+ $ expr instanceof Identical ? 'assertSame ' : ' assertEquals ' ,
111111 [$ expr ->right , $ expr ->left ]
112112 );
113113 } else {
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ public function refactor(Node $node): MethodCall|null
122122 } elseif ($ innerSoleExpr instanceof Identical || $ innerSoleExpr instanceof Instanceof_ || $ innerSoleExpr instanceof Isset_ || ($ innerSoleExpr instanceof FuncCall && $ this ->isName (
123123 $ innerSoleExpr ->name ,
124124 'array_key_exists '
125- ))) {
125+ )) || $ innerSoleExpr instanceof Expr \ BinaryOp \Equal ) {
126126 $ joinedExprs = [$ innerSoleExpr ];
127127 } else {
128128 return null ;
You can’t perform that action at this time.
0 commit comments