Skip to content

Commit 86a5172

Browse files
MAGETWO-88018: [Forwardport] Display a more meaningful error message in case of misspelt module name #13731
- Merge Pull Request #13731 from nmalevanec/magento2:2.3-develop-PR-port-12843 - Merged commits: 1. 34a1dee 2. 82f701a 3. 7a0ce57 4. 57a6e17 5. 70b2722 6. d77d9a0
2 parents c920a56 + d77d9a0 commit 86a5172

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
@@ -45,6 +45,12 @@ public function getDir($moduleName, $type = '')
4545
{
4646
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
4747

48+
// An empty $type means it's getting the directory of the module itself.
49+
if (empty($type) && !isset($path)) {
50+
// Note: do not throw \LogicException, as it would break backwards-compatibility.
51+
throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered.");
52+
}
53+
4854
if ($type) {
4955
if (!in_array($type, [
5056
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
@@ -59,4 +59,17 @@ public function testGetDirModuleSubDirUnknown()
5959

6060
$this->_model->getDir('Test_Module', 'unknown');
6161
}
62+
63+
/**
64+
* @expectedException \InvalidArgumentException
65+
* @expectedExceptionMessage Module 'Test Module' is not correctly registered.
66+
*/
67+
public function testGetDirModuleIncorrectlyRegistered()
68+
{
69+
$this->moduleRegistryMock->expects($this->once())
70+
->method('getPath')
71+
->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module'))
72+
->willReturn(null);
73+
$this->_model->getDir('Test Module');
74+
}
6275
}

0 commit comments

Comments
 (0)