diff --git a/src/Weekdays.php b/src/Weekdays.php index 87232d3..3282327 100644 --- a/src/Weekdays.php +++ b/src/Weekdays.php @@ -13,7 +13,13 @@ public function __construct( /** @var array $weekdays */ public array $weekdays, ) { - // TODO: Validate for unique + $enumValues = []; + foreach ($this->weekdays as $weekday) { + $enumValues[] = $weekday->value; + } + if (count($enumValues) !== count(array_unique($enumValues))) { + throw new \InvalidArgumentException('Weekdays must be unique.'); + } } // -- Array normalizable diff --git a/tests/Weekdays/ConstructionTest.php b/tests/Weekdays/ConstructionTest.php new file mode 100644 index 0000000..2a7625f --- /dev/null +++ b/tests/Weekdays/ConstructionTest.php @@ -0,0 +1,47 @@ +expectException(\InvalidArgumentException::class); + + // -- Act + new Weekdays([ + Weekday::MONDAY, + Weekday::MONDAY, + Weekday::TUESDAY, + ]); + } +}