CoordinatorTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. namespace lib\AppFramework\Bootstrap;
  24. use OC\AppFramework\Bootstrap\Coordinator;
  25. use OC\Support\CrashReport\Registry;
  26. use OCP\App\IAppManager;
  27. use OCP\AppFramework\App;
  28. use OCP\AppFramework\Bootstrap\IBootContext;
  29. use OCP\AppFramework\Bootstrap\IBootstrap;
  30. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  31. use OCP\AppFramework\QueryException;
  32. use OCP\Dashboard\IManager;
  33. use OCP\Diagnostics\IEventLogger;
  34. use OCP\EventDispatcher\IEventDispatcher;
  35. use OCP\IServerContainer;
  36. use PHPUnit\Framework\MockObject\MockObject;
  37. use Psr\Log\LoggerInterface;
  38. use Test\TestCase;
  39. class CoordinatorTest extends TestCase {
  40. /** @var IAppManager|MockObject */
  41. private $appManager;
  42. /** @var IServerContainer|MockObject */
  43. private $serverContainer;
  44. /** @var Registry|MockObject */
  45. private $crashReporterRegistry;
  46. /** @var IManager|MockObject */
  47. private $dashboardManager;
  48. /** @var IEventDispatcher|MockObject */
  49. private $eventDispatcher;
  50. /** @var IEventLogger|MockObject */
  51. private $eventLogger;
  52. /** @var LoggerInterface|MockObject */
  53. private $logger;
  54. /** @var Coordinator */
  55. private $coordinator;
  56. protected function setUp(): void {
  57. parent::setUp();
  58. $this->appManager = $this->createMock(IAppManager::class);
  59. $this->serverContainer = $this->createMock(IServerContainer::class);
  60. $this->crashReporterRegistry = $this->createMock(Registry::class);
  61. $this->dashboardManager = $this->createMock(IManager::class);
  62. $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
  63. $this->eventLogger = $this->createMock(IEventLogger::class);
  64. $this->logger = $this->createMock(LoggerInterface::class);
  65. $this->coordinator = new Coordinator(
  66. $this->serverContainer,
  67. $this->crashReporterRegistry,
  68. $this->dashboardManager,
  69. $this->eventDispatcher,
  70. $this->eventLogger,
  71. $this->appManager,
  72. $this->logger,
  73. );
  74. }
  75. public function testBootAppNotLoadable(): void {
  76. $appId = 'settings';
  77. $this->serverContainer->expects($this->once())
  78. ->method('query')
  79. ->with(\OCA\Settings\AppInfo\Application::class)
  80. ->willThrowException(new QueryException(""));
  81. $this->logger->expects($this->once())
  82. ->method('error');
  83. $this->coordinator->bootApp($appId);
  84. }
  85. public function testBootAppNotBootable(): void {
  86. $appId = 'settings';
  87. $mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class);
  88. $this->serverContainer->expects($this->once())
  89. ->method('query')
  90. ->with(\OCA\Settings\AppInfo\Application::class)
  91. ->willReturn($mockApp);
  92. $this->coordinator->bootApp($appId);
  93. }
  94. public function testBootApp(): void {
  95. $appId = 'settings';
  96. $mockApp = new class extends App implements IBootstrap {
  97. public function __construct() {
  98. parent::__construct('test', []);
  99. }
  100. public function register(IRegistrationContext $context): void {
  101. }
  102. public function boot(IBootContext $context): void {
  103. }
  104. };
  105. $this->serverContainer->expects($this->once())
  106. ->method('query')
  107. ->with(\OCA\Settings\AppInfo\Application::class)
  108. ->willReturn($mockApp);
  109. $this->coordinator->bootApp($appId);
  110. }
  111. }