webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assert unique values in array

Isinlor opened this issue · comments

One more proposition - allow to assert that all values in an array are unique e.g.

Assert::uniqueValues($array)
Assert::allUnique($array)
Assert::noDuplicates($array)

I would follow semantics of array_unique() so probably the assertion would look like:
count($array) === count(array_unique($array))

👍 on Assert::uniqueValues(iterable $iterable)

https://secure.php.net/manual/en/language.types.iterable.php

Iterable is a pseudo-type introduced in PHP 7.1

Given this repo needs to keep compatibility with previous PHP versions, then we can't use iterable but array