]> git.mxchange.org Git - friendica.git/commitdiff
Remove BasePath dependency from App\Mode
authorPhilipp <admin@philipp.info>
Sun, 15 Jan 2023 12:46:01 +0000 (13:46 +0100)
committerPhilipp <admin@philipp.info>
Sun, 15 Jan 2023 15:17:07 +0000 (16:17 +0100)
src/App/Mode.php
static/dependencies.config.php
tests/src/App/ModeTest.php

index 514df91c649d7cc53e1199ea3d2cfce7698ff2b4..48c88d803a15791b892579003787db8bb0812def 100644 (file)
@@ -24,7 +24,6 @@ namespace Friendica\App;
 use Detection\MobileDetect;
 use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Database\Database;
-use Friendica\Util\BasePath;
 
 /**
  * Mode of the current Friendica Node
@@ -129,15 +128,13 @@ class Mode
         *
         * @throws \Exception
         */
-       public function determine(BasePath $basepath, Database $database, Cache $configCache): Mode
+       public function determine(string $basePath, Database $database, Cache $configCache): Mode
        {
                $mode = 0;
 
-               $basepathName = $basepath->getPath();
-
-               if (!file_exists($basepathName . '/config/local.config.php')
-                   && !file_exists($basepathName . '/config/local.ini.php')
-                   && !file_exists($basepathName . '/.htconfig.php')) {
+               if (!file_exists($basePath . '/config/local.config.php') &&
+                       !file_exists($basePath . '/config/local.ini.php') &&
+                       !file_exists($basePath . '/.htconfig.php')) {
                        return new Mode($mode);
                }
 
index 6feb76989b19c5e9a317992957a7fe3bdf8fe9e1..1836a44dd5cccf053dd1aca0ca29f4cdce6efa1f 100644 (file)
@@ -94,7 +94,9 @@ return [
        App\Mode::class              => [
                'call' => [
                        ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
-                       ['determine', [], Dice::CHAIN_CALL],
+                       ['determine', [
+                               [Dice::INSTANCE => '$basepath']
+                       ], Dice::CHAIN_CALL],
                ],
        ],
        Config\Capability\IManageConfigValues::class => [
index aecd2b17526f37200008ae925a575273a4ed1481..a651a73b1dd96b27cd06608f6f0a807f9643d629 100644 (file)
@@ -57,7 +57,6 @@ class ModeTest extends MockedTest
 
                $this->setUpVfsDir();
 
-               $this->basePathMock    = Mockery::mock(BasePath::class);
                $this->databaseMock    = Mockery::mock(Database::class);
                $this->configCacheMock = Mockery::mock(Cache::class);
        }
@@ -71,15 +70,13 @@ class ModeTest extends MockedTest
 
        public function testWithoutConfig()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
                self::assertTrue($this->root->hasChild('config/local.config.php'));
 
                $this->delConfigFile('local.config.php');
 
                self::assertFalse($this->root->hasChild('config/local.config.php'));
 
-               $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
 
                self::assertTrue($mode->isInstall());
                self::assertFalse($mode->isNormal());
@@ -89,11 +86,9 @@ class ModeTest extends MockedTest
 
        public function testWithoutDatabase()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
                $this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
 
-               $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
 
                self::assertFalse($mode->isNormal());
                self::assertTrue($mode->isInstall());
@@ -104,13 +99,11 @@ class ModeTest extends MockedTest
 
        public function testWithMaintenanceMode()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
                $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
                $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
                                                          ->andReturn(true)->once();
 
-               $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
 
                self::assertFalse($mode->isNormal());
                self::assertFalse($mode->isInstall());
@@ -120,13 +113,11 @@ class ModeTest extends MockedTest
 
        public function testNormalMode()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
                $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
                $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
                                                          ->andReturn(false)->once();
 
-               $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
 
                self::assertTrue($mode->isNormal());
                self::assertFalse($mode->isInstall());
@@ -139,13 +130,11 @@ class ModeTest extends MockedTest
         */
        public function testDisabledMaintenance()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
-
                $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
                $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
                                                          ->andReturn(false)->once();
 
-               $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode = (new Mode())->determine($this->root->url(), $this->databaseMock, $this->configCacheMock);
 
                self::assertTrue($mode->isNormal());
                self::assertFalse($mode->isInstall());
@@ -158,11 +147,9 @@ class ModeTest extends MockedTest
         */
        public function testImmutable()
        {
-               $this->basePathMock->shouldReceive('getPath')->andReturn(null)->once();
-
                $mode = new Mode();
 
-               $modeNew = $mode->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $modeNew = $mode->determine('', $this->databaseMock, $this->configCacheMock);
 
                self::assertNotSame($modeNew, $mode);
        }