diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 936fce3a046b7..688c7c43ac0e4 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,6 +45,12 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); + // An empty $type means it's getting the directory of the module itself. + if (empty($type) && !isset($path)) { + // Note: do not throw \LogicException, as it would break backwards-compatibility. + throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered."); + } + if ($type) { if (!in_array($type, [ self::MODULE_ETC_DIR, diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php index 335228888cc4b..055e4be71baf1 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php @@ -59,4 +59,17 @@ public function testGetDirModuleSubDirUnknown() $this->_model->getDir('Test_Module', 'unknown'); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Module 'Test Module' is not correctly registered. + */ + public function testGetDirModuleIncorrectlyRegistered() + { + $this->moduleRegistryMock->expects($this->once()) + ->method('getPath') + ->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module')) + ->willReturn(null); + $this->_model->getDir('Test Module'); + } }