Skip to content

Commit 2c6fb75

Browse files
author
Oleksii Korshenko
authored
MAGETWO-88018: [Forwardport] Display a more meaningful error message in case of misspelt module name #13731
2 parents e6a01f7 + 86a5172 commit 2c6fb75

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/internal/Magento/Framework/Module/Dir.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public function getDir($moduleName, $type = '')
4646
{
4747
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
4848

49+
// An empty $type means it's getting the directory of the module itself.
50+
if (empty($type) && !isset($path)) {
51+
// Note: do not throw \LogicException, as it would break backwards-compatibility.
52+
throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered.");
53+
}
54+
4955
if ($type) {
5056
if (!in_array($type, [
5157
self::MODULE_ETC_DIR,

lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,17 @@ public function testGetDirModuleSubDirUnknown()
6969

7070
$this->_model->getDir('Test_Module', 'unknown');
7171
}
72+
73+
/**
74+
* @expectedException \InvalidArgumentException
75+
* @expectedExceptionMessage Module 'Test Module' is not correctly registered.
76+
*/
77+
public function testGetDirModuleIncorrectlyRegistered()
78+
{
79+
$this->moduleRegistryMock->expects($this->once())
80+
->method('getPath')
81+
->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module'))
82+
->willReturn(null);
83+
$this->_model->getDir('Test Module');
84+
}
7285
}

0 commit comments

Comments
 (0)