forked from phpstan/phpstan-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequiredAutowiringExtensionTest.php
65 lines (55 loc) · 1.8 KB
/
RequiredAutowiringExtensionTest.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
62
63
64
65
<?php declare(strict_types = 1);
namespace PHPStan\Symfony;
use PHPStan\Reflection\AdditionalConstructorsExtension;
use PHPStan\Rules\Properties\UninitializedPropertyRule;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use Symfony\Contracts\Service\Attribute\Required;
use function class_exists;
/**
* @extends RuleTestCase<UninitializedPropertyRule>
*/
final class RequiredAutowiringExtensionTest extends RuleTestCase
{
protected function getRule(): Rule
{
$container = self::getContainer();
$container->getServicesByTag(AdditionalConstructorsExtension::EXTENSION_TAG);
return $container->getByType(UninitializedPropertyRule::class);
}
public function testRequiredAnnotations(): void
{
$this->analyse([__DIR__ . '/data/required-annotations.php'], [
[
'Class RequiredAnnotationTest\TestAnnotations has an uninitialized property $three. Give it default value or assign it in the constructor.',
12,
],
[
'Class RequiredAnnotationTest\TestAnnotations has an uninitialized property $four. Give it default value or assign it in the constructor.',
14,
],
]);
}
public function testRequiredAttributes(): void
{
if (!class_exists(Required::class)) {
self::markTestSkipped('Required symfony/[email protected] or higher is not installed');
}
$this->analyse([__DIR__ . '/data/required-attributes.php'], [
[
'Class RequiredAttributesTest\TestAttributes has an uninitialized property $three. Give it default value or assign it in the constructor.',
14,
],
[
'Class RequiredAttributesTest\TestAttributes has an uninitialized property $four. Give it default value or assign it in the constructor.',
16,
],
]);
}
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/required-autowiring-config.neon',
];
}
}