-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathNoGetRepositoryOnServiceRepositoryEntityRuleTest.php
More file actions
49 lines (40 loc) · 1.76 KB
/
NoGetRepositoryOnServiceRepositoryEntityRuleTest.php
File metadata and controls
49 lines (40 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule;
use Iterator;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule;
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule\Source\Repository\SomeServiceRepository;
final class NoGetRepositoryOnServiceRepositoryEntityRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}
public static function provideData(): Iterator
{
$errorMessage = sprintf(NoGetRepositoryOnServiceRepositoryEntityRule::ERROR_MESSAGE, 'SomeEntity', SomeServiceRepository::class);
yield [__DIR__ . '/Fixture/GetRepositoryOnServiceAwareEntity.php', [[
$errorMessage,
14,
]]];
$errorMessage = sprintf(NoGetRepositoryOnServiceRepositoryEntityRule::ERROR_MESSAGE, 'SomeEntity', SomeServiceRepository::class);
yield [__DIR__ . '/Fixture/GetServiceInterfaceRepository.php', [[
$errorMessage,
14,
]]];
yield [__DIR__ . '/Fixture/SkipGetRepositoryOnNormalRepository.php', []];
}
protected function getRule(): Rule
{
$reflectionProvider = self::getContainer()->getByType(ReflectionProvider::class);
return new NoGetRepositoryOnServiceRepositoryEntityRule($reflectionProvider);
}
}