Skip to content

Commit

Permalink
add regression tests for phpstan/phpstan#7000
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Apr 8, 2022
1 parent 5066420 commit bc53e9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -859,6 +859,7 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6927.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/constant-array-optional-set.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7000.php');
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7000.php
@@ -0,0 +1,20 @@
<?php

namespace Bug7000;

use function PHPStan\Testing\assertType;

class Foo
{
public function doBar(): void
{
/** @var array{require?: array<string, string>, require-dev?: array<string, string>} $composer */
$composer = array();
foreach (array('require', 'require-dev') as $linkType) {
if (isset($composer[$linkType])) {
assertType('array{require: array<string, string>, require-dev: array<string, string>}', $composer);
foreach ($composer[$linkType] as $x) {}
}
}
}
}
Expand Up @@ -367,4 +367,9 @@ public function testBug4747(): void
$this->analyse([__DIR__ . '/data/bug-4747.php'], []);
}

public function testBug7000(): void
{
$this->analyse([__DIR__ . '/data/bug-7000.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-7000.php
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace Bug7000;

class Foo
{
public function doBar(): void
{
/** @var array{require?: array<string, string>, require-dev?: array<string, string>} $composer */
$composer = array();
foreach (array('require', 'require-dev') as $linkType) {
if (isset($composer[$linkType])) {
foreach ($composer[$linkType] as $x) {}
}
}
}
}

0 comments on commit bc53e9f

Please sign in to comment.