1
0

CoordinatorTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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->logger
  72. );
  73. }
  74. public function testBootAppNotLoadable(): void {
  75. $appId = 'settings';
  76. $this->serverContainer->expects($this->once())
  77. ->method('query')
  78. ->with(\OCA\Settings\AppInfo\Application::class)
  79. ->willThrowException(new QueryException(""));
  80. $this->logger->expects($this->once())
  81. ->method('error');
  82. $this->coordinator->bootApp($appId);
  83. }
  84. public function testBootAppNotBootable(): void {
  85. $appId = 'settings';
  86. $mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class);
  87. $this->serverContainer->expects($this->once())
  88. ->method('query')
  89. ->with(\OCA\Settings\AppInfo\Application::class)
  90. ->willReturn($mockApp);
  91. $this->coordinator->bootApp($appId);
  92. }
  93. public function testBootApp(): void {
  94. $appId = 'settings';
  95. $mockApp = new class extends App implements IBootstrap {
  96. public function __construct() {
  97. parent::__construct('test', []);
  98. }
  99. public function register(IRegistrationContext $context): void {
  100. }
  101. public function boot(IBootContext $context): void {
  102. }
  103. };
  104. $this->serverContainer->expects($this->once())
  105. ->method('query')
  106. ->with(\OCA\Settings\AppInfo\Application::class)
  107. ->willReturn($mockApp);
  108. $this->coordinator->bootApp($appId);
  109. }
  110. }