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.
 
 
 
 
 
 

214 lines
6.1 KiB

  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 Friendica\Test\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 DependencyCheckTest 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. self::assertInstanceOf(BasePath::class, $basePath);
  58. self::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. self::assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
  69. $configCache = new Cache();
  70. $configFileLoader->setupCache($configCache);
  71. self::assertNotEmpty($configCache->getAll());
  72. self::assertArrayHasKey('database', $configCache->getAll());
  73. self::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. self::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. self::assertInstanceOf(Profiler::class, $profiler);
  95. self::assertTrue($profiler->isRendertime());
  96. }
  97. public function testDatabase()
  98. {
  99. // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
  100. if (version_compare(PHP_VERSION, '7.3') < 0) {
  101. $configCache = $this->dice->create(Cache::class);
  102. $configCache->set('database', 'disable_pdo', true);
  103. }
  104. /** @var Database $database */
  105. $database = $this->dice->create(Database::class);
  106. self::assertInstanceOf(Database::class, $database);
  107. self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
  108. self::assertNotNull($database->getConnection(), 'There is no database connection');
  109. $result = $database->p("SELECT 1");
  110. self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
  111. self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
  112. self::assertTrue($database->connected(), 'The database is not connected');
  113. }
  114. public function testAppMode()
  115. {
  116. // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
  117. if (version_compare(PHP_VERSION, '7.3') < 0) {
  118. $configCache = $this->dice->create(Cache::class);
  119. $configCache->set('database', 'disable_pdo', true);
  120. }
  121. /** @var App\Mode $mode */
  122. $mode = $this->dice->create(App\Mode::class);
  123. self::assertInstanceOf(App\Mode::class, $mode);
  124. self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
  125. self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
  126. self::assertTrue($mode->has(App\Mode::DBCONFIGAVAILABLE), 'Database config is not available');
  127. self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
  128. self::assertTrue($mode->isNormal(), 'Not in normal mode');
  129. }
  130. public function testConfiguration()
  131. {
  132. /** @var IConfig $config */
  133. $config = $this->dice->create(IConfig::class);
  134. self::assertInstanceOf(IConfig::class, $config);
  135. self::assertNotEmpty($config->get('database', 'username'));
  136. }
  137. public function testLogger()
  138. {
  139. /** @var LoggerInterface $logger */
  140. $logger = $this->dice->create(LoggerInterface::class, ['test']);
  141. self::assertInstanceOf(LoggerInterface::class, $logger);
  142. }
  143. public function testDevLogger()
  144. {
  145. /** @var IConfig $config */
  146. $config = $this->dice->create(IConfig::class);
  147. $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
  148. /** @var LoggerInterface $logger */
  149. $logger = $this->dice->create('$devLogger', ['dev']);
  150. self::assertInstanceOf(LoggerInterface::class, $logger);
  151. }
  152. public function testCache()
  153. {
  154. /** @var ICache $cache */
  155. $cache = $this->dice->create(ICache::class);
  156. self::assertInstanceOf(ICache::class, $cache);
  157. }
  158. public function testMemoryCache()
  159. {
  160. /** @var IMemoryCache $cache */
  161. $cache = $this->dice->create(IMemoryCache::class);
  162. // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
  163. self::assertInstanceOf(ICache::class, $cache);
  164. }
  165. public function testLock()
  166. {
  167. /** @var ILock $cache */
  168. $lock = $this->dice->create(ILock::class);
  169. self::assertInstanceOf(ILock::class, $lock);
  170. }
  171. }