From 603a578a1c9baab2c9eda08d5a316ed25a0163bf Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg <mail@danielkesselberg.de> Date: Mon, 10 Sep 2018 22:45:40 +0200 Subject: [PATCH] Change return false to throw new Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de> --- lib/private/Setup.php | 17 ++++++++++++----- tests/lib/SetupTest.php | 15 ++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index a31d746a062..4b6f2d54583 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -43,6 +43,7 @@ namespace OC; use bantu\IniGetWrapper\IniGetWrapper; use Exception; +use InvalidArgumentException; use OC\App\AppStore\Bundles\BundleFetcher; use OC\Authentication\Token\DefaultTokenCleanupJob; use OC\Authentication\Token\DefaultTokenProvider; @@ -434,18 +435,19 @@ class Setup { * Find webroot from config * * @param SystemConfig $config - * @return bool|string + * @return string + * @throws InvalidArgumentException when invalid value for overwrite.cli.url */ - public static function findWebRoot(SystemConfig $config) { + public static function findWebRoot(SystemConfig $config): string { // For CLI read the value from overwrite.cli.url if (\OC::$CLI) { $webRoot = $config->getValue('overwrite.cli.url', ''); if ($webRoot === '') { - return false; + throw new InvalidArgumentException('overwrite.cli.url is empty'); } $webRoot = parse_url($webRoot, PHP_URL_PATH); if ($webRoot === null) { - return false; + throw new InvalidArgumentException('invalid value for overwrite.cli.url'); } $webRoot = rtrim($webRoot, '/'); } else { @@ -463,7 +465,12 @@ class Setup { */ public static function updateHtaccess() { $config = \OC::$server->getSystemConfig(); - $webRoot = self::findWebRoot($config); + + try { + $webRoot = self::findWebRoot($config); + } catch (InvalidArgumentException $e) { + return false; + } $setupHelper = new \OC\Setup( $config, diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index fe3b1b54d23..40481de8f1d 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -134,18 +134,23 @@ class SetupTest extends \Test\TestCase { /** * @dataProvider findWebRootProvider + * @param $url + * @param $expected */ - public function testFindWebRootCli($url, $webRoot) { + public function testFindWebRootCli($url, $expected) { $this->config ->expects($this->once()) ->method('getValue') ->will($this->returnValue($url)); \OC::$CLI = true; - $this->assertEquals( - $webRoot, - $this->setupClass::findWebRoot($this->config) - ); + try { + $webRoot = $this->setupClass::findWebRoot($this->config); + } catch (\InvalidArgumentException $e) { + $webRoot = false; + } + + $this->assertEquals($webRoot, $expected); } public function findWebRootProvider(): array { -- GitLab