Merge pull request #6600 from annando/false-notifications
[friendica.git/.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\ConfigCache;
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         use ConfigMockTrait;
18
19         /**
20          * @var MockInterface|App The mocked Friendica\App
21          */
22         protected $app;
23
24         /**
25          * Mock the App
26          *
27          * @param vfsStreamDirectory $root The root directory
28          * @param MockInterface|ConfigCache $config The config cache
29          */
30         public function mockApp($root, $config)
31         {
32                 $this->mockConfigGet('system', 'theme', 'testtheme');
33
34                 // Mocking App and most used functions
35                 $this->app = \Mockery::mock(App::class);
36                 $this->app
37                         ->shouldReceive('getBasePath')
38                         ->andReturn($root->url());
39
40                 $config
41                         ->shouldReceive('get')
42                         ->with('database', 'hostname')
43                         ->andReturn(getenv('MYSQL_HOST'));
44                 $config
45                         ->shouldReceive('get')
46                         ->with('database', 'username')
47                         ->andReturn(getenv('MYSQL_USERNAME'));
48                 $config
49                         ->shouldReceive('get')
50                         ->with('database', 'password')
51                         ->andReturn(getenv('MYSQL_PASSWORD'));
52                 $config
53                         ->shouldReceive('get')
54                         ->with('database', 'database')
55                         ->andReturn(getenv('MYSQL_DATABASE'));
56                 $this->app
57                         ->shouldReceive('getConfig')
58                         ->andReturn($config);
59
60                 $this->app
61                         ->shouldReceive('getTemplateEngine')
62                         ->andReturn(new FriendicaSmartyEngine());
63                 $this->app
64                         ->shouldReceive('getCurrentTheme')
65                         ->andReturn('Smarty3');
66                 $this->app
67                         ->shouldReceive('saveTimestamp')
68                         ->andReturn(true);
69                 $this->app
70                         ->shouldReceive('getBaseUrl')
71                         ->andReturn('http://friendica.local');
72
73                 BaseObject::setApp($this->app);
74         }
75 }