forked from rectorphp/type-perfect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNarrowPrivateClassMethodParamTypeRuleTest.php
More file actions
69 lines (58 loc) · 2.71 KB
/
NarrowPrivateClassMethodParamTypeRuleTest.php
File metadata and controls
69 lines (58 loc) · 2.71 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule;
use Iterator;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Param;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\TypePerfect\Rules\NarrowPrivateClassMethodParamTypeRule;
final class NarrowPrivateClassMethodParamTypeRuleTest extends RuleTestCase
{
/**
* @param list<array{0: string, 1: int, 2?: string|null}> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SkipDuplicatedCallOfSameMethodWithComment.php', []];
yield [__DIR__ . '/Fixture/SkipCorrectUnionType.php', []];
yield [__DIR__ . '/Fixture/SkipRecursive.php', []];
yield [__DIR__ . '/Fixture/SkipMixed.php', []];
yield [__DIR__ . '/Fixture/SkipOptedOut.php', []];
yield [__DIR__ . '/Fixture/SkipNotFromThis.php', []];
yield [__DIR__ . '/Fixture/SkipParentNotIf.php', []];
yield [__DIR__ . '/Fixture/SkipNoArgs.php', []];
yield [__DIR__ . '/Fixture/SkipAlreadyCorrectType.php', []];
yield [__DIR__ . '/Fixture/SkipMayOverrideArg.php', []];
yield [__DIR__ . '/Fixture/SkipMultipleUsed.php', []];
yield [__DIR__ . '/Fixture/SkipNotPrivate.php', []];
$errorMessage = sprintf(NarrowPrivateClassMethodParamTypeRule::ERROR_MESSAGE, 1, MethodCall::class);
yield [__DIR__ . '/Fixture/Fixture.php', [[$errorMessage, 19]]];
yield [__DIR__ . '/Fixture/DifferentClassSameMethodCallName.php', [[$errorMessage, 25]]];
$argErrorMessage = sprintf(NarrowPrivateClassMethodParamTypeRule::ERROR_MESSAGE, 1, Arg::class);
$paramErrorMessage = sprintf(NarrowPrivateClassMethodParamTypeRule::ERROR_MESSAGE, 2, Param::class);
yield [__DIR__ . '/Fixture/DoubleShot.php', [[$argErrorMessage, 15], [$paramErrorMessage, 15]]];
yield [__DIR__ . '/Fixture/SkipGenericType.php', []];
yield [__DIR__ . '/Fixture/SkipAbstractBase.php', []];
yield [__DIR__ . '/Fixture/SkipVariadics.php', []];
yield [__DIR__ . '/Fixture/SkipSameGeneric.php', []];
}
/**
* @return string[]
*/
public static function getAdditionalConfigFiles(): array
{
return [__DIR__ . '/../../../config/extension.neon'];
}
protected function getRule(): Rule
{
return self::getContainer()->getByType(NarrowPrivateClassMethodParamTypeRule::class);
}
}