Skip to content

Commit 0307f23

Browse files
herndlmondrejmirtes
authored andcommitted
Specify non-empty-array for Assert::uniqueValues
1 parent 0e81610 commit 0307f23

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ private function getExpressionResolvers(): array
752752
)
753753
);
754754
},
755+
'uniqueValues' => static function (Scope $scope, Arg $value): array {
756+
return self::createIsNonEmptyArrayAndSomethingExprPair('uniqueValues', [$value]);
757+
},
755758
];
756759

757760
foreach (['contains', 'startsWith', 'endsWith'] as $name) {
@@ -784,7 +787,6 @@ private function getExpressionResolvers(): array
784787
return self::createIsNonEmptyStringAndSomethingExprPair($name, [$value]);
785788
};
786789
}
787-
788790
}
789791

790792
return $this->resolvers;
@@ -1003,6 +1005,28 @@ private static function createIsNonEmptyStringAndSomethingExprPair(string $name,
10031005
return [$expr, $rootExpr];
10041006
}
10051007

1008+
/**
1009+
* @param Arg[] $args
1010+
* @return array{Expr, Expr}
1011+
*/
1012+
private static function createIsNonEmptyArrayAndSomethingExprPair(string $name, array $args): array
1013+
{
1014+
$expr = new GreaterOrEqual(
1015+
new FuncCall(
1016+
new Name('count'),
1017+
[$args[0]]
1018+
),
1019+
new LNumber(1)
1020+
);
1021+
1022+
$rootExpr = new BooleanAnd(
1023+
$expr,
1024+
new FuncCall(new Name('FAUX_FUNCTION_ ' . $name), $args)
1025+
);
1026+
1027+
return [$expr, $rootExpr];
1028+
}
1029+
10061030
private function specifyRootExprIfSet(?Expr $rootExpr, SpecifiedTypes $specifiedTypes): SpecifiedTypes
10071031
{
10081032
if ($rootExpr === null) {

tests/Type/WebMozartAssert/data/type.php

+6
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ public function isArrayAccessible($a, $b): void
305305
Assert::nullOrIsArrayAccessible($b);
306306
assertType('array|ArrayAccess|null', $b);
307307
}
308+
309+
public function uniqueValues(array $a): void
310+
{
311+
Assert::uniqueValues($a);
312+
assertType('non-empty-array', $a);
313+
}
308314
}
309315

310316
class Foo {}

0 commit comments

Comments
 (0)