Skip to content

Commit

Permalink
Fix all* methods for partially iterable types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 24, 2021
1 parent 5119d01 commit dcb3839
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private function arrayOrIterable(
\Closure $typeCallback
): SpecifiedTypes
{
$currentType = $scope->getType($expr);
$currentType = TypeCombinator::intersect($scope->getType($expr), new IterableType(new MixedType(), new MixedType()));
$arrayTypes = TypeUtils::getArrays($currentType);
if (count($arrayTypes) > 0) {
$newArrayTypes = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public function testExtension(): void
'Variable $ag is: class-string',
134,
],
[
'Variable $ah is: array<stdClass>',
141,
],
]);
}

Expand Down
9 changes: 8 additions & 1 deletion tests/Type/WebMozartAssert/data/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Foo
{

public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae, $af, $ag)
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae, $af, $ag, array $ah)
{
$a;

Expand Down Expand Up @@ -132,6 +132,13 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,

Assert::classExists($ag);
$ag;

if (rand(0, 1)) {
$ah = false;
}

Assert::allIsInstanceOf($ah, \stdClass::class);
$ah;
}

}
Expand Down

0 comments on commit dcb3839

Please sign in to comment.