Skip to content

Commit a06c890

Browse files
phpstan-botclaude
andcommitted
Convert Bug8579Test to standard rule test and assertType test
Move the Bug8579 regression test from a custom Analyser test to a standard RuleTestCase for InstantiationRule with rememberPossiblyImpureFunctionValues: false config. Convert the class_exists false-not-remembered test to assertType assertions in the existing DoNotRememberPossiblyImpureFunctionValues test data file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 50a2756 commit a06c890

6 files changed

Lines changed: 57 additions & 73 deletions

tests/PHPStan/Analyser/Bug8579Test.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/PHPStan/Analyser/data/bug-8579-false-not-remembered.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/PHPStan/Analyser/data/do-not-remember-possibly-impure-function-values.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,23 @@ function test(): void
109109
assertType('int', impure());
110110
}
111111
}
112+
113+
function testClassExistsFalseNotRemembered(): void
114+
{
115+
if (!class_exists('Bug8579FalseNotRememberedA')) {
116+
// class_exists returned false here, but we don't exit
117+
}
118+
119+
assertType('bool', class_exists('Bug8579FalseNotRememberedA'));
120+
}
121+
122+
function testClassExistsFalseNotRememberedElse(): void
123+
{
124+
if (class_exists('Bug8579FalseNotRememberedB')) {
125+
// true branch
126+
} else {
127+
// class_exists returned false in this branch
128+
}
129+
130+
assertType('bool', class_exists('Bug8579FalseNotRememberedB'));
131+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Classes;
4+
5+
use PHPStan\Rules\Rule;
6+
use PHPStan\Testing\RuleTestCase;
7+
use function array_merge;
8+
9+
/**
10+
* @extends RuleTestCase<InstantiationRule>
11+
*/
12+
class InstantiationDoNotRememberPossiblyImpureValuesRuleTest extends RuleTestCase
13+
{
14+
15+
protected function getRule(): Rule
16+
{
17+
return self::getContainer()->getByType(InstantiationRule::class);
18+
}
19+
20+
public function testBug8579(): void
21+
{
22+
$this->analyse([__DIR__ . '/data/bug-8579.php'], []);
23+
}
24+
25+
public static function getAdditionalConfigFiles(): array
26+
{
27+
return array_merge(
28+
parent::getAdditionalConfigFiles(),
29+
[
30+
__DIR__ . '/doNotRememberPossiblyImpureValues.neon',
31+
],
32+
);
33+
}
34+
35+
}
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
rememberPossiblyImpureFunctionValues: false

0 commit comments

Comments
 (0)