Skip to content

Commit 4ea67dc

Browse files
committed
test more scenarios which should not remember scope
1 parent d0b99e9 commit 4ea67dc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/PHPStan/Rules/Constants/ConstantRuleTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ public function testRememberedConstructorScope(): void
108108
65,
109109
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
110110
],
111+
[
112+
'Constant XYZ22 not found.',
113+
87,
114+
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
115+
],
116+
[
117+
'Constant XYZ not found.',
118+
88,
119+
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
120+
],
121+
[
122+
'Constant XYZ33 not found.',
123+
98,
124+
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
125+
],
111126
]);
112127
}
113128

tests/PHPStan/Rules/Constants/data/remembered-constructor-scope.php

+21
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,24 @@ public function doFoo(): void {
7777
echo XYZ;
7878
}
7979
}
80+
81+
class StaticMethodScopeNotRemembered {
82+
static public function init() {
83+
define('XYZ22', '123');
84+
}
85+
86+
public function doFoo(): void {
87+
echo XYZ22; // error because defined in static method
88+
echo XYZ; // error, because should not mix scope of __constructor() scope of different class
89+
}
90+
}
91+
92+
class InstanceMethodScopeNotRemembered {
93+
public function init() {
94+
define('XYZ33', '123');
95+
}
96+
97+
public function doFoo(): void {
98+
echo XYZ33; // error because defined in non-constructor method
99+
}
100+
}

0 commit comments

Comments
 (0)