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/>.
22 namespace Friendica\Test\functional;
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 DependencyCheckTest 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 self::assertInstanceOf(BasePath::class, $basePath);
67 self::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 self::assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
81 $configCache = new Cache();
82 $configCache->set('database', 'disable_pdo', true);
83 $configFileLoader->setupCache($configCache);
85 self::assertNotEmpty($configCache->getAll());
86 self::assertArrayHasKey('database', $configCache->getAll());
87 self::assertArrayHasKey('system', $configCache->getAll());
91 * Test the construction of a profiler class with DI
93 public function testProfiler()
95 /** @var Profiler $profiler */
96 $profiler = $this->dice->create(Profiler::class);
98 self::assertInstanceOf(Profiler::class, $profiler);
100 $configCache = new Cache([
109 // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
110 $this->dice = new Dice();
111 $profiler = $this->dice->create(Profiler::class, [$configCache]);
113 self::assertInstanceOf(Profiler::class, $profiler);
114 self::assertTrue($profiler->isRendertime());
117 public function testDatabase()
119 /** @var Database $database */
120 $database = $this->dice->create(Database::class);
122 self::assertInstanceOf(Database::class, $database);
123 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
124 self::assertNotNull($database->getConnection(), 'There is no database connection');
126 $result = $database->p("SELECT 1");
127 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
128 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
130 self::assertTrue($database->connected(), 'The database is not connected');
133 public function testAppMode()
135 /** @var App\Mode $mode */
136 $mode = $this->dice->create(App\Mode::class);
138 self::assertInstanceOf(App\Mode::class, $mode);
140 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
141 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
142 self::assertTrue($mode->has(App\Mode::DBCONFIGAVAILABLE), 'Database config is not available');
143 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
145 self::assertTrue($mode->isNormal(), 'Not in normal mode');
148 public function testConfiguration()
150 /** @var IConfig $config */
151 $config = $this->dice->create(IConfig::class);
153 self::assertInstanceOf(IConfig::class, $config);
155 self::assertNotEmpty($config->get('database', 'username'));
158 public function testLogger()
160 /** @var LoggerInterface $logger */
161 $logger = $this->dice->create(LoggerInterface::class, ['test']);
163 self::assertInstanceOf(LoggerInterface::class, $logger);
166 public function testDevLogger()
168 /** @var IConfig $config */
169 $config = $this->dice->create(IConfig::class);
170 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
172 /** @var LoggerInterface $logger */
173 $logger = $this->dice->create('$devLogger', ['dev']);
175 self::assertInstanceOf(LoggerInterface::class, $logger);
178 public function testCache()
180 /** @var ICache $cache */
181 $cache = $this->dice->create(ICache::class);
183 self::assertInstanceOf(ICache::class, $cache);
186 public function testMemoryCache()
188 /** @var IMemoryCache $cache */
189 $cache = $this->dice->create(IMemoryCache::class);
191 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
192 self::assertInstanceOf(ICache::class, $cache);
195 public function testLock()
197 /** @var ILock $cache */
198 $lock = $this->dice->create(ILock::class);
200 self::assertInstanceOf(ILock::class, $lock);