Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
4.8KB

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2020, Friendica
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  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.
  11. *
  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.
  16. *
  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/>.
  19. *
  20. */
  21. namespace functional;
  22. use Dice\Dice;
  23. use Friendica\App;
  24. use Friendica\Core\Cache\ICache;
  25. use Friendica\Core\Cache\IMemoryCache;
  26. use Friendica\Core\Config\Cache;
  27. use Friendica\Core\Config\IConfig;
  28. use Friendica\Core\Lock\ILock;
  29. use Friendica\Database\Database;
  30. use Friendica\Test\Util\VFSTrait;
  31. use Friendica\Util\BasePath;
  32. use Friendica\Util\ConfigFileLoader;
  33. use Friendica\Util\Profiler;
  34. use PHPUnit\Framework\TestCase;
  35. use Psr\Log\LoggerInterface;
  36. class dependencyCheck extends TestCase
  37. {
  38. use VFSTrait;
  39. /**
  40. * @var Dice
  41. */
  42. private $dice;
  43. protected function setUp()
  44. {
  45. parent::setUp();
  46. $this->setUpVfsDir();
  47. $this->dice = (new Dice())
  48. ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
  49. }
  50. /**
  51. * Test the creation of the BasePath
  52. */
  53. public function testBasePath()
  54. {
  55. /** @var BasePath $basePath */
  56. $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
  57. $this->assertInstanceOf(BasePath::class, $basePath);
  58. $this->assertEquals($this->root->url(), $basePath->getPath());
  59. }
  60. /**
  61. * Test the initial config cache
  62. * Should not need any other files
  63. */
  64. public function testConfigFileLoader()
  65. {
  66. /** @var ConfigFileLoader $configFileLoader */
  67. $configFileLoader = $this->dice->create(ConfigFileLoader::class);
  68. $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
  69. $configCache = new Cache();
  70. $configFileLoader->setupCache($configCache);
  71. $this->assertNotEmpty($configCache->getAll());
  72. $this->assertArrayHasKey('database', $configCache->getAll());
  73. $this->assertArrayHasKey('system', $configCache->getAll());
  74. }
  75. /**
  76. * Test the construction of a profiler class with DI
  77. */
  78. public function testProfiler()
  79. {
  80. /** @var Profiler $profiler */
  81. $profiler = $this->dice->create(Profiler::class);
  82. $this->assertInstanceOf(Profiler::class, $profiler);
  83. $configCache = new Cache([
  84. 'system' => [
  85. 'profiler' => true,
  86. ],
  87. 'rendertime' => [
  88. 'callstack' => true,
  89. ]
  90. ]);
  91. // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
  92. $this->dice = new Dice();
  93. $profiler = $this->dice->create(Profiler::class, [$configCache]);
  94. $this->assertInstanceOf(Profiler::class, $profiler);
  95. $this->assertTrue($profiler->isRendertime());
  96. }
  97. public function testDatabase()
  98. {
  99. /** @var Database $database */
  100. $database = $this->dice->create(Database::class);
  101. $this->assertInstanceOf(Database::class, $database);
  102. $this->assertTrue($database->connected());
  103. }
  104. public function testAppMode()
  105. {
  106. /** @var App\Mode $mode */
  107. $mode = $this->dice->create(App\Mode::class);
  108. $this->assertInstanceOf(App\Mode::class, $mode);
  109. $this->assertTrue($mode->isNormal());
  110. }
  111. public function testConfiguration()
  112. {
  113. /** @var IConfig $config */
  114. $config = $this->dice->create(IConfig::class);
  115. $this->assertInstanceOf(IConfig::class, $config);
  116. $this->assertNotEmpty($config->get('database', 'username'));
  117. }
  118. public function testLogger()
  119. {
  120. /** @var LoggerInterface $logger */
  121. $logger = $this->dice->create(LoggerInterface::class, ['test']);
  122. $this->assertInstanceOf(LoggerInterface::class, $logger);
  123. }
  124. public function testDevLogger()
  125. {
  126. /** @var IConfig $config */
  127. $config = $this->dice->create(IConfig::class);
  128. $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
  129. /** @var LoggerInterface $logger */
  130. $logger = $this->dice->create('$devLogger', ['dev']);
  131. $this->assertInstanceOf(LoggerInterface::class, $logger);
  132. }
  133. public function testCache()
  134. {
  135. /** @var ICache $cache */
  136. $cache = $this->dice->create(ICache::class);
  137. $this->assertInstanceOf(ICache::class, $cache);
  138. }
  139. public function testMemoryCache()
  140. {
  141. /** @var IMemoryCache $cache */
  142. $cache = $this->dice->create(IMemoryCache::class);
  143. // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
  144. $this->assertInstanceOf(ICache::class, $cache);
  145. }
  146. public function testLock()
  147. {
  148. /** @var ILock $cache */
  149. $lock = $this->dice->create(ILock::class);
  150. $this->assertInstanceOf(ILock::class, $lock);
  151. }
  152. }