Skip to content

Commit 2873b44

Browse files
authored
Support ::minCount assertion
1 parent 7c19228 commit 2873b44

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This extension specifies types of values passed to:
5454
* `Assert::notSame`
5555
* `Assert::implementsInterface`
5656
* `Assert::classExists`
57+
* `Assert::minCount`
5758
* `nullOr*` and `all*` variants of the above methods
5859

5960

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.1 || ^8.0",
10-
"phpstan/phpstan": "^0.12.40"
10+
"phpstan/phpstan": "^0.12.49"
1111
},
1212
"require-dev": {
1313
"phing/phing": "^2.16.3",

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@ private static function getExpressionResolvers(): array
389389
[$class]
390390
);
391391
},
392+
'minCount' => function (Scope $scope, Arg $array, Arg $number): \PhpParser\Node\Expr {
393+
return new \PhpParser\Node\Expr\BinaryOp\GreaterOrEqual(
394+
new \PhpParser\Node\Expr\FuncCall(
395+
new \PhpParser\Node\Name('count'),
396+
[$array]
397+
),
398+
$number->value
399+
);
400+
},
392401
];
393402
}
394403

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public function testExtension(): void
184184
'Variable $ai is: array<string>',
185185
146,
186186
],
187+
[
188+
'Variable $ak is: int',
189+
152,
190+
],
187191
]);
188192
}
189193

tests/Type/WebMozartAssert/data/data.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
144144
$ai;
145145
Assert::allString($ai);
146146
$ai;
147+
148+
/** @var int[] $aj */
149+
$aj = doFoo();
150+
Assert::minCount($aj, 1);
151+
$ak = array_pop($aj);
152+
$ak;
147153
}
148154

149155
}

0 commit comments

Comments
 (0)