/
UsedTraitsRuleTest.php
61 lines (55 loc) · 1.82 KB
/
UsedTraitsRuleTest.php
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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Generics;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
/**
* @extends RuleTestCase<UsedTraitsRule>
*/
class UsedTraitsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new UsedTraitsRule(
self::getContainer()->getByType(FileTypeMapper::class),
new GenericAncestorsCheck(
$this->createReflectionProvider(),
new GenericObjectTypeCheck(),
new VarianceCheck(true),
true,
[],
),
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/used-traits.php'], [
[
'PHPDoc tag @use contains generic type UsedTraits\NongenericTrait<stdClass> but trait UsedTraits\NongenericTrait is not generic.',
20,
],
[
'Type int in generic type UsedTraits\GenericTrait<int> in PHPDoc tag @use is not subtype of template type T of object of trait UsedTraits\GenericTrait.',
31,
],
[
'Class UsedTraits\Baz uses generic trait UsedTraits\GenericTrait but does not specify its types: T',
38,
'You can turn this off by setting <fg=cyan>checkGenericClassInNonGenericObjectType: false</> in your <fg=cyan>%configurationFile%</>.',
],
[
'Generic type UsedTraits\GenericTrait<stdClass, Exception> in PHPDoc tag @use specifies 2 template types, but trait UsedTraits\GenericTrait supports only 1: T',
46,
],
[
'The @use tag of trait UsedTraits\NestedTrait describes UsedTraits\NongenericTrait but the trait uses UsedTraits\GenericTrait.',
54,
],
[
'Trait UsedTraits\NestedTrait uses generic trait UsedTraits\GenericTrait but does not specify its types: T',
54,
'You can turn this off by setting <fg=cyan>checkGenericClassInNonGenericObjectType: false</> in your <fg=cyan>%configurationFile%</>.',
],
]);
}
}