Skip to content

Commit ef4d30d

Browse files
authored
Skip SkipConstraintValidatorTest (#200)
1 parent 838ffd3 commit ef4d30d

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

src/Enum/SymfonyClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ final class SymfonyClass
3838
public const URL_GENERATOR = 'Symfony\Component\Routing\Generator\UrlGeneratorInterface';
3939

4040
public const COMMAND = 'Symfony\Component\Console\Command\Command';
41+
42+
public const VALIDATOR_TEST_CASE = 'Symfony\Component\Validator\Test\ConstraintValidatorTestCase';
4143
}

src/Rules/PHPUnit/NoMockOnlyTestRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Rules\RuleErrorBuilder;
1414
use Symplify\PHPStanRules\Enum\ClassName;
1515
use Symplify\PHPStanRules\Enum\PHPUnitRuleIdentifier;
16+
use Symplify\PHPStanRules\Enum\SymfonyClass;
1617
use Symplify\PHPStanRules\Testing\PHPUnitTestAnalyser;
1718

1819
/**
@@ -46,6 +47,10 @@ public function processNode(Node $node, Scope $scope): array
4647
return [];
4748
}
4849

50+
if ($classLike->extends instanceof Name && $classLike->extends->toString() === SymfonyClass::VALIDATOR_TEST_CASE) {
51+
return [];
52+
}
53+
4954
if ($classLike->getProperties() === []) {
5055
return [];
5156
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Validator\Test;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
abstract class ConstraintValidatorTestCase extends TestCase
8+
{
9+
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Fixture;
4+
5+
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
6+
use Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Source\FirstClass;
7+
use Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Source\SecondClass;
8+
9+
final class SkipConstraintValidatorTest extends ConstraintValidatorTestCase
10+
{
11+
private \PHPUnit\Framework\MockObject\MockObject $firstMock;
12+
13+
private \PHPUnit\Framework\MockObject\MockObject $secondMock;
14+
15+
public function test()
16+
{
17+
$this->firstMock = $this->createMock(FirstClass::class);
18+
$this->secondMock = $this->createMock(SecondClass::class);
19+
}
20+
}

tests/Rules/PHPUnit/NoMockOnlyTestRule/NoMockOnlyTestRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static function provideData(): Iterator
2828
yield [__DIR__ . '/Fixture/SkipTestWithClass.php', []];
2929
yield [__DIR__ . '/Fixture/SkipNoProperty.php', []];
3030
yield [__DIR__ . '/Fixture/SkipSoleProperty.php', []];
31+
yield [__DIR__ . '/Fixture/SkipConstraintValidatorTest.php', []];
3132
}
3233

3334
protected function getRule(): Rule

tests/Rules/PHPUnit/NoMockOnlyTestRule/Source/FirstClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Source;
44

5-
final class FirstClass
5+
class FirstClass
66
{
77
}

tests/Rules/PHPUnit/NoMockOnlyTestRule/Source/SecondClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace Symplify\PHPStanRules\Tests\Rules\PHPUnit\NoMockOnlyTestRule\Source;
44

5-
final class SecondClass
5+
class SecondClass
66
{
77
}

0 commit comments

Comments
 (0)