3 namespace Friendica\Test\Util;
6 use Friendica\BaseObject;
7 use Friendica\Core\Config;
8 use Friendica\Core\Config\ConfigCache;
9 use Friendica\Render\FriendicaSmartyEngine;
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|ConfigCache The mocked Config Cache
26 protected $configCache;
31 * @param vfsStreamDirectory $root The root directory
32 * @param MockInterface|ConfigCache $config The config cache
34 public function mockApp($root, $config)
36 $this->configCache = $config;
37 // Mocking App and most used functions
38 $this->app = \Mockery::mock(App::class);
40 ->shouldReceive('getBasePath')
41 ->andReturn($root->url());
44 ->shouldReceive('get')
45 ->with('database', 'hostname')
46 ->andReturn(getenv('MYSQL_HOST'));
48 ->shouldReceive('get')
49 ->with('database', 'username')
50 ->andReturn(getenv('MYSQL_USERNAME'));
52 ->shouldReceive('get')
53 ->with('database', 'password')
54 ->andReturn(getenv('MYSQL_PASSWORD'));
56 ->shouldReceive('get')
57 ->with('database', 'database')
58 ->andReturn(getenv('MYSQL_DATABASE'));
60 ->shouldReceive('get')
61 ->with('config', 'hostname')
62 ->andReturn('localhost');
64 ->shouldReceive('get')
65 ->with('system', 'theme', NULL)
66 ->andReturn('system_theme');
69 ->shouldReceive('getConfig')
73 ->shouldReceive('getTemplateEngine')
74 ->andReturn(new FriendicaSmartyEngine());
76 ->shouldReceive('getCurrentTheme')
77 ->andReturn('Smarty3');
79 ->shouldReceive('saveTimestamp')
82 ->shouldReceive('getBaseUrl')
83 ->andReturn('http://friendica.local');
85 // Initialize empty Config
86 Config::init($config);
87 $configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
89 ->shouldReceive('isConnected')
91 Config::setAdapter($configAdapter);
93 BaseObject::setApp($this->app);