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.

136 lines
3.1 KiB

  1. <?php
  2. namespace functional;
  3. use Dice\Dice;
  4. use Friendica\App;
  5. use Friendica\Core\Config\Cache\ConfigCache;
  6. use Friendica\Core\Config\Configuration;
  7. use Friendica\Database\Database;
  8. use Friendica\Test\Util\VFSTrait;
  9. use Friendica\Util\BasePath;
  10. use Friendica\Util\ConfigFileLoader;
  11. use Friendica\Util\Profiler;
  12. use PHPUnit\Framework\TestCase;
  13. use Psr\Log\LoggerInterface;
  14. class dependencyCheck extends TestCase
  15. {
  16. use VFSTrait;
  17. /**
  18. * @var Dice
  19. */
  20. private $dice;
  21. protected function setUp()
  22. {
  23. parent::setUp();
  24. $this->setUpVfsDir();
  25. $this->dice = new Dice();
  26. $this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
  27. }
  28. /**
  29. * Test the creation of the BasePath
  30. */
  31. public function testBasePath()
  32. {
  33. /** @var BasePath $basePath */
  34. $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
  35. $this->assertInstanceOf(BasePath::class, $basePath);
  36. $this->assertEquals($this->root->url(), $basePath->getPath());
  37. }
  38. /**
  39. * Test the initial config cache
  40. * Should not need any other files
  41. */
  42. public function testConfigFileLoader()
  43. {
  44. /** @var ConfigFileLoader $configFileLoader */
  45. $configFileLoader = $this->dice->create(ConfigFileLoader::class);
  46. $this->assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
  47. $configCache = new ConfigCache();
  48. $configFileLoader->setupCache($configCache);
  49. $this->assertNotEmpty($configCache->getAll());
  50. $this->assertArrayHasKey('database', $configCache->getAll());
  51. $this->assertArrayHasKey('system', $configCache->getAll());
  52. }
  53. /**
  54. * Test the construction of a profiler class with DI
  55. */
  56. public function testProfiler()
  57. {
  58. /** @var Profiler $profiler */
  59. $profiler = $this->dice->create(Profiler::class);
  60. $this->assertInstanceOf(Profiler::class, $profiler);
  61. $configCache = new ConfigCache([
  62. 'system' => [
  63. 'profiler' => true,
  64. ],
  65. 'rendertime' => [
  66. 'callstack' => true,
  67. ]
  68. ]);
  69. $profiler = $this->dice->create(Profiler::class, [$configCache]);
  70. $this->assertInstanceOf(Profiler::class, $profiler);
  71. $this->assertTrue($profiler->isRendertime());
  72. }
  73. public function testDatabase()
  74. {
  75. /** @var Database $database */
  76. $database = $this->dice->create(Database::class);
  77. $this->assertInstanceOf(Database::class, $database);
  78. $this->assertTrue($database->connected());
  79. }
  80. public function testAppMode()
  81. {
  82. /** @var App\Mode $mode */
  83. $mode = $this->dice->create(App\Mode::class);
  84. $this->assertInstanceOf(App\Mode::class, $mode);
  85. $this->assertTrue($mode->isNormal());
  86. }
  87. public function testConfiguration()
  88. {
  89. /** @var Configuration $config */
  90. $config = $this->dice->create(Configuration::class);
  91. $this->assertInstanceOf(Configuration::class, $config);
  92. $this->assertNotEmpty($config->get('database', 'username'));
  93. }
  94. public function testLogger()
  95. {
  96. /** @var LoggerInterface $logger */
  97. $logger = $this->dice->create(LoggerInterface::class, ['test']);
  98. $this->assertInstanceOf(LoggerInterface::class, $logger);
  99. }
  100. public function testDevLogger()
  101. {
  102. /** @var LoggerInterface $logger */
  103. $logger = $this->dice->create('$devLogger', ['dev']);
  104. self::assertInstanceOf(LoggerInterface::class, $logger);
  105. }
  106. }