Fixing some AutomaticInstallationConsoleTests
[friendica.git/.git] / tests / Util / AppMockTrait.php
index 817570d..23920ff 100644 (file)
@@ -30,19 +30,27 @@ trait AppMockTrait
         */
        protected $profilerMock;
 
+       /**
+        * @var MockInterface|App\Mode The mocked App mode
+        */
+       protected $mode;
+
        /**
         * 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);
                $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
                // 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);
 
@@ -52,6 +60,37 @@ trait AppMockTrait
                        ->shouldReceive('getBasePath')
                        ->andReturn($root->url());
 
+               $this->app
+                       ->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);
@@ -79,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);
        }
 }