SupportedDatabaseTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Tests;
  8. use Doctrine\DBAL\Platforms\SqlitePlatform;
  9. use OCA\Settings\SetupChecks\SupportedDatabase;
  10. use OCP\IDBConnection;
  11. use OCP\IL10N;
  12. use OCP\IUrlGenerator;
  13. use OCP\SetupCheck\SetupResult;
  14. use Test\TestCase;
  15. /**
  16. * @group DB
  17. */
  18. class SupportedDatabaseTest extends TestCase {
  19. private IL10N $l10n;
  20. private IUrlGenerator $urlGenerator;
  21. private IDBConnection $connection;
  22. private SupportedDatabase $check;
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  26. $this->urlGenerator = $this->getMockBuilder(IUrlGenerator::class)->getMock();
  27. $this->connection = \OCP\Server::get(IDBConnection::class);
  28. $this->check = new SupportedDatabase(
  29. $this->l10n,
  30. $this->urlGenerator,
  31. \OCP\Server::get(IDBConnection::class)
  32. );
  33. }
  34. public function testPass(): void {
  35. $platform = $this->connection->getDatabasePlatform();
  36. if ($platform instanceof SqlitePlatform) {
  37. /** SQlite always gets a warning */
  38. $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
  39. } else {
  40. $this->assertContains($this->check->run()->getSeverity(), [SetupResult::SUCCESS, SetupResult::INFO]);
  41. }
  42. }
  43. }