Merge remote-tracking branch 'upstream/develop' into diasppora-delivery
[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\Render\FriendicaSmartyEngine;
8 use Mockery\MockInterface;
9 use org\bovigo\vfs\vfsStreamDirectory;
10
11 /**
12  * Trait to Mock the global App instance
13  */
14 trait AppMockTrait
15 {
16         use ConfigMockTrait;
17
18         /**
19          * @var MockInterface|App The mocked Friendica\App
20          */
21         protected $app;
22
23         /**
24          * Mock the App
25          *
26          * @param vfsStreamDirectory $root The root directory
27          */
28         public function mockApp($root)
29         {
30                 $this->mockConfigGet('system', 'theme', 'testtheme');
31
32                 // Mocking App and most used functions
33                 $this->app = \Mockery::mock(App::class);
34                 $this->app
35                         ->shouldReceive('getBasePath')
36                         ->andReturn($root->url());
37
38                 $this->app
39                         ->shouldReceive('getConfigValue')
40                         ->with('database', 'hostname')
41                         ->andReturn(getenv('MYSQL_HOST'));
42                 $this->app
43                         ->shouldReceive('getConfigValue')
44                         ->with('database', 'username')
45                         ->andReturn(getenv('MYSQL_USERNAME'));
46                 $this->app
47                         ->shouldReceive('getConfigValue')
48                         ->with('database', 'password')
49                         ->andReturn(getenv('MYSQL_PASSWORD'));
50                 $this->app
51                         ->shouldReceive('getConfigValue')
52                         ->with('database', 'database')
53                         ->andReturn(getenv('MYSQL_DATABASE'));
54                 $this->app
55                         ->shouldReceive('getTemplateEngine')
56                         ->andReturn(new FriendicaSmartyEngine());
57                 $this->app
58                         ->shouldReceive('getCurrentTheme')
59                         ->andReturn('Smarty3');
60                 $this->app
61                         ->shouldReceive('saveTimestamp')
62                         ->andReturn(true);
63                 $this->app
64                         ->shouldReceive('getBaseUrl')
65                         ->andReturn('http://friendica.local');
66
67                 BaseObject::setApp($this->app);
68         }
69 }