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\ConfigCache::class);
47 $this->configMock->shouldReceive('getAll')->andReturn([])->once();
48 $this->mode = \Mockery::mock(App\Mode::class);
49 $configModel= \Mockery::mock(\Friendica\Model\Config\Config::class);
50 // Disable the adapter
51 $configModel->shouldReceive('isConnected')->andReturn(false);
53 $config = new Config\JitConfiguration($this->configMock, $configModel);
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($this->configMock);
74 ->shouldReceive('getConfig')
77 ->shouldReceive('getTemplateEngine')
78 ->andReturn(new FriendicaSmartyEngine());
80 ->shouldReceive('getCurrentTheme')
81 ->andReturn('Smarty3');
83 ->shouldReceive('getProfiler')
84 ->andReturn($this->profilerMock);
86 ->shouldReceive('getBaseUrl')
87 ->andReturnUsing(function () {
88 return $this->configMock->get('system', 'url');
91 BaseObject::setApp($this->app);
98 ->shouldReceive('has')
101 ->shouldReceive('get')
102 ->with('database', 'hostname')
103 ->andReturn(getenv('MYSQL_HOST'));
105 ->shouldReceive('get')
106 ->with('database', 'username')
107 ->andReturn(getenv('MYSQL_USERNAME'));
109 ->shouldReceive('get')
110 ->with('database', 'password')
111 ->andReturn(getenv('MYSQL_PASSWORD'));
113 ->shouldReceive('get')
114 ->with('database', 'database')
115 ->andReturn(getenv('MYSQL_DATABASE'));
117 ->shouldReceive('get')
118 ->with('config', 'hostname')
119 ->andReturn('localhost');
121 ->shouldReceive('get')
122 ->with('system', 'theme')
123 ->andReturn('system_theme');