Skip to content

Commit 27e88c3

Browse files
committed
Added regression test
1 parent 16cd93f commit 27e88c3

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Testing\PHPStanTestCase;
6+
use PHPUnit\Framework\Attributes\CoversNothing;
7+
use function array_map;
8+
use function array_merge;
9+
use function array_unique;
10+
use function error_reporting;
11+
use const E_ALL;
12+
13+
#[CoversNothing]
14+
class Bug13813IntegrationTest extends PHPStanTestCase
15+
{
16+
17+
public function testBug13813(): void
18+
{
19+
error_reporting(E_ALL);
20+
$analyzerResult = $this->runAnalyse([
21+
__DIR__ . '/data/bug-13813.php',
22+
__DIR__ . '/Bug13813Rule.php',
23+
]);
24+
$this->assertCount(2, $analyzerResult->getAllPhpErrors());
25+
$this->assertCount(2, $analyzerResult->getFilteredPhpErrors());
26+
}
27+
28+
/**
29+
* @param string[] $files
30+
* @return Error[]
31+
*/
32+
private function runAnalyse(array $files): AnalyserResult
33+
{
34+
$files = array_map(fn (string $file): string => $this->getFileHelper()->normalizePath($file), $files);
35+
/** @var Analyser $analyser */
36+
$analyser = self::getContainer()->getByType(Analyser::class);
37+
38+
return $analyser->analyse($files);
39+
}
40+
41+
public static function getAdditionalConfigFiles(): array
42+
{
43+
return array_unique(
44+
array_merge(
45+
parent::getAdditionalConfigFiles(),
46+
[
47+
__DIR__ . '/bug13813.neon',
48+
],
49+
),
50+
);
51+
}
52+
53+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Expr\Variable;
7+
use PHPStan\Rules\Rule;
8+
9+
/**
10+
* @implements Rule<Node\Expr\Variable>
11+
*/
12+
class Bug13813Rule implements Rule
13+
{
14+
15+
public function getNodeType(): string
16+
{
17+
return Variable::class;
18+
}
19+
20+
public function processNode(Node $node, Scope $scope): array
21+
{
22+
for ($i = 0; $i < 100; $i++) {
23+
echo $x; // force emit a PHP warning at runtime
24+
}
25+
26+
return [];
27+
}
28+
29+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rules:
2+
- PHPStan\Analyser\Bug13813Rule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Bug13813;
4+
5+
function doFoo($x) {
6+
echo $x;
7+
}

0 commit comments

Comments
 (0)