Skip to content

Commit 734e0b3

Browse files
committed
fix regression tests
1 parent fe05863 commit 734e0b3

3 files changed

Lines changed: 32 additions & 28 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,26 +1432,6 @@ public function testBug14318(): void
14321432
$this->analyse([__DIR__ . '/data/bug-14318.php'], []);
14331433
}
14341434

1435-
public function testBug11284(): void
1436-
{
1437-
$this->cliArgumentsVariablesRegistered = true;
1438-
$this->polluteScopeWithLoopInitialAssignments = false;
1439-
$this->checkMaybeUndefinedVariables = true;
1440-
$this->polluteScopeWithAlwaysIterableForeach = true;
1441-
1442-
$this->analyse([__DIR__ . '/data/bug-11284.php'], []);
1443-
}
1444-
1445-
public function testBug7806(): void
1446-
{
1447-
$this->cliArgumentsVariablesRegistered = true;
1448-
$this->polluteScopeWithLoopInitialAssignments = false;
1449-
$this->checkMaybeUndefinedVariables = true;
1450-
$this->polluteScopeWithAlwaysIterableForeach = true;
1451-
1452-
$this->analyse([__DIR__ . '/data/bug-7806.php'], []);
1453-
}
1454-
14551435
#[RequiresPhp('>= 8.0')]
14561436
public function testBug14274(): void
14571437
{

tests/PHPStan/Rules/Variables/EmptyRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ public function testBug10367(): void
209209
$this->analyse([__DIR__ . '/data/bug-10367.php'], []);
210210
}
211211

212+
public function testBug11284(): void
213+
{
214+
$this->treatPhpDocTypesAsCertain = true;
215+
216+
$this->analyse([__DIR__ . '/data/bug-11284.php'], []);
217+
}
218+
219+
public function testBug7806(): void
220+
{
221+
$this->treatPhpDocTypesAsCertain = true;
222+
223+
$this->analyse([__DIR__ . '/data/bug-7806.php'], []);
224+
}
225+
212226
#[RequiresPhp('>= 8.0')]
213227
public function testIssetAfterRememberedConstructor(): void
214228
{

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@
22

33
namespace Bug7806;
44

5-
class HelloWorld
6-
{
5+
class Test {
6+
/**
7+
* @param array<string>|null $reasons
8+
* @throws \Exception
9+
*/
10+
function check(array &$reasons = null): void {
11+
$fileName = time() % 2 ? "abc":null;
12+
if (!$fileName) {
13+
$reasons[] = sprintf("Dependency check fail");
14+
throw new \Exception("check failed");
15+
}
16+
}
717

8-
public function test(): void
9-
{
18+
function test():void {
1019
try {
11-
preg_match('/pattern/', 'subject', $reasons);
12-
} catch (\Throwable $e) {
20+
$this->check($reasons);
21+
printf("ok\n");
22+
} catch (\Exception $e) {
1323
if (!empty($reasons)) {
14-
echo implode(', ', $reasons);
24+
$e = new \Exception("Dependency check failed: " . implode(', ', $reasons), 0, $e);
1525
}
26+
throw new \Exception("Failed", 0, $e);
1627
}
1728
}
18-
1929
}

0 commit comments

Comments
 (0)