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 bool $raw If true, no config mocking will be done
44 public function mockApp(vfsStreamDirectory $root, $raw = false)
46 $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
47 $this->mode = \Mockery::mock(App\Mode::class);
48 $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
49 // Disable the adapter
50 $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
52 $config = new Config\Configuration($this->configMock, $configAdapterMock);
53 // Initialize empty Config
54 Config::init($config);
56 // Mocking App and most used functions
57 $this->app = \Mockery::mock(App::class);
59 ->shouldReceive('getBasePath')
60 ->andReturn($root->url());
63 ->shouldReceive('getMode')
64 ->andReturn($this->mode);
66 $this->profilerMock = \Mockery::mock(Profiler::class);
67 $this->profilerMock->shouldReceive('saveTimestamp');
70 ->shouldReceive('getConfigCache')
71 ->andReturn($this->configMock);
73 ->shouldReceive('getTemplateEngine')
74 ->andReturn(new FriendicaSmartyEngine());
76 ->shouldReceive('getCurrentTheme')
77 ->andReturn('Smarty3');
79 ->shouldReceive('getProfiler')
80 ->andReturn($this->profilerMock);
82 ->shouldReceive('getBaseUrl')
83 ->andReturnUsing(function () {
84 return $this->configMock->get('system', 'url');
87 BaseObject::setApp($this->app);
94 ->shouldReceive('has')
97 ->shouldReceive('get')
98 ->with('database', 'hostname')
99 ->andReturn(getenv('MYSQL_HOST'));
101 ->shouldReceive('get')
102 ->with('database', 'username')
103 ->andReturn(getenv('MYSQL_USERNAME'));
105 ->shouldReceive('get')
106 ->with('database', 'password')
107 ->andReturn(getenv('MYSQL_PASSWORD'));
109 ->shouldReceive('get')
110 ->with('database', 'database')
111 ->andReturn(getenv('MYSQL_DATABASE'));
113 ->shouldReceive('get')
114 ->with('config', 'hostname')
115 ->andReturn('localhost');
117 ->shouldReceive('get')
118 ->with('system', 'theme')
119 ->andReturn('system_theme');