]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
Merge pull request #7643 from nupplaphil/task/add_drone_ci
[friendica.git] / tests / functional / DependencyCheckTest.php
1 <?php
2
3 namespace functional;
4
5 use Dice\Dice;
6 use Friendica\App;
7 use Friendica\Core\Cache\ICache;
8 use Friendica\Core\Cache\IMemoryCache;
9 use Friendica\Core\Config\Cache\ConfigCache;
10 use Friendica\Core\Config\Configuration;
11 use Friendica\Core\Lock\ILock;
12 use Friendica\Database\Database;
13 use Friendica\Test\Util\VFSTrait;
14 use Friendica\Util\BasePath;
15 use Friendica\Util\ConfigFileLoader;
16 use Friendica\Util\Profiler;
17 use PHPUnit\Framework\TestCase;
18 use Psr\Log\LoggerInterface;
19
20 class dependencyCheck extends TestCase
21 {
22         use VFSTrait;
23
24         /**
25          * @var Dice
26          */
27         private $dice;
28
29         protected function setUp()
30         {
31                 parent::setUp();
32
33                 $this->setUpVfsDir();
34
35                 $this->dice = (new Dice())
36                         ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
37         }
38
39         /**
40          * Test the creation of the BasePath
41          */
42         public function testBasePath()
43         {
44                 /** @var BasePath $basePath */
45                 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
46
47                 $this->assertInstanceOf(BasePath::class, $basePath);
48                 $this->assertEquals($this->root->url(), $basePath->getPath());
49         }
50
51         /**
52          * Test the initial config cache
53          * Should not need any other files
54          */
55         public function testConfigFileLoader()
56         {
57                 /** @var ConfigFileLoader $configFileLoader */
58                 $configFileLoader = $this->dice->create(ConfigFileLoader::class);
59
60                 $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
61
62                 $configCache = new ConfigCache();
63                 $configFileLoader->setupCache($configCache);
64
65                 $this->assertNotEmpty($configCache->getAll());
66                 $this->assertArrayHasKey('database', $configCache->getAll());
67                 $this->assertArrayHasKey('system', $configCache->getAll());
68         }
69
70         /**
71          * Test the construction of a profiler class with DI
72          */
73         public function testProfiler()
74         {
75                 /** @var Profiler $profiler */
76                 $profiler = $this->dice->create(Profiler::class);
77
78                 $this->assertInstanceOf(Profiler::class, $profiler);
79
80                 $configCache = new ConfigCache([
81                         'system' => [
82                                 'profiler' => true,
83                         ],
84                         'rendertime' => [
85                                 'callstack' => true,
86                         ]
87                 ]);
88
89                 // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
90                 $this->dice = new Dice();
91                 $profiler = $this->dice->create(Profiler::class, [$configCache]);
92
93                 $this->assertInstanceOf(Profiler::class, $profiler);
94                 $this->assertTrue($profiler->isRendertime());
95         }
96
97         public function testDatabase()
98         {
99                 /** @var Database $database */
100                 $database = $this->dice->create(Database::class);
101
102                 $this->assertInstanceOf(Database::class, $database);
103                 $this->assertTrue($database->connected());
104         }
105
106         public function testAppMode()
107         {
108                 /** @var App\Mode $mode */
109                 $mode = $this->dice->create(App\Mode::class);
110
111                 $this->assertInstanceOf(App\Mode::class, $mode);
112
113                 $this->assertTrue($mode->isNormal());
114         }
115
116         public function testConfiguration()
117         {
118                 /** @var Configuration $config */
119                 $config = $this->dice->create(Configuration::class);
120
121                 $this->assertInstanceOf(Configuration::class, $config);
122
123                 $this->assertNotEmpty($config->get('database', 'username'));
124         }
125
126         public function testLogger()
127         {
128                 /** @var LoggerInterface $logger */
129                 $logger = $this->dice->create(LoggerInterface::class, ['test']);
130
131                 $this->assertInstanceOf(LoggerInterface::class, $logger);
132         }
133
134         public function testDevLogger()
135         {
136                 /** @var LoggerInterface $logger */
137                 $logger = $this->dice->create('$devLogger', ['dev']);
138
139                 $this->assertInstanceOf(LoggerInterface::class, $logger);
140         }
141
142         public function testCache()
143         {
144                 /** @var ICache $cache */
145                 $cache = $this->dice->create(ICache::class);
146
147                 $this->assertInstanceOf(ICache::class, $cache);
148         }
149
150         public function testMemoryCache()
151         {
152                 /** @var IMemoryCache $cache */
153                 $cache = $this->dice->create(IMemoryCache::class);
154
155                 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
156                 $this->assertInstanceOf(ICache::class, $cache);
157         }
158
159         public function testLock()
160         {
161                 /** @var ILock $cache */
162                 $lock = $this->dice->create(ILock::class);
163
164                 $this->assertInstanceOf(ILock::class, $lock);
165         }
166 }