Skip to content

Commit

Permalink
Support ::minCount assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
R4c00n authored Jan 29, 2021
1 parent 7c19228 commit 2873b44
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This extension specifies types of values passed to:
* `Assert::notSame`
* `Assert::implementsInterface`
* `Assert::classExists`
* `Assert::minCount`
* `nullOr*` and `all*` variants of the above methods


Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^0.12.40"
"phpstan/phpstan": "^0.12.49"
},
"require-dev": {
"phing/phing": "^2.16.3",
Expand Down
9 changes: 9 additions & 0 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ private static function getExpressionResolvers(): array
[$class]
);
},
'minCount' => function (Scope $scope, Arg $array, Arg $number): \PhpParser\Node\Expr {
return new \PhpParser\Node\Expr\BinaryOp\GreaterOrEqual(
new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('count'),
[$array]
),
$number->value
);
},
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public function testExtension(): void
'Variable $ai is: array<string>',
146,
],
[
'Variable $ak is: int',
152,
],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Type/WebMozartAssert/data/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
$ai;
Assert::allString($ai);
$ai;

/** @var int[] $aj */
$aj = doFoo();
Assert::minCount($aj, 1);
$ak = array_pop($aj);
$ak;
}

}
Expand Down

0 comments on commit 2873b44

Please sign in to comment.