diff --git a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php index 5048486d..4b5978ba 100644 --- a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php +++ b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php @@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespaces implements Expression public function __construct(string ...$namespaces) { - $this->namespaces = $namespaces; + $this->namespaces = array_values(array_unique($namespaces)); } public function describe(ClassDescription $theClass, string $because): Description diff --git a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php index 95b526ff..4f8dce9e 100644 --- a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php +++ b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php @@ -84,4 +84,14 @@ public function test_it_should_check_multiple_namespaces_in_or(): void $haveNameMatching->evaluate($classDesc, $violations, $because); self::assertNotEquals(0, $violations->count()); } + + public function test_duplicate_namespaces_are_removed(): void + { + $expression = new ResideInOneOfTheseNamespaces('A', 'B', 'A', 'C', 'D', 'D'); + + self::assertSame( + 'should reside in one of these namespaces: A, B, C, D because rave', + $expression->describe(ClassDescription::getBuilder('Marko')->build(), 'rave')->toString() + ); + } }