diff --git a/.gitattributes b/.gitattributes index 891327c..d5966aa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,5 +2,4 @@ .gitignore export-ignore .gitlab-ci.yml export-ignore .travis.yml export-ignore -tests/ export-ignore -CI/ export-ignore \ No newline at end of file +test/ export-ignore \ No newline at end of file diff --git a/src/FuzeWorks/Configurator.php b/src/FuzeWorks/Configurator.php index 956c2a4..a3fd5e6 100644 --- a/src/FuzeWorks/Configurator.php +++ b/src/FuzeWorks/Configurator.php @@ -126,9 +126,13 @@ class Configurator * @param string $category Optional * @param int $priority * @return $this + * @throws InvalidArgumentException */ public function addDirectory(string $directory, string $category, $priority = Priority::NORMAL): Configurator { + if (!file_exists($directory)) + throw new InvalidArgumentException("Could not add directory. Directory does not exist."); + if (!isset($this->directories[$category])) $this->directories[$category] = []; @@ -151,11 +155,11 @@ class Configurator */ public function addComponent(iComponent $component): Configurator { - if (in_array($component, $this->components)) + if (isset($this->components[get_class($component)])) return $this; $component->onAddComponent($this); - $this->components[] = $component; + $this->components[get_class($component)] = $component; return $this; } @@ -349,7 +353,7 @@ class Configurator Logger::enable(); // Load components - foreach ($this->components as $component) + foreach ($this->components as $componentSuperClass => $component) { Logger::logInfo("Adding Component: '" . $component->getName() . "'"); foreach ($component->getClasses() as $componentName => $componentClass) diff --git a/test/core/core_configuratorTest.php b/test/core/core_configuratorTest.php index 7b7c4a0..2abe17b 100644 --- a/test/core/core_configuratorTest.php +++ b/test/core/core_configuratorTest.php @@ -240,6 +240,16 @@ class configuratorTest extends CoreTestAbstract $this->assertEquals([vfsStream::url('testAddComponentDirectory')], $container->testaddcomponentdirectory->getComponentPaths()); } + /** + * @depends testAddComponentDirectory + * @covers ::addDirectory + * @expectedException \FuzeWorks\Exception\InvalidArgumentException + */ + public function testAddComponentDirectoryNotExist() + { + $this->configurator->addDirectory('not_exist', 'irrelevant'); + } + /* ---------------------------------- Deferred Invocation --------------------------------------- */ /**