7 use Friendica\Core\Cache\ICache;
8 use Friendica\Core\Cache\IMemoryCache;
9 use Friendica\Core\Config\Cache\ConfigCache;
10 use Friendica\Core\Config\Configuration;
11 use Friendica\Core\Lock\ILock;
12 use Friendica\Database\Database;
13 use Friendica\Test\Util\VFSTrait;
14 use Friendica\Util\BasePath;
15 use Friendica\Util\ConfigFileLoader;
16 use Friendica\Util\Profiler;
17 use PHPUnit\Framework\TestCase;
18 use Psr\Log\LoggerInterface;
20 class dependencyCheck extends TestCase
29 protected function setUp()
35 $this->dice = (new Dice())
36 ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
40 * Test the creation of the BasePath
42 public function testBasePath()
44 /** @var BasePath $basePath */
45 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
47 $this->assertInstanceOf(BasePath::class, $basePath);
48 $this->assertEquals($this->root->url(), $basePath->getPath());
52 * Test the initial config cache
53 * Should not need any other files
55 public function testConfigFileLoader()
57 /** @var ConfigFileLoader $configFileLoader */
58 $configFileLoader = $this->dice->create(ConfigFileLoader::class);
60 $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
62 $configCache = new ConfigCache();
63 $configFileLoader->setupCache($configCache);
65 $this->assertNotEmpty($configCache->getAll());
66 $this->assertArrayHasKey('database', $configCache->getAll());
67 $this->assertArrayHasKey('system', $configCache->getAll());
71 * Test the construction of a profiler class with DI
73 public function testProfiler()
75 /** @var Profiler $profiler */
76 $profiler = $this->dice->create(Profiler::class);
78 $this->assertInstanceOf(Profiler::class, $profiler);
80 $configCache = new ConfigCache([
89 // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
90 $this->dice = new Dice();
91 $profiler = $this->dice->create(Profiler::class, [$configCache]);
93 $this->assertInstanceOf(Profiler::class, $profiler);
94 $this->assertTrue($profiler->isRendertime());
97 public function testDatabase()
99 /** @var Database $database */
100 $database = $this->dice->create(Database::class);
102 $this->assertInstanceOf(Database::class, $database);
103 $this->assertTrue($database->connected());
106 public function testAppMode()
108 /** @var App\Mode $mode */
109 $mode = $this->dice->create(App\Mode::class);
111 $this->assertInstanceOf(App\Mode::class, $mode);
113 $this->assertTrue($mode->isNormal());
116 public function testConfiguration()
118 /** @var Configuration $config */
119 $config = $this->dice->create(Configuration::class);
121 $this->assertInstanceOf(Configuration::class, $config);
123 $this->assertNotEmpty($config->get('database', 'username'));
126 public function testLogger()
128 /** @var LoggerInterface $logger */
129 $logger = $this->dice->create(LoggerInterface::class, ['test']);
131 $this->assertInstanceOf(LoggerInterface::class, $logger);
134 public function testDevLogger()
136 /** @var Configuration $config */
137 $config = $this->dice->create(Configuration::class);
138 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
140 /** @var LoggerInterface $logger */
141 $logger = $this->dice->create('$devLogger', ['dev']);
143 $this->assertInstanceOf(LoggerInterface::class, $logger);
146 public function testCache()
148 /** @var ICache $cache */
149 $cache = $this->dice->create(ICache::class);
151 $this->assertInstanceOf(ICache::class, $cache);
154 public function testMemoryCache()
156 /** @var IMemoryCache $cache */
157 $cache = $this->dice->create(IMemoryCache::class);
159 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
160 $this->assertInstanceOf(ICache::class, $cache);
163 public function testLock()
165 /** @var ILock $cache */
166 $lock = $this->dice->create(ILock::class);
168 $this->assertInstanceOf(ILock::class, $lock);