AutoInstall Test fix
[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                 // simply returning the input when using L10n::t()
31                 $l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
32                 $l10nMock->shouldReceive('t')
33                         ->andReturnUsing(function ($arg) { return $arg; });
34
35                 $this->mockConfigGet('system', 'theme', 'testtheme');
36
37                 // Mocking App and most used functions
38                 $this->app = \Mockery::mock(App::class);
39                 $this->app
40                         ->shouldReceive('getBasePath')
41                         ->andReturn($root->url());
42
43                 $this->app
44                         ->shouldReceive('getConfigValue')
45                         ->with('database', 'hostname')
46                         ->andReturn(getenv('MYSQL_HOST'));
47                 $this->app
48                         ->shouldReceive('getConfigValue')
49                         ->with('database', 'username')
50                         ->andReturn(getenv('MYSQL_USERNAME'));
51                 $this->app
52                         ->shouldReceive('getConfigValue')
53                         ->with('database', 'password')
54                         ->andReturn(getenv('MYSQL_PASSWORD'));
55                 $this->app
56                         ->shouldReceive('getConfigValue')
57                         ->with('database', 'database')
58                         ->andReturn(getenv('MYSQL_DATABASE'));
59                 $this->app
60                         ->shouldReceive('getTemplateEngine')
61                         ->andReturn(new FriendicaSmartyEngine());
62                 $this->app
63                         ->shouldReceive('getCurrentTheme')
64                         ->andReturn('Smarty3');
65                 $this->app
66                         ->shouldReceive('saveTimestamp')
67                         ->andReturn(true);
68                 $this->app
69                         ->shouldReceive('getBaseUrl')
70                         ->andReturn('http://friendica.local');
71
72                 BaseObject::setApp($this->app);
73         }
74 }