]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
Improve bin/run_xgettext script
[friendica.git] / tests / functional / DependencyCheckTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace functional;
23
24 use Dice\Dice;
25 use Friendica\App;
26 use Friendica\Core\Cache\ICache;
27 use Friendica\Core\Cache\IMemoryCache;
28 use Friendica\Core\Config\Cache;
29 use Friendica\Core\Config\IConfig;
30 use Friendica\Core\Lock\ILock;
31 use Friendica\Database\Database;
32 use Friendica\Test\Util\VFSTrait;
33 use Friendica\Util\BasePath;
34 use Friendica\Util\ConfigFileLoader;
35 use Friendica\Util\Profiler;
36 use PHPUnit\Framework\TestCase;
37 use Psr\Log\LoggerInterface;
38
39 class dependencyCheck extends TestCase
40 {
41         use VFSTrait;
42
43         /**
44          * @var Dice
45          */
46         private $dice;
47
48         protected function setUp()
49         {
50                 parent::setUp();
51
52                 $this->setUpVfsDir();
53
54                 $this->dice = (new Dice())
55                         ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
56         }
57
58         /**
59          * Test the creation of the BasePath
60          */
61         public function testBasePath()
62         {
63                 /** @var BasePath $basePath */
64                 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
65
66                 $this->assertInstanceOf(BasePath::class, $basePath);
67                 $this->assertEquals($this->root->url(), $basePath->getPath());
68         }
69
70         /**
71          * Test the initial config cache
72          * Should not need any other files
73          */
74         public function testConfigFileLoader()
75         {
76                 /** @var ConfigFileLoader $configFileLoader */
77                 $configFileLoader = $this->dice->create(ConfigFileLoader::class);
78
79                 $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
80
81                 $configCache = new Cache();
82                 $configFileLoader->setupCache($configCache);
83
84                 $this->assertNotEmpty($configCache->getAll());
85                 $this->assertArrayHasKey('database', $configCache->getAll());
86                 $this->assertArrayHasKey('system', $configCache->getAll());
87         }
88
89         /**
90          * Test the construction of a profiler class with DI
91          */
92         public function testProfiler()
93         {
94                 /** @var Profiler $profiler */
95                 $profiler = $this->dice->create(Profiler::class);
96
97                 $this->assertInstanceOf(Profiler::class, $profiler);
98
99                 $configCache = new Cache([
100                         'system' => [
101                                 'profiler' => true,
102                         ],
103                         'rendertime' => [
104                                 'callstack' => true,
105                         ]
106                 ]);
107
108                 // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
109                 $this->dice = new Dice();
110                 $profiler = $this->dice->create(Profiler::class, [$configCache]);
111
112                 $this->assertInstanceOf(Profiler::class, $profiler);
113                 $this->assertTrue($profiler->isRendertime());
114         }
115
116         public function testDatabase()
117         {
118                 /** @var Database $database */
119                 $database = $this->dice->create(Database::class);
120
121                 $this->assertInstanceOf(Database::class, $database);
122                 $this->assertTrue($database->connected());
123         }
124
125         public function testAppMode()
126         {
127                 /** @var App\Mode $mode */
128                 $mode = $this->dice->create(App\Mode::class);
129
130                 $this->assertInstanceOf(App\Mode::class, $mode);
131
132                 $this->assertTrue($mode->isNormal());
133         }
134
135         public function testConfiguration()
136         {
137                 /** @var IConfig $config */
138                 $config = $this->dice->create(IConfig::class);
139
140                 $this->assertInstanceOf(IConfig::class, $config);
141
142                 $this->assertNotEmpty($config->get('database', 'username'));
143         }
144
145         public function testLogger()
146         {
147                 /** @var LoggerInterface $logger */
148                 $logger = $this->dice->create(LoggerInterface::class, ['test']);
149
150                 $this->assertInstanceOf(LoggerInterface::class, $logger);
151         }
152
153         public function testDevLogger()
154         {
155                 /** @var IConfig $config */
156                 $config = $this->dice->create(IConfig::class);
157                 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
158
159                 /** @var LoggerInterface $logger */
160                 $logger = $this->dice->create('$devLogger', ['dev']);
161
162                 $this->assertInstanceOf(LoggerInterface::class, $logger);
163         }
164
165         public function testCache()
166         {
167                 /** @var ICache $cache */
168                 $cache = $this->dice->create(ICache::class);
169
170                 $this->assertInstanceOf(ICache::class, $cache);
171         }
172
173         public function testMemoryCache()
174         {
175                 /** @var IMemoryCache $cache */
176                 $cache = $this->dice->create(IMemoryCache::class);
177
178                 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
179                 $this->assertInstanceOf(ICache::class, $cache);
180         }
181
182         public function testLock()
183         {
184                 /** @var ILock $cache */
185                 $lock = $this->dice->create(ILock::class);
186
187                 $this->assertInstanceOf(ILock::class, $lock);
188         }
189 }