]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
Introduce DICE
[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\Config\Cache\ConfigCache;
8 use Friendica\Core\Config\Configuration;
9 use Friendica\Database\Database;
10 use Friendica\Test\Util\VFSTrait;
11 use Friendica\Util\BasePath;
12 use Friendica\Util\ConfigFileLoader;
13 use Friendica\Util\Profiler;
14 use PHPUnit\Framework\TestCase;
15 use Psr\Log\LoggerInterface;
16
17 class dependencyCheck extends TestCase
18 {
19         use VFSTrait;
20
21         /**
22          * @var Dice
23          */
24         private $dice;
25
26         protected function setUp()
27         {
28                 parent::setUp();
29
30                 $this->setUpVfsDir();
31
32                 $this->dice = new Dice();
33                 $this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
34         }
35
36         /**
37          * Test the creation of the BasePath
38          */
39         public function testBasePath()
40         {
41                 /** @var BasePath $basePath */
42                 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
43
44                 $this->assertInstanceOf(BasePath::class, $basePath);
45                 $this->assertEquals($this->root->url(), $basePath->getPath());
46         }
47
48         /**
49          * Test the initial config cache
50          * Should not need any other files
51          */
52         public function testConfigFileLoader()
53         {
54                 /** @var ConfigFileLoader $configFileLoader */
55                 $configFileLoader = $this->dice->create(ConfigFileLoader::class);
56
57                 $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
58
59                 $configCache = new ConfigCache();
60                 $configFileLoader->setupCache($configCache);
61
62                 $this->assertNotEmpty($configCache->getAll());
63                 $this->assertArrayHasKey('database', $configCache->getAll());
64                 $this->assertArrayHasKey('system', $configCache->getAll());
65         }
66
67         /**
68          * Test the construction of a profiler class with DI
69          */
70         public function testProfiler()
71         {
72                 /** @var Profiler $profiler */
73                 $profiler = $this->dice->create(Profiler::class);
74
75                 $this->assertInstanceOf(Profiler::class, $profiler);
76
77                 $configCache = new ConfigCache([
78                         'system' => [
79                                 'profiler' => true,
80                         ],
81                         'rendertime' => [
82                                 'callstack' => true,
83                         ]
84                 ]);
85
86                 $profiler = $this->dice->create(Profiler::class, [$configCache]);
87
88                 $this->assertInstanceOf(Profiler::class, $profiler);
89                 $this->assertTrue($profiler->isRendertime());
90         }
91
92         public function testDatabase()
93         {
94                 /** @var Database $database */
95                 $database = $this->dice->create(Database::class);
96
97                 $this->assertInstanceOf(Database::class, $database);
98                 $this->assertTrue($database->connected());
99         }
100
101         public function testAppMode()
102         {
103                 /** @var App\Mode $mode */
104                 $mode = $this->dice->create(App\Mode::class);
105
106                 $this->assertInstanceOf(App\Mode::class, $mode);
107
108                 $this->assertTrue($mode->isNormal());
109         }
110
111         public function testConfiguration()
112         {
113                 /** @var Configuration $config */
114                 $config = $this->dice->create(Configuration::class);
115
116                 $this->assertInstanceOf(Configuration::class, $config);
117
118                 $this->assertNotEmpty($config->get('database', 'username'));
119         }
120
121         public function testLogger()
122         {
123                 /** @var LoggerInterface $logger */
124                 $logger = $this->dice->create(LoggerInterface::class, ['test']);
125
126                 $this->assertInstanceOf(LoggerInterface::class, $logger);
127         }
128
129         public function testDevLogger()
130         {
131                 /** @var LoggerInterface $logger */
132                 $logger = $this->dice->create('$devLogger', ['dev']);
133
134                 self::assertInstanceOf(LoggerInterface::class, $logger);
135         }
136 }