summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2018-09-10 22:45:40 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2018-09-10 22:45:40 +0200
commit603a578a1c9baab2c9eda08d5a316ed25a0163bf (patch)
tree1d050a159ab95c22c91900dfcf3c8d7d10bde84e
parent62c03beb1d2dc133542c088e6c72b201211ccfba (diff)
downloadnextcloud-server-603a578a1c9baab2c9eda08d5a316ed25a0163bf.tar.gz
nextcloud-server-603a578a1c9baab2c9eda08d5a316ed25a0163bf.zip
Change return false to throw new
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
-rw-r--r--lib/private/Setup.php17
-rw-r--r--tests/lib/SetupTest.php15
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 {