File tree Expand file tree Collapse file tree 2 files changed +55
-3
lines changed
rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture
rules/CodeQuality/Rector/MethodCall Expand file tree Collapse file tree 2 files changed +55
-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 HandleSoloCompare extends TestCase
8+ {
9+ public function test ()
10+ {
11+ $ someMock = $ this ->createMock ('AnyType ' )
12+ ->expects ($ this ->any ())
13+ ->method ('trans ' )
14+ ->with (
15+ $ this ->callback (
16+ fn ($ args ): bool => count ($ args ) === 5
17+ )
18+ );
19+ }
20+ }
21+
22+ ?>
23+ -----
24+ <?php
25+
26+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \WithCallbackIdenticalToStandaloneAssertsRector \Fixture ;
27+
28+ use PHPUnit \Framework \TestCase ;
29+
30+ final class HandleSoloCompare extends TestCase
31+ {
32+ public function test ()
33+ {
34+ $ someMock = $ this ->createMock ('AnyType ' )
35+ ->expects ($ this ->any ())
36+ ->method ('trans ' )
37+ ->with (
38+ $ this ->callback (
39+ function ($ args ): bool {
40+ $ this ->assertCount (5 , $ args );
41+ return true ;
42+ }
43+ )
44+ );
45+ }
46+ }
47+
48+ ?>
Original file line number Diff line number Diff line change 44
55namespace Rector \PHPUnit \CodeQuality \Rector \MethodCall ;
66
7+ use PhpParser \Node \Expr \BinaryOp \Identical ;
78use PhpParser \Node ;
89use PhpParser \Node \ClosureUse ;
910use PhpParser \Node \Expr ;
@@ -38,7 +39,7 @@ public function __construct(
3839 public function getRuleDefinition (): RuleDefinition
3940 {
4041 return new RuleDefinition (
41- 'Replaces identical compare in $this->callable() to standalone PHPUnit asserts ' ,
42+ 'Replaces identical compare in $this->callable() sole return to standalone PHPUnit asserts that show more detailed failure messages ' ,
4243 [
4344 new CodeSample (
4445 <<<'CODE_SAMPLE'
@@ -113,11 +114,14 @@ public function refactor(Node $node): MethodCall|null
113114 }
114115
115116 $ innerSoleExpr = $ this ->matchInnerSoleExpr ($ argAndFunctionLike ->getFunctionLike ());
116- if (! $ innerSoleExpr instanceof BooleanAnd) {
117+ if ($ innerSoleExpr instanceof BooleanAnd) {
118+ $ joinedExprs = $ this ->extractJoinedExprs ($ innerSoleExpr );
119+ } elseif ($ innerSoleExpr instanceof Identical) {
120+ $ joinedExprs = [$ innerSoleExpr ];
121+ } else {
117122 return null ;
118123 }
119124
120- $ joinedExprs = $ this ->extractJoinedExprs ($ innerSoleExpr );
121125 if ($ joinedExprs === null || $ joinedExprs === []) {
122126 return null ;
123127 }
You can’t perform that action at this time.
0 commit comments