Skip to content

Commit a191a3b

Browse files
Add tests
1 parent 8712fc8 commit a191a3b

2 files changed

Lines changed: 101 additions & 19 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,15 +1442,15 @@ public function testBug14323(): void
14421442
$this->analyse([__DIR__ . '/data/bug-14323.php'], [
14431443
[
14441444
'Variable $command might not be defined.',
1445-
40,
1445+
24,
14461446
],
14471447
[
14481448
'Variable $command might not be defined.',
1449-
66,
1449+
50,
14501450
],
14511451
[
14521452
'Variable $command might not be defined.',
1453-
118,
1453+
119,
14541454
],
14551455
]);
14561456
}

tests/PHPStan/Rules/Variables/data/bug-14323.php

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ class Process {
99
public function __construct(array $a) {}
1010
}
1111

12-
class Process2 {
13-
/**
14-
* @param array<string> $a
15-
* @throws ProcessFailedException
16-
*/
17-
public function __construct(array $a) {}
18-
}
19-
20-
class Process3 {
21-
/**
22-
* @param array<string> $a
23-
* @throws void
24-
*/
25-
public function __construct(array $a) {}
26-
}
27-
2812
abstract class DbCommand
2913
{
3014
/**
@@ -77,6 +61,15 @@ public function handle()
7761
abstract public function getCommand();
7862
}
7963

64+
65+
class Process2 {
66+
/**
67+
* @param array<string> $a
68+
* @throws ProcessFailedException
69+
*/
70+
public function __construct(array $a) {}
71+
}
72+
8073
abstract class DbCommand3
8174
{
8275
/**
@@ -103,6 +96,14 @@ public function handle()
10396
abstract public function getCommand();
10497
}
10598

99+
class Process3 {
100+
/**
101+
* @param array<string> $a
102+
* @throws void
103+
*/
104+
public function __construct(array $a) {}
105+
}
106+
106107
abstract class DbCommand4
107108
{
108109
/**
@@ -128,3 +129,84 @@ public function handle()
128129
*/
129130
abstract public function getCommand();
130131
}
132+
133+
class Process4 {
134+
/**
135+
* @param array<string> $a
136+
*
137+
* @throws \LogicException
138+
*/
139+
public function __construct(array $a) {}
140+
141+
/**
142+
* @throws ProcessFailedException
143+
* @throws \LogicException
144+
*/
145+
public function mustRun(): int {}
146+
}
147+
148+
abstract class DbCommand5
149+
{
150+
/**
151+
* @return int
152+
*/
153+
public function handle()
154+
{
155+
try {
156+
(new Process4(
157+
array_merge([$command = $this->getCommand()]),
158+
))->mustRun();
159+
} catch (ProcessFailedException $e) {
160+
echo ("{$command} not found in path.");
161+
162+
return 1;
163+
}
164+
165+
return 0;
166+
}
167+
168+
/**
169+
* @return string
170+
*/
171+
abstract public function getCommand();
172+
}
173+
174+
class Process5 {
175+
/**
176+
* @param array<string> $a
177+
*
178+
* @throws \LogicException
179+
*/
180+
public function __construct(array $a) {}
181+
182+
/**
183+
* @throws ProcessFailedException
184+
*/
185+
public function mustRun(): int {}
186+
}
187+
188+
abstract class DbCommand6
189+
{
190+
/**
191+
* @return int
192+
*/
193+
public function handle()
194+
{
195+
try {
196+
(new Process5(
197+
array_merge([$command = $this->getCommand()]),
198+
))->mustRun();
199+
} catch (ProcessFailedException $e) {
200+
echo ("{$command} not found in path.");
201+
202+
return 1;
203+
}
204+
205+
return 0;
206+
}
207+
208+
/**
209+
* @return string
210+
*/
211+
abstract public function getCommand();
212+
}

0 commit comments

Comments
 (0)