Skip to content

Commit 2319e42

Browse files
Add assertions
1 parent 12b94b6 commit 2319e42

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ private static function findTestFiles(): iterable
262262
yield __DIR__ . '/../Rules/Properties/data/bug-14012.php';
263263
yield __DIR__ . '/../Rules/Variables/data/bug-14124.php';
264264
yield __DIR__ . '/../Rules/Variables/data/bug-14124b.php';
265+
yield __DIR__ . '/../Rules/Arrays/data/bug-10345.php';
265266
yield __DIR__ . '/../Rules/Arrays/data/bug-14308.php';
266267
}
267268

tests/PHPStan/Rules/Arrays/data/bug-10345.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
namespace Bug10345;
66

7+
use function PHPStan\Testing\assertType;
8+
79
$container = new \stdClass();
810
$container->items = [];
911

1012
$func = function() use ($container): int {
11-
foreach ($container->items as $item) {}
13+
assertType('stdClass', $container);
14+
assertType('mixed', $container->items);
15+
foreach ($container->items as $item) {
16+
}
1217
return 1;
1318
};
1419

@@ -25,6 +30,8 @@ class Foo {
2530
$container2->items = [];
2631

2732
$func2 = function() use ($container2): int {
33+
assertType('Bug10345\Foo', $container2);
34+
assertType('list<string>', $container2->items);
2835
foreach ($container2->items as $item) {}
2936
return 1;
3037
};
@@ -53,6 +60,8 @@ public function setItems(array $items): void
5360
$container3 = new Bar();
5461
if ($container3->getItems() === []) {
5562
$func3 = function() use ($container3): int {
63+
assertType('Bug10345\Bar', $container3);
64+
assertType('list<string>', $container3->getItems());
5665
foreach ($container3->getItems() as $item) {}
5766
return 1;
5867
};
@@ -67,6 +76,8 @@ public function setItems(array $items): void
6776
$container4->items = [];
6877

6978
$func4 = function() use ($container4): int {
79+
assertType('Bug10345\Foo', $container4);
80+
assertType('list<string>', $container4->items);
7081
foreach ($container4?->items as $item) {}
7182
return 1;
7283
};

0 commit comments

Comments
 (0)