Skip to content

Commit cf1df70

Browse files
Add test
1 parent 6723fac commit cf1df70

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

tests/PHPStan/Rules/Pure/PureMethodRuleTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,37 @@ public function testBug12224(): void
216216
]);
217217
}
218218

219+
public function testAllMethodsArePure(): void
220+
{
221+
$this->treatPhpDocTypesAsCertain = true;
222+
$this->analyse([__DIR__ . '/data/all-methods-are-pure.php'], [
223+
[
224+
'Method AllMethodsArePure\Foo::test() is marked as pure but returns void.',
225+
10,
226+
],
227+
[
228+
'Method AllMethodsArePure\Foo::pure() is marked as pure but returns void.',
229+
17,
230+
],
231+
[
232+
'Method AllMethodsArePure\Foo::impure() is marked as impure but does not have any side effects.',
233+
24,
234+
],
235+
[
236+
'Method AllMethodsArePure\Bar::test() is marked as impure but does not have any side effects.',
237+
34,
238+
],
239+
[
240+
'Method AllMethodsArePure\Bar::pure() is marked as pure but returns void.',
241+
41,
242+
],
243+
[
244+
'Method AllMethodsArePure\Bar::impure() is marked as impure but does not have any side effects.',
245+
48,
246+
],
247+
]);
248+
}
249+
219250
public function testBug12382(): void
220251
{
221252
$this->treatPhpDocTypesAsCertain = true;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace AllMethodsArePure;
4+
5+
/**
6+
* @phpstan-all-methods-pure
7+
*/
8+
final class Foo
9+
{
10+
function test(): void
11+
{
12+
}
13+
14+
/**
15+
* @phpstan-pure
16+
*/
17+
function pure(): void
18+
{
19+
}
20+
21+
/**
22+
* @phpstan-impure
23+
*/
24+
function impure(): void
25+
{
26+
}
27+
}
28+
29+
/**
30+
* @phpstan-all-methods-impure
31+
*/
32+
final class Bar
33+
{
34+
function test(): void
35+
{
36+
}
37+
38+
/**
39+
* @phpstan-pure
40+
*/
41+
function pure(): void
42+
{
43+
}
44+
45+
/**
46+
* @phpstan-impure
47+
*/
48+
function impure(): void
49+
{
50+
}
51+
}

0 commit comments

Comments
 (0)