Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate namespaces in ResideInOneOfTheseNamespaces #431

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
Loading