diff --git a/src/ClassSet.php b/src/ClassSet.php index d654c1c5..0d748564 100644 --- a/src/ClassSet.php +++ b/src/ClassSet.php @@ -11,11 +11,9 @@ */ class ClassSet implements \IteratorAggregate { - /** @var string */ - private $directory; + private string $directory; - /** @var array */ - private $exclude; + private array $exclude; private function __construct(string $directory) { @@ -51,7 +49,7 @@ public function getIterator(): \Traversable ->ignoreUnreadableDirs(true) ->ignoreVCS(true); - if ($this->exclude) { + if ([] !== $this->exclude) { $finder->notPath($this->exclude); } diff --git a/tests/Integration/CheckEnumTest.php b/tests/Integration/CheckEnumTest.php new file mode 100644 index 00000000..d0385f5e --- /dev/null +++ b/tests/Integration/CheckEnumTest.php @@ -0,0 +1,107 @@ +createDirStructure())->url(); + + $runner = TestRunner::create('8.4'); + + $rules = []; + + $rules[] = Rule::allClasses() + ->that(new ResideInOneOfTheseNamespaces('Modules\*\App\Domains\*\Enums')) + ->should(new HaveNameMatching('*Enum')) + ->because('we want uniform naming'); + + $rules[] = Rule::allClasses() + ->that(new ResideInOneOfTheseNamespaces('Modules\*\App\Domains\*\Enums')) + ->should(new IsEnum()) + ->because('Enums should be enums'); + + $runner->run($dir, ...$rules); + + $this->assertCount(2, $runner->getViolations()); + $this->assertCount(0, $runner->getParsingErrors()); + + $this->assertStringContainsString('should have a name that matches *Enum because', $runner->getViolations()->get(0)->getError()); + $this->assertStringContainsString('Aclass should be an enum because Enums should be enums', $runner->getViolations()->get(1)->getError()); + } + + public function createDirStructure(): array + { + return [ + 'Modules' => [ + 'Core' => [ + 'App' => [ + 'Domains' => [ + 'Base' => [ + 'Enums' => [ + 'BillingEnum.php' => ' ' ' [ + 'OneTrait.php' => ' '