aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php
blob: 05e7a1b71c7674fe81ba9bfa5cc8779e2db0d952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace lib\AppFramework\Bootstrap;

use OC\AppFramework\Bootstrap\Coordinator;
use OC\Support\CrashReport\Registry;
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException;
use OCP\Dashboard\IManager;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class CoordinatorTest extends TestCase {
	/** @var IAppManager|MockObject */
	private $appManager;

	/** @var IServerContainer|MockObject */
	private $serverContainer;

	/** @var Registry|MockObject */
	private $crashReporterRegistry;

	/** @var IManager|MockObject */
	private $dashboardManager;

	/** @var IEventDispatcher|MockObject */
	private $eventDispatcher;

	/** @var IEventLogger|MockObject */
	private $eventLogger;

	/** @var LoggerInterface|MockObject */
	private $logger;

	/** @var Coordinator */
	private $coordinator;

	protected function setUp(): void {
		parent::setUp();

		$this->appManager = $this->createMock(IAppManager::class);
		$this->serverContainer = $this->createMock(IServerContainer::class);
		$this->crashReporterRegistry = $this->createMock(Registry::class);
		$this->dashboardManager = $this->createMock(IManager::class);
		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
		$this->eventLogger = $this->createMock(IEventLogger::class);
		$this->logger = $this->createMock(LoggerInterface::class);

		$this->coordinator = new Coordinator(
			$this->serverContainer,
			$this->crashReporterRegistry,
			$this->dashboardManager,
			$this->eventDispatcher,
			$this->eventLogger,
			$this->appManager,
			$this->logger,
		);
	}

	public function testBootAppNotLoadable(): void {
		$appId = 'settings';
		$this->serverContainer->expects($this->once())
			->method('query')
			->with(\OCA\Settings\AppInfo\Application::class)
			->willThrowException(new QueryException(''));
		$this->logger->expects($this->once())
			->method('error');

		$this->coordinator->bootApp($appId);
	}

	public function testBootAppNotBootable(): void {
		$appId = 'settings';
		$mockApp = $this->createMock(\OCA\Settings\AppInfo\Application::class);
		$this->serverContainer->expects($this->once())
			->method('query')
			->with(\OCA\Settings\AppInfo\Application::class)
			->willReturn($mockApp);

		$this->coordinator->bootApp($appId);
	}

	public function testBootApp(): void {
		$appId = 'settings';
		$mockApp = new class extends App implements IBootstrap {
			public function __construct() {
				parent::__construct('test', []);
			}

			public function register(IRegistrationContext $context): void {
			}

			public function boot(IBootContext $context): void {
			}
		};
		$this->serverContainer->expects($this->once())
			->method('query')
			->with(\OCA\Settings\AppInfo\Application::class)
			->willReturn($mockApp);

		$this->coordinator->bootApp($appId);
	}
}