File tree Expand file tree Collapse file tree 2 files changed +28
-9
lines changed
rules-tests/PHPUnit120/Rector/CallLike/CreateStubOverCreateMockArgRector/Fixture
rules/PHPUnit120/Rector/CallLike Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \PHPUnit120 \Rector \CallLike \CreateStubOverCreateMockArgRector \Fixture ;
4+
5+ use PHPUnit \Framework \MockObject \MockObject ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ final class SkipPropertyFetch extends TestCase
9+ {
10+ private MockObject $ item ;
11+
12+ public function testThat ()
13+ {
14+ $ this ->item = $ this ->createMock (\stdClass::class);
15+ }
16+
17+ public function testUsedMock ()
18+ {
19+ $ this ->item ->expects ($ this ->atLeastOnce ())->method ('someMethod ' )->willReturn (123 );
20+ }
21+ }
Original file line number Diff line number Diff line change 1414use PhpParser \Node \Identifier ;
1515use PhpParser \Node \Stmt \ClassMethod ;
1616use PhpParser \Node \Stmt \Expression ;
17- use Rector \PHPStan \ScopeFetcher ;
1817use Rector \PHPUnit \CodeQuality \NodeAnalyser \MockObjectExprDetector ;
19- use Rector \PHPUnit \Enum \PHPUnitClassName ;
2018use Rector \PHPUnit \NodeAnalyzer \TestsNodeAnalyzer ;
2119use Rector \Rector \AbstractRector ;
2220use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -90,13 +88,7 @@ public function getNodeTypes(): array
9088 */
9189 public function refactor (Node $ node ): MethodCall |StaticCall |New_ |ArrayItem |ClassMethod |null
9290 {
93- $ scope = ScopeFetcher::fetch ($ node );
94- if (! $ scope ->isInClass ()) {
95- return null ;
96- }
97-
98- $ classReflection = $ scope ->getClassReflection ();
99- if (! $ classReflection ->is (PHPUnitClassName::TEST_CASE )) {
91+ if (! $ this ->testsNodeAnalyzer ->isInTestClass ($ node )) {
10092 return null ;
10193 }
10294
@@ -165,6 +157,12 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
165157 }
166158
167159 $ assign = $ stmt ->expr ;
160+
161+ // handled in another rule
162+ if ($ assign ->var instanceof Expr \PropertyFetch) {
163+ continue ;
164+ }
165+
168166 $ createMockMethodCall = $ this ->matchCreateMockMethodCall ($ assign ->expr );
169167
170168 if (! $ createMockMethodCall instanceof MethodCall) {
You can’t perform that action at this time.
0 commit comments