Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
* Regression test

Closes phpstan/phpstan#5223
  • Loading branch information
herndlm committed Jul 26, 2022
1 parent 5d7a1a5 commit 6478c73
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-6364.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-5758.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-3931.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5223.php');
}

/**
Expand Down
56 changes: 56 additions & 0 deletions tests/PHPStan/Analyser/data/bug-5223.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types = 1);

namespace Bug5223;

use function PHPStan\Testing\assertType;

class HelloWorld
{

/**
* @param array{
* categoryKeys: string[],
* tagNames: string[],
* } $filters
*/
public function withUnset(array $filters): void
{
assertType("array{categoryKeys: array<string>, tagNames: array<string>}", $filters);

unset($filters['page']);
assertType("array{categoryKeys: array<string>, tagNames: array<string>}", $filters);

unset($filters['limit']);
assertType("array{categoryKeys: array<string>, tagNames: array<string>}", $filters);

assertType('*ERROR*', $filters['something']);
var_dump($filters['something']);

$this->test($filters);
}

/**
* @param array{
* categoryKeys: string[],
* tagNames: string[],
* } $filters
*/
public function withoutUnset(array $filters): void
{
assertType("array{categoryKeys: array<string>, tagNames: array<string>}", $filters);
assertType('*ERROR*', $filters['something']);
var_dump($filters['something']);

$this->test($filters);
}

/**
* @param array{
* categoryKeys: string[],
* tagNames: string[],
* } $filters
*/
private function test(array $filters): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,26 @@ public function testBug5758(): void
$this->analyse([__DIR__ . '/data/bug-5758.php'], []);
}

public function testBug5223(): void
{
$this->analyse([__DIR__ . '/../../Analyser/data/bug-5223.php'], [
[
'Offset \'something\' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.',
26,
],
[
'Offset \'something\' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.',
27,
],
[
'Offset \'something\' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.',
41,
],
[
'Offset \'something\' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.',
42,
],
]);
}

}
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Variables/UnsetRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public function testBug4289(): void
$this->analyse([__DIR__ . '/data/bug-4289.php'], []);
}

public function testBug5223(): void
{
$this->analyse([__DIR__ . '/../../Analyser/data/bug-5223.php'], [
[
'Cannot unset offset \'page\' on array{categoryKeys: array<string>, tagNames: array<string>}.',
20,
],
[
'Cannot unset offset \'limit\' on array{categoryKeys: array<string>, tagNames: array<string>}.',
23,
],
]);
}

}

0 comments on commit 6478c73

Please sign in to comment.