3 namespace Friendica\Test\Util;
6 use Friendica\BaseObject;
7 use Friendica\Core\Config;
8 use Friendica\Render\FriendicaSmartyEngine;
9 use Mockery\MockInterface;
10 use org\bovigo\vfs\vfsStreamDirectory;
13 * Trait to Mock the global App instance
18 * @var MockInterface|App The mocked Friendica\App
23 * @var MockInterface|Config\Configuration The mocked Config Cache
25 protected $configCache;
30 * @param vfsStreamDirectory $root The root directory
31 * @param MockInterface|Config\Configuration $config The config cache
33 public function mockApp($root, Config\Configuration $config)
35 $this->configCache = $config;
36 // Mocking App and most used functions
37 $this->app = \Mockery::mock(App::class);
39 ->shouldReceive('getBasePath')
40 ->andReturn($root->url());
43 ->shouldReceive('get')
44 ->with('database', 'hostname')
45 ->andReturn(getenv('MYSQL_HOST'));
47 ->shouldReceive('get')
48 ->with('database', 'username')
49 ->andReturn(getenv('MYSQL_USERNAME'));
51 ->shouldReceive('get')
52 ->with('database', 'password')
53 ->andReturn(getenv('MYSQL_PASSWORD'));
55 ->shouldReceive('get')
56 ->with('database', 'database')
57 ->andReturn(getenv('MYSQL_DATABASE'));
59 ->shouldReceive('get')
60 ->with('config', 'hostname')
61 ->andReturn('localhost');
63 ->shouldReceive('get')
64 ->with('system', 'theme', NULL, false)
65 ->andReturn('system_theme');
67 ->shouldReceive('getConfig')
71 ->shouldReceive('getConfigCache')
75 ->shouldReceive('getTemplateEngine')
76 ->andReturn(new FriendicaSmartyEngine());
78 ->shouldReceive('getCurrentTheme')
79 ->andReturn('Smarty3');
81 ->shouldReceive('saveTimestamp')
84 ->shouldReceive('getBaseUrl')
85 ->andReturn('http://friendica.local');
87 // Initialize empty Config
88 Config::init($config);
90 BaseObject::setApp($this->app);