Skip to content

Commit 55e005a

Browse files
authored
skip NoMockOnlyTestRule if non mock class properties found (#183)
1 parent dd825e8 commit 55e005a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Rules/PHPUnit/NoMockOnlyTestRule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5151
}
5252

5353
$hasExclusivelyMockedProperties = true;
54+
$hasSomeProperties = false;
5455

5556
foreach ($classLike->getProperties() as $property) {
5657
if (! $property->type instanceof Name) {
@@ -61,10 +62,12 @@ public function processNode(Node $node, Scope $scope): array
6162

6263
if ($propertyClassName !== ClassName::MOCK_OBJECT_CLASS) {
6364
$hasExclusivelyMockedProperties = false;
65+
} else {
66+
$hasSomeProperties = true;
6467
}
6568
}
6669

67-
if ($hasExclusivelyMockedProperties === false) {
70+
if ($hasExclusivelyMockedProperties === false || $hasSomeProperties === false) {
6871
return [];
6972
}
7073

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipSoleProperty extends TestCase
8+
{
9+
private array $someItems = [];
10+
}

tests/Rules/PHPUnit/NoMockOnlyTestRule/NoMockOnlyTestRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function provideData(): Iterator
2727

2828
yield [__DIR__ . '/Fixture/SkipTestWithClass.php', []];
2929
yield [__DIR__ . '/Fixture/SkipNoProperty.php', []];
30+
yield [__DIR__ . '/Fixture/SkipSoleProperty.php', []];
3031
}
3132

3233
protected function getRule(): Rule

0 commit comments

Comments
 (0)