]> git.mxchange.org Git - friendica.git/blob - tests/Util/AppMockTrait.php
66b95b04e84605023a02c6a316b9fd4eebbc310b
[friendica.git] / tests / Util / AppMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Friendica\App;
6 use Friendica\BaseObject;
7 use Friendica\Core\Config;
8 use Friendica\Render\FriendicaSmartyEngine;
9 use Mockery\MockInterface;
10 use org\bovigo\vfs\vfsStreamDirectory;
11
12 /**
13  * Trait to Mock the global App instance
14  */
15 trait AppMockTrait
16 {
17         /**
18          * @var MockInterface|App The mocked Friendica\App
19          */
20         protected $app;
21
22         /**
23          * @var MockInterface|Config\Configuration The mocked Config Cache
24          */
25         protected $configCache;
26
27         /**
28          * Mock the App
29          *
30          * @param vfsStreamDirectory $root The root directory
31          * @param MockInterface|Config\Configuration $config The config cache
32          */
33         public function mockApp($root, Config\Configuration $config)
34         {
35                 $this->configCache = $config;
36                 // Mocking App and most used functions
37                 $this->app = \Mockery::mock(App::class);
38                 $this->app
39                         ->shouldReceive('getBasePath')
40                         ->andReturn($root->url());
41
42                 $config
43                         ->shouldReceive('get')
44                         ->with('database', 'hostname')
45                         ->andReturn(getenv('MYSQL_HOST'));
46                 $config
47                         ->shouldReceive('get')
48                         ->with('database', 'username')
49                         ->andReturn(getenv('MYSQL_USERNAME'));
50                 $config
51                         ->shouldReceive('get')
52                         ->with('database', 'password')
53                         ->andReturn(getenv('MYSQL_PASSWORD'));
54                 $config
55                         ->shouldReceive('get')
56                         ->with('database', 'database')
57                         ->andReturn(getenv('MYSQL_DATABASE'));
58                 $config
59                         ->shouldReceive('get')
60                         ->with('config', 'hostname')
61                         ->andReturn('localhost');
62                 $config
63                         ->shouldReceive('get')
64                         ->with('system', 'theme', NULL, false)
65                         ->andReturn('system_theme');
66                 $config
67                         ->shouldReceive('getConfig')
68                         ->andReturn($config);
69
70                 $this->app
71                         ->shouldReceive('getConfigCache')
72                         ->andReturn($config);
73
74                 $this->app
75                         ->shouldReceive('getTemplateEngine')
76                         ->andReturn(new FriendicaSmartyEngine());
77                 $this->app
78                         ->shouldReceive('getCurrentTheme')
79                         ->andReturn('Smarty3');
80                 $this->app
81                         ->shouldReceive('saveTimestamp')
82                         ->andReturn(true);
83                 $this->app
84                         ->shouldReceive('getBaseUrl')
85                         ->andReturn('http://friendica.local');
86
87                 // Initialize empty Config
88                 Config::init($config);
89
90                 BaseObject::setApp($this->app);
91         }
92 }