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\Model\Config;
29 use Friendica\Core\Config\ValueObject\Cache;
30 use Friendica\Core\Config\Capability\IManageConfigValues;
31 use Friendica\Core\Lock\Capability\ICanLock;
32 use Friendica\Database\Database;
33 use Friendica\Test\Util\VFSTrait;
34 use Friendica\Util\BasePath;
35 use Friendica\Core\Config\Util\ConfigFileManager;
36 use Friendica\Util\Profiler;
37 use PHPUnit\Framework\TestCase;
38 use Psr\Log\LoggerInterface;
40 class DependencyCheckTest extends TestCase
49 protected function setUp() : void
55 $this->dice = (new Dice())
56 ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
60 * Test the creation of the BasePath
62 public function testBasePath()
64 /** @var BasePath $basePath */
65 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
67 self::assertInstanceOf(BasePath::class, $basePath);
68 self::assertEquals($this->root->url(), $basePath->getPath());
72 * Test the initial config cache
73 * Should not need any other files
75 public function testConfigFileLoader()
77 /** @var ConfigFileManager $configFileManager */
78 $configFileManager = $this->dice->create(ConfigFileManager::class);
80 self::assertInstanceOf(ConfigFileManager::class, $configFileManager);
82 $configCache = new Cache();
83 $configFileManager->setupCache($configCache);
85 self::assertNotEmpty($configCache->getAll());
86 self::assertArrayHasKey('database', $configCache->getAll());
87 self::assertArrayHasKey('system', $configCache->getAll());
90 public function testDatabase()
92 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
93 if (version_compare(PHP_VERSION, '7.3') < 0) {
94 $configCache = $this->dice->create(Cache::class);
95 $configCache->set('database', 'disable_pdo', true);
98 /** @var Database $database */
99 $database = $this->dice->create(Database::class);
101 self::assertInstanceOf(Database::class, $database);
102 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
103 self::assertNotNull($database->getConnection(), 'There is no database connection');
105 $result = $database->p("SELECT 1");
106 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
107 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
109 self::assertTrue($database->connected(), 'The database is not connected');
112 public function testAppMode()
114 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
115 if (version_compare(PHP_VERSION, '7.3') < 0) {
116 $configCache = $this->dice->create(Cache::class);
117 $configCache->set('database', 'disable_pdo', true);
120 /** @var App\Mode $mode */
121 $mode = $this->dice->create(App\Mode::class);
123 self::assertInstanceOf(App\Mode::class, $mode);
125 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
126 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
127 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
129 self::assertTrue($mode->isNormal(), 'Not in normal mode');
132 public function testConfiguration()
134 /** @var IManageConfigValues $config */
135 $config = $this->dice->create(IManageConfigValues::class);
137 self::assertInstanceOf(IManageConfigValues::class, $config);
139 self::assertNotEmpty($config->get('database', 'username'));
142 public function testLogger()
144 /** @var LoggerInterface $logger */
145 $logger = $this->dice->create(LoggerInterface::class, ['test']);
147 self::assertInstanceOf(LoggerInterface::class, $logger);
150 public function testDevLogger()
152 /** @var IManageConfigValues $config */
153 $config = $this->dice->create(IManageConfigValues::class);
154 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
156 /** @var LoggerInterface $logger */
157 $logger = $this->dice->create('$devLogger', ['dev']);
159 self::assertInstanceOf(LoggerInterface::class, $logger);
162 public function testCache()
164 /** @var ICanCache $cache */
165 $cache = $this->dice->create(ICanCache::class);
167 self::assertInstanceOf(ICanCache::class, $cache);
170 public function testMemoryCache()
172 /** @var ICanCacheInMemory $cache */
173 $cache = $this->dice->create(ICanCacheInMemory::class);
175 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
176 self::assertInstanceOf(ICanCache::class, $cache);
179 public function testLock()
181 /** @var ICanLock $cache */
182 $lock = $this->dice->create(ICanLock::class);
184 self::assertInstanceOf(ICanLock::class, $lock);