2019-07-21 01:22:10 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
namespace Friendica\Test\functional;
|
2019-07-21 01:22:10 +02:00
|
|
|
|
|
|
|
use Dice\Dice;
|
|
|
|
use Friendica\App;
|
2019-08-04 15:42:39 +02:00
|
|
|
use Friendica\Core\Cache\ICache;
|
|
|
|
use Friendica\Core\Cache\IMemoryCache;
|
2020-01-19 22:23:44 +01:00
|
|
|
use Friendica\Core\Config\Cache;
|
2020-01-19 21:29:36 +01:00
|
|
|
use Friendica\Core\Config\IConfig;
|
2019-08-04 15:42:39 +02:00
|
|
|
use Friendica\Core\Lock\ILock;
|
2019-07-21 01:22:10 +02:00
|
|
|
use Friendica\Database\Database;
|
|
|
|
use Friendica\Test\Util\VFSTrait;
|
|
|
|
use Friendica\Util\BasePath;
|
|
|
|
use Friendica\Util\ConfigFileLoader;
|
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
2020-10-18 20:31:57 +02:00
|
|
|
class DependencyCheckTest extends TestCase
|
2019-07-21 01:22:10 +02:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Dice
|
|
|
|
*/
|
|
|
|
private $dice;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
|
|
|
|
2019-08-05 09:02:55 +02:00
|
|
|
$this->dice = (new Dice())
|
|
|
|
->addRules(include __DIR__ . '/../../static/dependencies.config.php');
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the creation of the BasePath
|
|
|
|
*/
|
|
|
|
public function testBasePath()
|
|
|
|
{
|
|
|
|
/** @var BasePath $basePath */
|
|
|
|
$basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(BasePath::class, $basePath);
|
|
|
|
self::assertEquals($this->root->url(), $basePath->getPath());
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the initial config cache
|
|
|
|
* Should not need any other files
|
|
|
|
*/
|
|
|
|
public function testConfigFileLoader()
|
|
|
|
{
|
|
|
|
/** @var ConfigFileLoader $configFileLoader */
|
|
|
|
$configFileLoader = $this->dice->create(ConfigFileLoader::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-01-19 22:23:44 +01:00
|
|
|
$configCache = new Cache();
|
2019-07-21 01:22:10 +02:00
|
|
|
$configFileLoader->setupCache($configCache);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNotEmpty($configCache->getAll());
|
|
|
|
self::assertArrayHasKey('database', $configCache->getAll());
|
|
|
|
self::assertArrayHasKey('system', $configCache->getAll());
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the construction of a profiler class with DI
|
|
|
|
*/
|
|
|
|
public function testProfiler()
|
|
|
|
{
|
|
|
|
/** @var Profiler $profiler */
|
|
|
|
$profiler = $this->dice->create(Profiler::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(Profiler::class, $profiler);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-01-19 22:23:44 +01:00
|
|
|
$configCache = new Cache([
|
2019-07-21 01:22:10 +02:00
|
|
|
'system' => [
|
|
|
|
'profiler' => true,
|
|
|
|
],
|
|
|
|
'rendertime' => [
|
|
|
|
'callstack' => true,
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-07-24 12:48:29 +02:00
|
|
|
// create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
|
2019-08-06 07:43:13 +02:00
|
|
|
$this->dice = new Dice();
|
2019-08-05 09:22:06 +02:00
|
|
|
$profiler = $this->dice->create(Profiler::class, [$configCache]);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(Profiler::class, $profiler);
|
|
|
|
self::assertTrue($profiler->isRendertime());
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDatabase()
|
|
|
|
{
|
|
|
|
/** @var Database $database */
|
|
|
|
$database = $this->dice->create(Database::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(Database::class, $database);
|
2020-11-07 10:02:21 +01:00
|
|
|
self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI]);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue($database->connected());
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAppMode()
|
|
|
|
{
|
|
|
|
/** @var App\Mode $mode */
|
|
|
|
$mode = $this->dice->create(App\Mode::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(App\Mode::class, $mode);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue($mode->isNormal());
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfiguration()
|
|
|
|
{
|
2020-01-19 21:29:36 +01:00
|
|
|
/** @var IConfig $config */
|
|
|
|
$config = $this->dice->create(IConfig::class);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(IConfig::class, $config);
|
2019-07-21 01:22:10 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNotEmpty($config->get('database', 'username'));
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogger()
|
|
|
|
{
|
|
|
|
/** @var LoggerInterface $logger */
|
|
|
|
$logger = $this->dice->create(LoggerInterface::class, ['test']);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(LoggerInterface::class, $logger);
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDevLogger()
|
|
|
|
{
|
2020-01-19 21:29:36 +01:00
|
|
|
/** @var IConfig $config */
|
|
|
|
$config = $this->dice->create(IConfig::class);
|
2019-12-11 20:30:31 +01:00
|
|
|
$config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
|
|
|
|
|
2019-07-21 01:22:10 +02:00
|
|
|
/** @var LoggerInterface $logger */
|
|
|
|
$logger = $this->dice->create('$devLogger', ['dev']);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(LoggerInterface::class, $logger);
|
2019-08-04 15:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCache()
|
|
|
|
{
|
|
|
|
/** @var ICache $cache */
|
|
|
|
$cache = $this->dice->create(ICache::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(ICache::class, $cache);
|
2019-08-04 15:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMemoryCache()
|
|
|
|
{
|
|
|
|
/** @var IMemoryCache $cache */
|
|
|
|
$cache = $this->dice->create(IMemoryCache::class);
|
|
|
|
|
|
|
|
// We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(ICache::class, $cache);
|
2019-08-04 15:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLock()
|
|
|
|
{
|
|
|
|
/** @var ILock $cache */
|
|
|
|
$lock = $this->dice->create(ILock::class);
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(ILock::class, $lock);
|
2019-07-21 01:22:10 +02:00
|
|
|
}
|
|
|
|
}
|