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;
26 use Friendica\Core\Cache\Capability\ICanCache;
27 use Friendica\Core\Cache\Capability\ICanCacheInMemory;
28 use Friendica\Core\Config\ValueObject\Cache;
29 use Friendica\Core\Config\Capability\IManageConfigValues;
30 use Friendica\Core\Lock\Capability\ICanLock;
31 use Friendica\Database\Database;
32 use Friendica\Test\Util\VFSTrait;
33 use Friendica\Util\BasePath;
34 use Friendica\Core\Config\Util\ConfigFileManager;
35 use PHPUnit\Framework\TestCase;
36 use Psr\Log\LoggerInterface;
38 class DependencyCheckTest extends TestCase
47 protected function setUp() : void
53 $this->dice = (new Dice())
54 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
55 ->addRule(BasePath::class, [
56 'constructParams' => [
61 ->addRule(LoggerInterface::class, ['constructParams' => ['test']]);
63 /** @var IManageConfigValues $config */
64 $config = $this->dice->create(IManageConfigValues::class);
65 $config->set('system', 'logfile', $this->root->url() . '/logs/friendica.log');
69 * Test the creation of the BasePath
71 public function testBasePath()
73 /** @var BasePath $basePath */
74 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
76 self::assertInstanceOf(BasePath::class, $basePath);
77 self::assertEquals($this->root->url(), $basePath->getPath());
81 * Test the initial config cache
82 * Should not need any other files
84 public function testConfigFileLoader()
86 /** @var ConfigFileManager $configFileManager */
87 $configFileManager = $this->dice->create(ConfigFileManager::class);
89 self::assertInstanceOf(ConfigFileManager::class, $configFileManager);
91 $configCache = new Cache();
92 $configFileManager->setupCache($configCache);
94 self::assertNotEmpty($configCache->getAll());
95 self::assertArrayHasKey('database', $configCache->getAll());
96 self::assertArrayHasKey('system', $configCache->getAll());
99 public function testDatabase()
101 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
102 if (version_compare(PHP_VERSION, '7.3') < 0) {
103 $configCache = $this->dice->create(Cache::class);
104 $configCache->set('database', 'disable_pdo', true);
107 /** @var Database $database */
108 $database = $this->dice->create(Database::class);
110 self::assertInstanceOf(Database::class, $database);
111 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
112 self::assertNotNull($database->getConnection(), 'There is no database connection');
114 $result = $database->p("SELECT 1");
115 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
116 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
118 self::assertTrue($database->connected(), 'The database is not connected');
121 public function testAppMode()
123 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
124 if (version_compare(PHP_VERSION, '7.3') < 0) {
125 $configCache = $this->dice->create(Cache::class);
126 $configCache->set('database', 'disable_pdo', true);
129 /** @var App\Mode $mode */
130 $mode = $this->dice->create(App\Mode::class);
132 self::assertInstanceOf(App\Mode::class, $mode);
134 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
135 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
136 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
138 self::assertTrue($mode->isNormal(), 'Not in normal mode');
141 public function testConfiguration()
143 /** @var IManageConfigValues $config */
144 $config = $this->dice->create(IManageConfigValues::class);
146 self::assertInstanceOf(IManageConfigValues::class, $config);
148 self::assertNotEmpty($config->get('database', 'username'));
151 public function testLogger()
153 /** @var LoggerInterface $logger */
154 $logger = $this->dice->create(LoggerInterface::class, [['$channel' => 'test']]);
156 self::assertInstanceOf(LoggerInterface::class, $logger);
159 public function testDevLogger()
161 /** @var IManageConfigValues $config */
162 $config = $this->dice->create(IManageConfigValues::class);
163 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
165 /** @var LoggerInterface $logger */
166 $logger = $this->dice->create('$devLogger', [['$channel' => 'dev']]);
168 self::assertInstanceOf(LoggerInterface::class, $logger);
171 public function testCache()
173 /** @var ICanCache $cache */
174 $cache = $this->dice->create(ICanCache::class);
177 self::assertInstanceOf(ICanCache::class, $cache);
180 public function testMemoryCache()
182 /** @var ICanCacheInMemory $cache */
183 $cache = $this->dice->create(ICanCacheInMemory::class);
185 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
186 self::assertInstanceOf(ICanCache::class, $cache);
189 public function testLock()
191 /** @var ICanLock $cache */
192 $lock = $this->dice->create(ICanLock::class);
194 self::assertInstanceOf(ICanLock::class, $lock);