Skip to content

Commit 7b88911

Browse files
Add tests
1 parent f320582 commit 7b88911

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tests/PHPStan/Rules/Pure/PureMethodRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ public function testAllMethodsArePure(): void
244244
'Method AllMethodsArePure\Bar::impure() is marked as impure but does not have any side effects.',
245245
48,
246246
],
247+
[
248+
'Impure call to method AllMethodsArePure\Test::impure() in pure method AllMethodsArePure\SideEffectPure::nothingWithImpure().',
249+
78,
250+
],
251+
[
252+
'Method AllMethodsArePure\SideEffectPure::impureWithPure() is marked as impure but does not have any side effects.',
253+
88,
254+
],
255+
[
256+
'Method AllMethodsArePure\SideEffectImpure::nothingWithPure() is marked as impure but does not have any side effects.',
257+
101,
258+
],
259+
[
260+
'Impure call to method AllMethodsArePure\Test::impure() in pure method AllMethodsArePure\SideEffectImpure::pureWithImpure().',
261+
106,
262+
],
247263
]);
248264
}
249265

tests/PHPStan/Rules/Pure/data/all-methods-are-pure.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,64 @@ function impure(): void
4949
{
5050
}
5151
}
52+
53+
class Test
54+
{
55+
/**
56+
* @phpstan-impure
57+
*/
58+
public static function impure(): void
59+
{
60+
}
61+
62+
/**
63+
* @phpstan-pure
64+
* @throws void
65+
*/
66+
public static function pure(): int
67+
{
68+
return 1;
69+
}
70+
}
71+
72+
/**
73+
* @phpstan-all-methods-pure
74+
*/
75+
final class SideEffectPure
76+
{
77+
public function nothingWithImpure(): int {
78+
Test::impure();
79+
}
80+
public function nothingWithPure(): int {
81+
Test::pure();
82+
}
83+
/** @phpstan-impure */
84+
public function impureWithImpure(): int {
85+
Test::impure();
86+
}
87+
/** @phpstan-impure */
88+
public function impureWithPure(): int {
89+
Test::pure();
90+
}
91+
}
92+
93+
/**
94+
* @phpstan-all-methods-impure
95+
*/
96+
final class SideEffectImpure
97+
{
98+
public function nothingWithImpure(): int {
99+
Test::impure();
100+
}
101+
public function nothingWithPure(): int {
102+
Test::pure();
103+
}
104+
/** @phpstan-pure */
105+
public function pureWithImpure(): int {
106+
Test::impure();
107+
}
108+
/** @phpstan-pure */
109+
public function pureWithPure(): int {
110+
Test::pure();
111+
}
112+
}

0 commit comments

Comments
 (0)