forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallToStaticMethodStatementWithoutSideEffectsRuleTest.php
More file actions
166 lines (152 loc) · 4.35 KB
/
CallToStaticMethodStatementWithoutSideEffectsRuleTest.php
File metadata and controls
166 lines (152 loc) · 4.35 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
155
156
157
158
159
160
161
162
163
164
165
166
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Methods;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<CallToStaticMethodStatementWithoutSideEffectsRule>
*/
class CallToStaticMethodStatementWithoutSideEffectsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = self::createReflectionProvider();
return new CallToStaticMethodStatementWithoutSideEffectsRule(
new RuleLevelHelper(
$broker,
checkNullables: true,
checkThisOnly: false,
checkUnionTypes: true,
checkExplicitMixed: false,
checkImplicitMixed: false,
checkBenevolentUnionTypes: false,
discoveringSymbolsTip: true,
),
$broker,
);
}
#[RequiresPhp('>= 8.0.0')]
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects.php'], [
[
'Call to method DateTime::format() on a separate line has no effect.',
23,
],
]);
}
#[RequiresPhp('< 8.0.0')]
public function testRulePhp7(): void
{
$this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects.php'], [
[
'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.',
12,
],
[
'Call to static method DateTimeImmutable::createFromFormat() on a separate line has no effect.',
13,
],
[
'Call to method DateTime::format() on a separate line has no effect.',
23,
],
]);
}
public function testPhpDoc(): void
{
$this->analyse([__DIR__ . '/data/static-method-call-statement-no-side-effects-phpdoc.php'], [
[
'Call to static method StaticMethodCallStatementNoSideEffects\BzzStatic::pure1() on a separate line has no effect.',
55,
],
[
'Call to static method StaticMethodCallStatementNoSideEffects\BzzStatic::pure2() on a separate line has no effect.',
56,
],
[
'Call to static method StaticMethodCallStatementNoSideEffects\BzzStatic::pure3() on a separate line has no effect.',
57,
],
[
'Call to static method StaticMethodCallStatementNoSideEffects\BzzStatic::pure4() on a separate line has no effect.',
58,
],
[
'Call to static method StaticMethodCallStatementNoSideEffects\BzzStatic::pure5() on a separate line has no effect.',
59,
],
[
'Call to static method StaticMethodCallStatementNoSideEffects\PureThrows::pureAndThrowsVoid() on a separate line has no effect.',
85,
],
]);
}
public function testBug4455(): void
{
$this->analyse([__DIR__ . '/data/bug-4455-static.php'], []);
}
public function testBug12224(): void
{
$this->analyse([__DIR__ . '/data/bug-12224.php'], []);
}
public function testFirstClassCallables(): void
{
$this->analyse([__DIR__ . '/data/first-class-callable-static-method-without-side-effect.php'], [
[
'Call to static method FirstClassCallableStaticMethodWithoutSideEffect\Foo::doFoo() on a separate line has no effect.',
12,
],
[
'Call to static method FirstClassCallableStaticMethodWithoutSideEffect\Bar::doFoo() on a separate line has no effect.',
36,
],
[
'Call to static method FirstClassCallableStaticMethodWithoutSideEffect\Bar::doBar() on a separate line has no effect.',
39,
],
]);
}
public function testBug10819(): void
{
$errors = [];
if (PHP_VERSION_ID < 80000) {
$errors = [
[
'Call to static method DateTime::createFromFormat() on a separate line has no effect.',
13,
],
];
}
$this->analyse([__DIR__ . '/data/bug-10819.php'], $errors);
}
public function testDynamicStaticCall(): void
{
$this->analyse([__DIR__ . '/data/dynamic-static-call.php'], [
[
'Call to static method DynamicStaticCall\Foo::doFoo() on a separate line has no effect.',
32,
],
[
'Call to static method DynamicStaticCall\FinalFoo::doFoo() on a separate line has no effect.',
33,
],
[
'Call to static method DynamicStaticCall\Bar::finalFoo() on a separate line has no effect.',
34,
],
]);
}
#[RequiresPhp('>= 8.5.0')]
public function testPipeOperator(): void
{
$this->analyse([__DIR__ . '/data/static-method-call-without-side-effect-pipe.php'], [
[
'Call to static method StaticMethodCallWithoutSideEffectPipe\Foo::doPure() on a separate line has no effect.',
33,
],
]);
}
}