Fixing some AutomaticInstallationConsoleTests
[friendica.git/.git] / tests / Util / AppMockTrait.php
index f8d1540..23920ff 100644 (file)
@@ -39,8 +39,10 @@ trait AppMockTrait
         * Mock the App
         *
         * @param vfsStreamDirectory $root The root directory
+        * @param Config\Cache\ConfigCache $configCache
+        * @param bool $raw If true, no config mocking will be done
         */
-       public function mockApp($root)
+       public function mockApp(vfsStreamDirectory $root, $configCache = null, $raw = false)
        {
                $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
                $this->mode = \Mockery::mock(App\Mode::class);
@@ -48,7 +50,7 @@ trait AppMockTrait
                // Disable the adapter
                $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
 
-               $config = new Config\Configuration($this->configMock, $configAdapterMock);
+               $config = new Config\Configuration((isset($configCache) ? $configCache : $this->configMock), $configAdapterMock);
                // Initialize empty Config
                Config::init($config);
 
@@ -62,6 +64,33 @@ trait AppMockTrait
                        ->shouldReceive('getMode')
                        ->andReturn($this->mode);
 
+               $this->profilerMock = \Mockery::mock(Profiler::class);
+               $this->profilerMock->shouldReceive('saveTimestamp');
+
+               $this->app
+                       ->shouldReceive('getConfigCache')
+                       ->andReturn((isset($configCache) ? $configCache : $this->configMock));
+               $this->app
+                       ->shouldReceive('getTemplateEngine')
+                       ->andReturn(new FriendicaSmartyEngine());
+               $this->app
+                       ->shouldReceive('getCurrentTheme')
+                       ->andReturn('Smarty3');
+               $this->app
+                       ->shouldReceive('getProfiler')
+                       ->andReturn($this->profilerMock);
+               $this->app
+                       ->shouldReceive('getBaseUrl')
+                       ->andReturnUsing(function () {
+                               return $this->app->getConfigCache()->get('system', 'url');
+                       });
+
+               BaseObject::setApp($this->app);
+
+               if ($raw) {
+                       return;
+               }
+
                $this->configMock
                        ->shouldReceive('has')
                        ->andReturn(true);
@@ -89,26 +118,5 @@ trait AppMockTrait
                        ->shouldReceive('get')
                        ->with('system', 'theme')
                        ->andReturn('system_theme');
-
-               $this->profilerMock = \Mockery::mock(Profiler::class);
-               $this->profilerMock->shouldReceive('saveTimestamp');
-
-               $this->app
-                       ->shouldReceive('getConfigCache')
-                       ->andReturn($this->configMock);
-               $this->app
-                       ->shouldReceive('getTemplateEngine')
-                       ->andReturn(new FriendicaSmartyEngine());
-               $this->app
-                       ->shouldReceive('getCurrentTheme')
-                       ->andReturn('Smarty3');
-               $this->app
-                       ->shouldReceive('getBaseUrl')
-                       ->andReturn('http://friendica.local');
-               $this->app
-                       ->shouldReceive('getProfiler')
-                       ->andReturn($this->profilerMock);
-
-               BaseObject::setApp($this->app);
        }
 }