Skip to content

Commit a2940e5

Browse files
committed
Fix all* methods for partially iterable types
1 parent 962f1a9 commit a2940e5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Type/BeberleiAssert/AssertHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private static function arrayOrIterable(
170170
\Closure $typeCallback
171171
): SpecifiedTypes
172172
{
173-
$currentType = $scope->getType($expr);
173+
$currentType = TypeCombinator::intersect($scope->getType($expr), new IterableType(new MixedType(), new MixedType()));
174174
$arrayTypes = TypeUtils::getArrays($currentType);
175175
if (count($arrayTypes) > 0) {
176176
$newArrayTypes = [];

tests/Type/BeberleiAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ public function testExtension(): void
248248
'Variable $assertThatAllFunction is: Assert\AssertionChain<mixed>-all',
249249
157,
250250
],
251+
[
252+
'Variable $a is: array<stdClass>',
253+
167,
254+
],
251255
]);
252256
}
253257

tests/Type/BeberleiAssert/data/data.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ public function doBar(?int $a, $b, $c, array $d, iterable $e, $g)
157157
$assertThatAllFunction;
158158
}
159159

160+
public function doBaz(array $a): void
161+
{
162+
if (rand(0, 1)) {
163+
$a = false;
164+
}
165+
166+
Assertion::allIsInstanceOf($a, \stdClass::class);
167+
$a;
168+
}
169+
160170
}
161171

162172
class Bar

0 commit comments

Comments
 (0)