3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
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;
39 class dependencyCheck extends TestCase
48 protected function setUp()
54 $this->dice = (new Dice())
55 ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
59 * Test the creation of the BasePath
61 public function testBasePath()
63 /** @var BasePath $basePath */
64 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
66 $this->assertInstanceOf(BasePath::class, $basePath);
67 $this->assertEquals($this->root->url(), $basePath->getPath());
71 * Test the initial config cache
72 * Should not need any other files
74 public function testConfigFileLoader()
76 /** @var ConfigFileLoader $configFileLoader */
77 $configFileLoader = $this->dice->create(ConfigFileLoader::class);
79 $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
81 $configCache = new Cache();
82 $configFileLoader->setupCache($configCache);
84 $this->assertNotEmpty($configCache->getAll());
85 $this->assertArrayHasKey('database', $configCache->getAll());
86 $this->assertArrayHasKey('system', $configCache->getAll());
90 * Test the construction of a profiler class with DI
92 public function testProfiler()
94 /** @var Profiler $profiler */
95 $profiler = $this->dice->create(Profiler::class);
97 $this->assertInstanceOf(Profiler::class, $profiler);
99 $configCache = new Cache([
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]);
112 $this->assertInstanceOf(Profiler::class, $profiler);
113 $this->assertTrue($profiler->isRendertime());
116 public function testDatabase()
118 /** @var Database $database */
119 $database = $this->dice->create(Database::class);
121 $this->assertInstanceOf(Database::class, $database);
122 $this->assertTrue($database->connected());
125 public function testAppMode()
127 /** @var App\Mode $mode */
128 $mode = $this->dice->create(App\Mode::class);
130 $this->assertInstanceOf(App\Mode::class, $mode);
132 $this->assertTrue($mode->isNormal());
135 public function testConfiguration()
137 /** @var IConfig $config */
138 $config = $this->dice->create(IConfig::class);
140 $this->assertInstanceOf(IConfig::class, $config);
142 $this->assertNotEmpty($config->get('database', 'username'));
145 public function testLogger()
147 /** @var LoggerInterface $logger */
148 $logger = $this->dice->create(LoggerInterface::class, ['test']);
150 $this->assertInstanceOf(LoggerInterface::class, $logger);
153 public function testDevLogger()
155 /** @var IConfig $config */
156 $config = $this->dice->create(IConfig::class);
157 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
159 /** @var LoggerInterface $logger */
160 $logger = $this->dice->create('$devLogger', ['dev']);
162 $this->assertInstanceOf(LoggerInterface::class, $logger);
165 public function testCache()
167 /** @var ICache $cache */
168 $cache = $this->dice->create(ICache::class);
170 $this->assertInstanceOf(ICache::class, $cache);
173 public function testMemoryCache()
175 /** @var IMemoryCache $cache */
176 $cache = $this->dice->create(IMemoryCache::class);
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);
182 public function testLock()
184 /** @var ILock $cache */
185 $lock = $this->dice->create(ILock::class);
187 $this->assertInstanceOf(ILock::class, $lock);