CoordinatorTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace lib\AppFramework\Bootstrap;
  8. use OC\AppFramework\Bootstrap\Coordinator;
  9. use OC\Support\CrashReport\Registry;
  10. use OCP\App\IAppManager;
  11. use OCP\AppFramework\App;
  12. use OCP\AppFramework\Bootstrap\IBootContext;
  13. use OCP\AppFramework\Bootstrap\IBootstrap;
  14. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  15. use OCP\AppFramework\QueryException;
  16. use OCP\Dashboard\IManager;
  17. use OCP\Diagnostics\IEventLogger;
  18. use OCP\EventDispatcher\IEventDispatcher;
  19. use OCP\IServerContainer;
  20. use PHPUnit\Framework\MockObject\MockObject;
  21. use Psr\Log\LoggerInterface;
  22. use Test\TestCase;
  23. class CoordinatorTest extends TestCase {
  24. /** @var IAppManager|MockObject */
  25. private $appManager;
  26. /** @var IServerContainer|MockObject */
  27. private $serverContainer;
  28. /** @var Registry|MockObject */
  29. private $crashReporterRegistry;
  30. /** @var IManager|MockObject */
  31. private $dashboardManager;
  32. /** @var IEventDispatcher|MockObject */
  33. private $eventDispatcher;
  34. /** @var IEventLogger|MockObject */
  35. private $eventLogger;
  36. /** @var LoggerInterface|MockObject */
  37. private $logger;
  38. /** @var Coordinator */
  39. private $coordinator;
  40. protected function setUp(): void {
  41. parent::setUp();
  42. $this->appManager = $this->createMock(IAppManager::class);
  43. $this->serverContainer = $this->createMock(IServerContainer::class);
  44. $this->crashReporterRegistry = $this->createMock(Registry::class);
  45. $this->dashboardManager = $this->createMock(IManager::class);
  46. $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
  47. $this->eventLogger = $this->createMock(IEventLogger::class);
  48. $this->logger = $this->createMock(LoggerInterface::class);
  49. $this->coordinator = new Coordinator(
  50. $this->serverContainer,
  51. $this->crashReporterRegistry,
  52. $this->dashboardManager,
  53. $this->eventDispatcher,
  54. $this->eventLogger,
  55. $this->appManager,
  56. $this->logger,
  57. );
  58. }
  59. public function testBootAppNotLoadable(): void {
  60. $appId = 'settings';
  61. $this->serverContainer->expects($this->once())
  62. ->method('query')
  63. ->with(\OCA\Settings\AppInfo\Application::class)
  64. ->willThrowException(new QueryException(''));
  65. $this->logger->expects($this->once())
  66. ->method('error');
  67. $this->coordinator->bootApp($appId);
  68. }
  69. public function testBootAppNotBootable(): void {
  70. $appId = 'settings';
  71. $mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class);
  72. $this->serverContainer->expects($this->once())
  73. ->method('query')
  74. ->with(\OCA\Settings\AppInfo\Application::class)
  75. ->willReturn($mockApp);
  76. $this->coordinator->bootApp($appId);
  77. }
  78. public function testBootApp(): void {
  79. $appId = 'settings';
  80. $mockApp = new class extends App implements IBootstrap {
  81. public function __construct() {
  82. parent::__construct('test', []);
  83. }
  84. public function register(IRegistrationContext $context): void {
  85. }
  86. public function boot(IBootContext $context): void {
  87. }
  88. };
  89. $this->serverContainer->expects($this->once())
  90. ->method('query')
  91. ->with(\OCA\Settings\AppInfo\Application::class)
  92. ->willReturn($mockApp);
  93. $this->coordinator->bootApp($appId);
  94. }
  95. }