Skip to content

Commit 7c19228

Browse files
committed
Support isList() assert
1 parent dcb3839 commit 7c19228

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ private static function getExpressionResolvers(): array
273273
)
274274
);
275275
},
276+
'isList' => function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
277+
return new \PhpParser\Node\Expr\FuncCall(
278+
new \PhpParser\Node\Name('is_array'),
279+
[$expr]
280+
);
281+
},
276282
'isCountable' => function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
277283
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr(
278284
new \PhpParser\Node\Expr\FuncCall(

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public function testExtension(): void
176176
'Variable $ah is: array<stdClass>',
177177
141,
178178
],
179+
[
180+
'Variable $ai is: array',
181+
144,
182+
],
183+
[
184+
'Variable $ai is: array<string>',
185+
146,
186+
],
179187
]);
180188
}
181189

tests/Type/WebMozartAssert/data/data.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Foo
88
{
99

10-
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)
10+
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)
1111
{
1212
$a;
1313

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

140140
Assert::allIsInstanceOf($ah, \stdClass::class);
141141
$ah;
142+
143+
Assert::isList($ai);
144+
$ai;
145+
Assert::allString($ai);
146+
$ai;
142147
}
143148

144149
}

0 commit comments

Comments
 (0)