]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
[frio] Add friendica-tagsinput library based on bootstrap-tagsinput
[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                 // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
87                 $this->dice = new Dice(include __DIR__ . '/../../static/dependencies.config.php');
88                 $profiler = $this->dice->create(Profiler::class, [$configCache]);
89
90                 $this->assertInstanceOf(Profiler::class, $profiler);
91                 $this->assertTrue($profiler->isRendertime());
92         }
93
94         public function testDatabase()
95         {
96                 /** @var Database $database */
97                 $database = $this->dice->create(Database::class);
98
99                 $this->assertInstanceOf(Database::class, $database);
100                 $this->assertTrue($database->connected());
101         }
102
103         public function testAppMode()
104         {
105                 /** @var App\Mode $mode */
106                 $mode = $this->dice->create(App\Mode::class);
107
108                 $this->assertInstanceOf(App\Mode::class, $mode);
109
110                 $this->assertTrue($mode->isNormal());
111         }
112
113         public function testConfiguration()
114         {
115                 /** @var Configuration $config */
116                 $config = $this->dice->create(Configuration::class);
117
118                 $this->assertInstanceOf(Configuration::class, $config);
119
120                 $this->assertNotEmpty($config->get('database', 'username'));
121         }
122
123         public function testLogger()
124         {
125                 /** @var LoggerInterface $logger */
126                 $logger = $this->dice->create(LoggerInterface::class, ['test']);
127
128                 $this->assertInstanceOf(LoggerInterface::class, $logger);
129         }
130
131         public function testDevLogger()
132         {
133                 /** @var LoggerInterface $logger */
134                 $logger = $this->dice->create('$devLogger', ['dev']);
135
136                 self::assertInstanceOf(LoggerInterface::class, $logger);
137         }
138 }