-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathAccessStaticPropertiesInAssignRuleTest.php
More file actions
107 lines (97 loc) · 2.78 KB
/
AccessStaticPropertiesInAssignRuleTest.php
File metadata and controls
107 lines (97 loc) · 2.78 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\ClassCaseSensitivityCheck;
use PHPStan\Rules\ClassForbiddenNameCheck;
use PHPStan\Rules\ClassNameCheck;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<AccessStaticPropertiesInAssignRule>
*/
class AccessStaticPropertiesInAssignRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$reflectionProvider = self::createReflectionProvider();
return new AccessStaticPropertiesInAssignRule(
new AccessStaticPropertiesCheck(
$reflectionProvider,
new RuleLevelHelper(
$reflectionProvider,
checkNullables: true,
checkThisOnly: false,
checkUnionTypes: true,
checkExplicitMixed: false,
checkImplicitMixed: false,
checkBenevolentUnionTypes: false,
discoveringSymbolsTip: true,
),
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
$reflectionProvider,
self::getContainer(),
),
new PhpVersion(PHP_VERSION_ID),
discoveringSymbolsTip: true,
),
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/access-static-properties-assign.php'], [
[
'Access to an undefined static property TestAccessStaticPropertiesAssign\AccessStaticPropertyWithDimFetch::$foo.',
10,
],
[
'Access to an undefined static property TestAccessStaticPropertiesAssign\AccessStaticPropertyWithDimFetch::$foo.',
15,
],
]);
}
public function testRuleAssignOp(): void
{
$this->analyse([__DIR__ . '/data/access-static-properties-assign-op.php'], [
[
'Access to an undefined static property AccessStaticProperties\AssignOpNonexistentProperty::$flags.',
15,
],
]);
}
public function testRuleExpressionNames(): void
{
$this->analyse([__DIR__ . '/data/properties-from-array-into-static-object.php'], [
[
'Access to an undefined static property PropertiesFromArrayIntoStaticObject\Foo::$noop.',
29,
],
]);
}
public function testBug2861(): void
{
$this->analyse([__DIR__ . '/data/bug-2861-assign.php'], []);
}
#[RequiresPhp('>= 8.5.0')]
public function testAsymmetricVisibility(): void
{
$this->analyse([__DIR__ . '/data/static-properties-asymmetric-visibility.php'], [
[
'Access to private(set) property $foo of class StaticPropertiesAsymmetricVisibility\Foo.',
25,
],
[
'Access to private(set) property $foo of class StaticPropertiesAsymmetricVisibility\Foo.',
32,
],
[
'Access to protected(set) property $bar of class StaticPropertiesAsymmetricVisibility\Foo.',
33,
],
]);
}
}