]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
2a3eed5973048bdae28c5fa967c82f1811076964
[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())->create(Profiler::class, [$configCache]);
91
92                 $this->assertInstanceOf(Profiler::class, $profiler);
93                 $this->assertTrue($profiler->isRendertime());
94         }
95
96         public function testDatabase()
97         {
98                 /** @var Database $database */
99                 $database = $this->dice->create(Database::class);
100
101                 $this->assertInstanceOf(Database::class, $database);
102                 $this->assertTrue($database->connected());
103         }
104
105         public function testAppMode()
106         {
107                 /** @var App\Mode $mode */
108                 $mode = $this->dice->create(App\Mode::class);
109
110                 $this->assertInstanceOf(App\Mode::class, $mode);
111
112                 $this->assertTrue($mode->isNormal());
113         }
114
115         public function testConfiguration()
116         {
117                 /** @var Configuration $config */
118                 $config = $this->dice->create(Configuration::class);
119
120                 $this->assertInstanceOf(Configuration::class, $config);
121
122                 $this->assertNotEmpty($config->get('database', 'username'));
123         }
124
125         public function testLogger()
126         {
127                 /** @var LoggerInterface $logger */
128                 $logger = $this->dice->create(LoggerInterface::class, ['test']);
129
130                 $this->assertInstanceOf(LoggerInterface::class, $logger);
131         }
132
133         public function testDevLogger()
134         {
135                 /** @var LoggerInterface $logger */
136                 $logger = $this->dice->create('$devLogger', ['dev']);
137
138                 $this->assertInstanceOf(LoggerInterface::class, $logger);
139         }
140
141         public function testCache()
142         {
143                 /** @var ICache $cache */
144                 $cache = $this->dice->create(ICache::class);
145
146                 $this->assertInstanceOf(ICache::class, $cache);
147         }
148
149         public function testMemoryCache()
150         {
151                 /** @var IMemoryCache $cache */
152                 $cache = $this->dice->create(IMemoryCache::class);
153
154                 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
155                 $this->assertInstanceOf(ICache::class, $cache);
156         }
157
158         public function testLock()
159         {
160                 /** @var ILock $cache */
161                 $lock = $this->dice->create(ILock::class);
162
163                 $this->assertInstanceOf(ILock::class, $lock);
164         }
165 }