3 * @copyright Copyright (C) 2010-2024, 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 /** @var Database $database */
84 $database = $this->dice->create(Database::class);
86 self::assertInstanceOf(Database::class, $database);
87 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
88 self::assertNotNull($database->getConnection(), 'There is no database connection');
90 $result = $database->p("SELECT 1");
91 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
92 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
94 self::assertTrue($database->connected(), 'The database is not connected');
97 public function testAppMode()
99 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
100 if (version_compare(PHP_VERSION, '7.3') < 0) {
101 $configCache = $this->dice->create(Cache::class);
102 $configCache->set('database', 'disable_pdo', true);
105 /** @var App\Mode $mode */
106 $mode = $this->dice->create(App\Mode::class);
108 self::assertInstanceOf(App\Mode::class, $mode);
110 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
111 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
112 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
114 self::assertTrue($mode->isNormal(), 'Not in normal mode');
117 public function testConfiguration()
119 /** @var IManageConfigValues $config */
120 $config = $this->dice->create(IManageConfigValues::class);
122 self::assertInstanceOf(IManageConfigValues::class, $config);
124 self::assertNotEmpty($config->get('database', 'username'));
127 public function testLogger()
129 /** @var LoggerInterface $logger */
130 $logger = $this->dice->create(LoggerInterface::class, [['$channel' => 'test']]);
132 self::assertInstanceOf(LoggerInterface::class, $logger);
135 public function testDevLogger()
137 /** @var IManageConfigValues $config */
138 $config = $this->dice->create(IManageConfigValues::class);
139 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
141 /** @var LoggerInterface $logger */
142 $logger = $this->dice->create('$devLogger', ['dev']);
144 self::assertInstanceOf(LoggerInterface::class, $logger);
147 public function testCache()
149 /** @var ICanCache $cache */
150 $cache = $this->dice->create(ICanCache::class);
153 self::assertInstanceOf(ICanCache::class, $cache);
156 public function testMemoryCache()
158 /** @var ICanCacheInMemory $cache */
159 $cache = $this->dice->create(ICanCacheInMemory::class);
161 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
162 self::assertInstanceOf(ICanCache::class, $cache);
165 public function testLock()
167 /** @var ICanLock $cache */
168 $lock = $this->dice->create(ICanLock::class);
170 self::assertInstanceOf(ICanLock::class, $lock);