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
43 public function mockApp($root)
45 $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
46 $this->mode = \Mockery::mock(App\Mode::class);
47 $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
48 // Disable the adapter
49 $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
51 $config = new Config\Configuration($this->configMock, $configAdapterMock);
52 // Initialize empty Config
53 Config::init($config);
55 // Mocking App and most used functions
56 $this->app = \Mockery::mock(App::class);
58 ->shouldReceive('getBasePath')
59 ->andReturn($root->url());
62 ->shouldReceive('getMode')
63 ->andReturn($this->mode);
66 ->shouldReceive('has')
69 ->shouldReceive('get')
70 ->with('database', 'hostname')
71 ->andReturn(getenv('MYSQL_HOST'));
73 ->shouldReceive('get')
74 ->with('database', 'username')
75 ->andReturn(getenv('MYSQL_USERNAME'));
77 ->shouldReceive('get')
78 ->with('database', 'password')
79 ->andReturn(getenv('MYSQL_PASSWORD'));
81 ->shouldReceive('get')
82 ->with('database', 'database')
83 ->andReturn(getenv('MYSQL_DATABASE'));
85 ->shouldReceive('get')
86 ->with('config', 'hostname')
87 ->andReturn('localhost');
89 ->shouldReceive('get')
90 ->with('system', 'theme')
91 ->andReturn('system_theme');
93 $this->profilerMock = \Mockery::mock(Profiler::class);
94 $this->profilerMock->shouldReceive('saveTimestamp');
97 ->shouldReceive('getConfigCache')
98 ->andReturn($this->configMock);
100 ->shouldReceive('getTemplateEngine')
101 ->andReturn(new FriendicaSmartyEngine());
103 ->shouldReceive('getCurrentTheme')
104 ->andReturn('Smarty3');
106 ->shouldReceive('getBaseUrl')
107 ->andReturn('http://friendica.local');
109 ->shouldReceive('getProfiler')
110 ->andReturn($this->profilerMock);
112 BaseObject::setApp($this->app);