From 5341fdd8af1a0994f542638cc379ffc00c71e283 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Mon, 15 Jan 2018 17:48:59 +0300 Subject: [PATCH] Do not cache app path if app is not found --- lib/private/App/AppManager.php | 15 ++++++++++++++- tests/lib/App/ManagerTest.php | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 01fab4729fe0..4d1d3a562f55 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -561,11 +561,24 @@ protected function findAppInDirectories($appId) { $versionToLoad['url'] .= '/' . $appId; } } - $this->appDirs[$appId] = empty($versionToLoad) ? false : $versionToLoad; + + if (empty($versionToLoad)) { + return false; + } + $this->saveAppPath($appId, $versionToLoad); } return $this->appDirs[$appId]; } + /** + * Save app path and webPath to internal cache + * @param string $appId + * @param string[] $appData + */ + protected function saveAppPath($appId, $appData) { + $this->appDirs[$appId] = $appData; + } + /** * Get apps roots as an array of path and url * Wrapper for easy mocking diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/ManagerTest.php index 27f111cf535f..1f9499850ede 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/ManagerTest.php @@ -510,4 +510,23 @@ public function appInfoDataProvider() { [ '2.2.3', '2.2.1', true ] ]; } + + public function testPathIsNotCachedForNotFoundApp() { + $appId = 'notexistingapp'; + + $appManager = $this->getMockBuilder(AppManager::class) + ->setMethods(['getAppVersionByPath', 'getAppRoots', 'saveAppPath']) + ->disableOriginalConstructor() + ->getMock(); + + $appManager->expects($this->any()) + ->method('getAppRoots') + ->willReturn([]); + + $appManager->expects($this->never()) + ->method('saveAppPath'); + + $appPath = $appManager->getAppPath($appId); + $this->assertFalse($appPath); + } }