3 namespace Friendica\Test\Util;
6 use Friendica\BaseObject;
7 use Friendica\Core\Config;
8 use Friendica\Render\FriendicaSmartyEngine;
9 use Friendica\Util\Profiler;
10 use Mockery\MockInterface;
11 use org\bovigo\vfs\vfsStreamDirectory;
14 * Trait to Mock the global App instance
19 * @var MockInterface|App The mocked Friendica\App
24 * @var MockInterface|Config\Configuration The mocked Config Cache
26 protected $configMock;
29 * @var MockInterface|Profiler The mocked profiler
31 protected $profilerMock;
34 * @var MockInterface|App\Mode The mocked App mode
41 * @param vfsStreamDirectory $root The root directory
42 * @param Config\Cache\ConfigCache $configCache
43 * @param bool $raw If true, no config mocking will be done
45 public function mockApp(vfsStreamDirectory $root, $configCache = null, $raw = false)
47 $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
48 $this->mode = \Mockery::mock(App\Mode::class);
49 $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
50 // Disable the adapter
51 $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
53 $config = new Config\Configuration((isset($configCache) ? $configCache : $this->configMock), $configAdapterMock);
54 // Initialize empty Config
55 Config::init($config);
57 // Mocking App and most used functions
58 $this->app = \Mockery::mock(App::class);
60 ->shouldReceive('getBasePath')
61 ->andReturn($root->url());
64 ->shouldReceive('getMode')
65 ->andReturn($this->mode);
67 $this->profilerMock = \Mockery::mock(Profiler::class);
68 $this->profilerMock->shouldReceive('saveTimestamp');
71 ->shouldReceive('getConfigCache')
72 ->andReturn((isset($configCache) ? $configCache : $this->configMock));
74 ->shouldReceive('getTemplateEngine')
75 ->andReturn(new FriendicaSmartyEngine());
77 ->shouldReceive('getCurrentTheme')
78 ->andReturn('Smarty3');
80 ->shouldReceive('getProfiler')
81 ->andReturn($this->profilerMock);
83 ->shouldReceive('getBaseUrl')
84 ->andReturnUsing(function () {
85 return $this->app->getConfigCache()->get('system', 'url');
88 BaseObject::setApp($this->app);
95 ->shouldReceive('has')
98 ->shouldReceive('get')
99 ->with('database', 'hostname')
100 ->andReturn(getenv('MYSQL_HOST'));
102 ->shouldReceive('get')
103 ->with('database', 'username')
104 ->andReturn(getenv('MYSQL_USERNAME'));
106 ->shouldReceive('get')
107 ->with('database', 'password')
108 ->andReturn(getenv('MYSQL_PASSWORD'));
110 ->shouldReceive('get')
111 ->with('database', 'database')
112 ->andReturn(getenv('MYSQL_DATABASE'));
114 ->shouldReceive('get')
115 ->with('config', 'hostname')
116 ->andReturn('localhost');
118 ->shouldReceive('get')
119 ->with('system', 'theme')
120 ->andReturn('system_theme');