Skip to content

Commit

Permalink
Support isList() assert
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 28, 2021
1 parent dcb3839 commit 7c19228
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ private static function getExpressionResolvers(): array
)
);
},
'isList' => function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
return new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('is_array'),
[$expr]
);
},
'isCountable' => function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr(
new \PhpParser\Node\Expr\FuncCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public function testExtension(): void
'Variable $ah is: array<stdClass>',
141,
],
[
'Variable $ai is: array',
144,
],
[
'Variable $ai is: array<string>',
146,
],
]);
}

Expand Down
7 changes: 6 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, array $ah)
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, $ai)
{
$a;

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

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

Assert::isList($ai);
$ai;
Assert::allString($ai);
$ai;
}

}
Expand Down

0 comments on commit 7c19228

Please sign in to comment.