3 * @copyright Copyright (C) 2010-2023, the Friendica project
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;
25 use Friendica\Core\Cache\Capability\ICanCache;
26 use Friendica\Core\Cache\Capability\ICanCacheInMemory;
27 use Friendica\Core\Config\ValueObject\Cache;
28 use Friendica\Core\Config\Capability\IManageConfigValues;
29 use Friendica\Core\Lock\Capability\ICanLock;
30 use Friendica\Database\Database;
31 use Friendica\Test\FixtureTest;
32 use Friendica\Util\BasePath;
33 use Friendica\Core\Config\Util\ConfigFileManager;
34 use Psr\Log\LoggerInterface;
36 class DependencyCheckTest extends FixtureTest
38 protected function setUp() : void
42 /** @var IManageConfigValues $config */
43 $config = $this->dice->create(IManageConfigValues::class);
44 $config->set('system', 'logfile', $this->root->url() . '/logs/friendica.log');
48 * Test the creation of the BasePath
50 public function testBasePath()
52 /** @var BasePath $basePath */
53 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
55 self::assertInstanceOf(BasePath::class, $basePath);
56 self::assertEquals($this->root->url(), $basePath->getPath());
58 /** @var Database $dba */
59 $dba = $this->dice->create(Database::class);
63 * Test the initial config cache
64 * Should not need any other files
66 public function testConfigFileLoader()
68 /** @var ConfigFileManager $configFileManager */
69 $configFileManager = $this->dice->create(ConfigFileManager::class);
71 self::assertInstanceOf(ConfigFileManager::class, $configFileManager);
73 $configCache = new Cache();
74 $configFileManager->setupCache($configCache);
76 self::assertNotEmpty($configCache->getAll());
77 self::assertArrayHasKey('database', $configCache->getAll());
78 self::assertArrayHasKey('system', $configCache->getAll());
81 public function testDatabase()
83 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
84 if (version_compare(PHP_VERSION, '7.3') < 0) {
85 $configCache = $this->dice->create(Cache::class);
86 $configCache->set('database', 'disable_pdo', true);
89 /** @var Database $database */
90 $database = $this->dice->create(Database::class);
92 self::assertInstanceOf(Database::class, $database);
93 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
94 self::assertNotNull($database->getConnection(), 'There is no database connection');
96 $result = $database->p("SELECT 1");
97 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
98 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
100 self::assertTrue($database->connected(), 'The database is not connected');
103 public function testAppMode()
105 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
106 if (version_compare(PHP_VERSION, '7.3') < 0) {
107 $configCache = $this->dice->create(Cache::class);
108 $configCache->set('database', 'disable_pdo', true);
111 /** @var App\Mode $mode */
112 $mode = $this->dice->create(App\Mode::class);
114 self::assertInstanceOf(App\Mode::class, $mode);
116 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
117 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
118 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
120 self::assertTrue($mode->isNormal(), 'Not in normal mode');
123 public function testConfiguration()
125 /** @var IManageConfigValues $config */
126 $config = $this->dice->create(IManageConfigValues::class);
128 self::assertInstanceOf(IManageConfigValues::class, $config);
130 self::assertNotEmpty($config->get('database', 'username'));
133 public function testLogger()
135 /** @var LoggerInterface $logger */
136 $logger = $this->dice->create(LoggerInterface::class, [['$channel' => 'test']]);
138 self::assertInstanceOf(LoggerInterface::class, $logger);
141 public function testDevLogger()
143 /** @var IManageConfigValues $config */
144 $config = $this->dice->create(IManageConfigValues::class);
145 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
147 /** @var LoggerInterface $logger */
148 $logger = $this->dice->create('$devLogger', ['dev']);
150 self::assertInstanceOf(LoggerInterface::class, $logger);
153 public function testCache()
155 /** @var ICanCache $cache */
156 $cache = $this->dice->create(ICanCache::class);
159 self::assertInstanceOf(ICanCache::class, $cache);
162 public function testMemoryCache()
164 /** @var ICanCacheInMemory $cache */
165 $cache = $this->dice->create(ICanCacheInMemory::class);
167 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
168 self::assertInstanceOf(ICanCache::class, $cache);
171 public function testLock()
173 /** @var ICanLock $cache */
174 $lock = $this->dice->create(ICanLock::class);
176 self::assertInstanceOf(ICanLock::class, $lock);