Repository navigation
Expand file tree
/
Copy pathAccessStaticPropertiesInAssignRuleTest.php
More file actions
154 lines (142 loc) · 4.33 KB
/
Copy pathAccessStaticPropertiesInAssignRuleTest.php
File metadata and controls
154 lines (142 loc) · 4.33 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
use PHPStan\Classes\ForbiddenClassNameExtension;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\ClassCaseSensitivityCheck;
use PHPStan\Rules\ClassForbiddenNameCheck;
use PHPStan\Rules\ClassNameCheck;
use PHPStan\Rules\NonStringableDynamicAccessCheck;
use PHPStan\Rules\RestrictedUsage\RestrictedClassNameUsageExtension;
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();
$ruleLevelHelper = new RuleLevelHelper(
$reflectionProvider,
checkNullables: true,
checkThisOnly: false,
checkUnionTypes: true,
checkExplicitMixed: false,
checkImplicitMixed: false,
checkBenevolentUnionTypes: false,
discoveringSymbolsTip: true,
);
return new AccessStaticPropertiesInAssignRule(
new AccessStaticPropertiesCheck(
$reflectionProvider,
$ruleLevelHelper,
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true, true),
new ClassForbiddenNameCheck(self::getContainer()->getExtensionsCollection(ForbiddenClassNameExtension::class)),
$reflectionProvider,
self::getContainer()->getExtensionsCollection(RestrictedClassNameUsageExtension::class),
),
new PhpVersion(PHP_VERSION_ID),
new NonStringableDynamicAccessCheck($ruleLevelHelper, true),
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,
],
]);
}
#[RequiresPhp('>= 8.0.0')]
public function testWritesOnStringUnions(): void
{
$this->analyse([__DIR__ . '/data/static-property-string-unions-assign.php'], [
[
'Access to an undefined static property StaticPropertyStringUnionsAssign\Baz::$missing.',
32,
],
[
'Access to an undefined static property StaticPropertyStringUnionsAssign\Baz::$missing.',
38,
],
[
'Access to an undefined static property StaticPropertyStringUnionsAssign\Baz::$missing.',
44,
],
[
'Access to private property $secret of class StaticPropertyStringUnionsAssign\Foo.',
50,
],
[
'Access to an undefined static property StaticPropertyStringUnionsAssign\Baz|StaticPropertyStringUnionsAssign\Foo::$count.',
56,
],
]);
}
#[RequiresPhp('>= 8.5.0')]
public function testAsymmetricVisibilityOnConstantString(): void
{
$this->analyse([__DIR__ . '/data/static-property-string-unions-asymmetric.php'], [
[
'Access to private(set) property $privateSet of class StaticPropertyStringUnionsAsymmetric\Foo.',
16,
],
[
'Access to protected(set) property $protectedSet of class StaticPropertyStringUnionsAsymmetric\Foo.',
17,
],
]);
}
}