CoordinatorTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\EventDispatcher\IEventDispatcher;
  34. use OCP\IServerContainer;
  35. use PHPUnit\Framework\MockObject\MockObject;
  36. use Psr\Log\LoggerInterface;
  37. use Test\TestCase;
  38. class CoordinatorTest extends TestCase {
  39. /** @var IAppManager|MockObject */
  40. private $appManager;
  41. /** @var IServerContainer|MockObject */
  42. private $serverContainer;
  43. /** @var Registry|MockObject */
  44. private $crashReporterRegistry;
  45. /** @var IManager|MockObject */
  46. private $dashboardManager;
  47. /** @var IEventDispatcher|MockObject */
  48. private $eventDispatcher;
  49. /** @var LoggerInterface|MockObject */
  50. private $logger;
  51. /** @var Coordinator */
  52. private $coordinator;
  53. protected function setUp(): void {
  54. parent::setUp();
  55. $this->appManager = $this->createMock(IAppManager::class);
  56. $this->serverContainer = $this->createMock(IServerContainer::class);
  57. $this->crashReporterRegistry = $this->createMock(Registry::class);
  58. $this->dashboardManager = $this->createMock(IManager::class);
  59. $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
  60. $this->logger = $this->createMock(LoggerInterface::class);
  61. $this->coordinator = new Coordinator(
  62. $this->serverContainer,
  63. $this->crashReporterRegistry,
  64. $this->dashboardManager,
  65. $this->eventDispatcher,
  66. $this->logger
  67. );
  68. }
  69. public function testBootAppNotLoadable(): void {
  70. $appId = 'settings';
  71. $this->serverContainer->expects($this->once())
  72. ->method('query')
  73. ->with(\OCA\Settings\AppInfo\Application::class)
  74. ->willThrowException(new QueryException(""));
  75. $this->logger->expects($this->once())
  76. ->method('error');
  77. $this->coordinator->bootApp($appId);
  78. }
  79. public function testBootAppNotBootable(): void {
  80. $appId = 'settings';
  81. $mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class);
  82. $this->serverContainer->expects($this->once())
  83. ->method('query')
  84. ->with(\OCA\Settings\AppInfo\Application::class)
  85. ->willReturn($mockApp);
  86. $this->coordinator->bootApp($appId);
  87. }
  88. public function testBootApp(): void {
  89. $appId = 'settings';
  90. $mockApp = new class extends App implements IBootstrap {
  91. public function __construct() {
  92. parent::__construct('test', []);
  93. }
  94. public function register(IRegistrationContext $context): void {
  95. }
  96. public function boot(IBootContext $context): void {
  97. }
  98. };
  99. $this->serverContainer->expects($this->once())
  100. ->method('query')
  101. ->with(\OCA\Settings\AppInfo\Application::class)
  102. ->willReturn($mockApp);
  103. $this->coordinator->bootApp($appId);
  104. }
  105. }