Skip to content

Commit bd7ac99

Browse files
committed
add fixture
1 parent b4cac76 commit bd7ac99

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
?>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\AllowMockObjectsWithoutExpectationsAttributeRector\Source;
4+
5+
final class SomeFinalClass
6+
{
7+
8+
}

rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PhpParser\Node\Stmt\Class_;
1515
use PhpParser\Node\Stmt\ClassMethod;
1616
use PHPStan\Reflection\ReflectionProvider;
17-
use PHPStan\Type\ObjectType;
1817
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
1918
use Rector\PhpParser\Node\BetterNodeFinder;
2019
use 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;

0 commit comments

Comments
 (0)