File tree Expand file tree Collapse file tree 3 files changed +66
-5
lines changed
rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector
rules/PHPUnit120/Rector/Class_ Expand file tree Collapse file tree 3 files changed +66
-5
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \PHPUnit120 \Rector \Class_ \AllowMockObjectsWithoutExpectationsAttributeRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Rector \PHPUnit \Tests \PHPUnit120 \Rector \Class_ \AllowMockObjectsWithoutExpectationsAttributeRector \Source \SomeFinalClass ;
7+
8+ final class FinalPropertyAsWell extends TestCase
9+ {
10+ private \PHPUnit \Framework \MockObject \MockObject $ someMock ;
11+
12+ protected function setUp (): void
13+ {
14+ $ this ->someMock = $ this ->createMock (SomeFinalClass::class);
15+ $ this ->someMock ->method ('some ' )->willReturn (true );
16+ }
17+
18+ public function testOne ()
19+ {
20+ }
21+
22+ public function testTwo ()
23+ {
24+ }
25+ }
26+
27+ ?>
28+ -----
29+ <?php
30+
31+ namespace Rector \PHPUnit \Tests \PHPUnit120 \Rector \Class_ \AllowMockObjectsWithoutExpectationsAttributeRector \Fixture ;
32+
33+ use PHPUnit \Framework \TestCase ;
34+ use Rector \PHPUnit \Tests \PHPUnit120 \Rector \Class_ \AllowMockObjectsWithoutExpectationsAttributeRector \Source \SomeFinalClass ;
35+
36+ #[\PHPUnit \Framework \Attributes \AllowMockObjectsWithoutExpectations]
37+ final class FinalPropertyAsWell extends TestCase
38+ {
39+ private \PHPUnit \Framework \MockObject \MockObject $ someMock ;
40+
41+ protected function setUp (): void
42+ {
43+ $ this ->someMock = $ this ->createMock (SomeFinalClass::class);
44+ $ this ->someMock ->method ('some ' )->willReturn (true );
45+ }
46+
47+ public function testOne ()
48+ {
49+ }
50+
51+ public function testTwo ()
52+ {
53+ }
54+ }
55+
56+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \PHPUnit120 \Rector \Class_ \AllowMockObjectsWithoutExpectationsAttributeRector \Source ;
4+
5+ final class SomeFinalClass
6+ {
7+
8+ }
Original file line number Diff line number Diff line change 1414use PhpParser \Node \Stmt \Class_ ;
1515use PhpParser \Node \Stmt \ClassMethod ;
1616use PHPStan \Reflection \ReflectionProvider ;
17- use PHPStan \Type \ObjectType ;
1817use Rector \Doctrine \NodeAnalyzer \AttributeFinder ;
1918use Rector \PhpParser \Node \BetterNodeFinder ;
2019use Rector \PHPUnit \Enum \PHPUnitAttribute ;
@@ -298,11 +297,9 @@ private function isMissingExpectsOnMockObjectMethodCallInSetUp(Class_ $class): b
298297 continue ;
299298 }
300299
301- if (! $ this -> isObjectType ( $ methodCall ->var , new ObjectType (PHPUnitClassName:: MOCK_OBJECT )) ) {
302- continue ;
300+ if ($ methodCall -> var instanceof Node \ Expr \Variable || $ methodCall ->var instanceof PropertyFetch ) {
301+ return true ;
303302 }
304-
305- return true ;
306303 }
307304
308305 return false ;
You can’t perform that action at this time.
0 commit comments