diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-17 15:17:59 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-19 10:38:26 +0200 |
commit | 2b7b7144d44cdb323039d8384f7a94fc6422e923 (patch) | |
tree | 6eada54697fa843a7d3de8d19e3b672d79877220 /tests | |
parent | dd0b9655b2dc72556f0a273f262357f5b058fe49 (diff) | |
download | nextcloud-server-2b7b7144d44cdb323039d8384f7a94fc6422e923.tar.gz nextcloud-server-2b7b7144d44cdb323039d8384f7a94fc6422e923.zip |
Allow crash reporters registration during app bootstrap
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Bootstrap/CoordinatorTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Support/CrashReport/RegistryTest.php | 48 |
2 files changed, 49 insertions, 5 deletions
diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 114872ed54d..c12e5eeb150 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -26,6 +26,7 @@ declare(strict_types=1); 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; @@ -46,6 +47,9 @@ class CoordinatorTest extends TestCase { /** @var IServerContainer|MockObject */ private $serverContainer; + /** @var Registry|MockObject */ + private $crashReporterRegistry; + /** @var IEventDispatcher|MockObject */ private $eventDispatcher; @@ -60,11 +64,13 @@ class CoordinatorTest extends TestCase { $this->appManager = $this->createMock(IAppManager::class); $this->serverContainer = $this->createMock(IServerContainer::class); + $this->crashReporterRegistry = $this->createMock(Registry::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->logger = $this->createMock(ILogger::class); $this->coordinator = new Coordinator( $this->serverContainer, + $this->crashReporterRegistry, $this->eventDispatcher, $this->logger ); diff --git a/tests/lib/Support/CrashReport/RegistryTest.php b/tests/lib/Support/CrashReport/RegistryTest.php index d85b006509e..f88902d7065 100644 --- a/tests/lib/Support/CrashReport/RegistryTest.php +++ b/tests/lib/Support/CrashReport/RegistryTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /** * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> * @@ -26,6 +28,8 @@ namespace Test\Support\CrashReport; use Exception; use OC\Support\CrashReport\Registry; +use OCP\AppFramework\QueryException; +use OCP\IServerContainer; use OCP\Support\CrashReport\ICollectBreadcrumbs; use OCP\Support\CrashReport\IMessageReporter; use OCP\Support\CrashReport\IReporter; @@ -33,26 +37,60 @@ use Test\TestCase; class RegistryTest extends TestCase { + /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */ + private $serverContainer; + /** @var Registry */ private $registry; protected function setUp(): void { parent::setUp(); - $this->registry = new Registry(); + $this->serverContainer = $this->createMock(IServerContainer::class); + + $this->registry = new Registry( + $this->serverContainer + ); } /** * Doesn't assert anything, just checks whether anything "explodes" */ - public function testDelegateToNone() { + public function testDelegateToNone(): void { $exception = new Exception('test'); $this->registry->delegateReport($exception); $this->addToAssertionCount(1); } - public function testDelegateBreadcrumbCollection() { + public function testRegisterLazyCantLoad(): void { + $reporterClass = '\OCA\MyApp\Reporter'; + $reporter = $this->createMock(IReporter::class); + $this->serverContainer->expects($this->once()) + ->method('query') + ->with($reporterClass) + ->willReturn($reporter); + $reporter->expects($this->once()) + ->method('report'); + $exception = new Exception('test'); + + $this->registry->registerLazy($reporterClass); + $this->registry->delegateReport($exception); + } + + public function testRegisterLazy(): void { + $reporterClass = '\OCA\MyApp\Reporter'; + $this->serverContainer->expects($this->once()) + ->method('query') + ->with($reporterClass) + ->willThrowException(new QueryException()); + $exception = new Exception('test'); + + $this->registry->registerLazy($reporterClass); + $this->registry->delegateReport($exception); + } + + public function testDelegateBreadcrumbCollection(): void { $reporter1 = $this->createMock(IReporter::class); $reporter2 = $this->createMock(ICollectBreadcrumbs::class); $message = 'hello'; @@ -66,7 +104,7 @@ class RegistryTest extends TestCase { $this->registry->delegateBreadcrumb($message, $category); } - public function testDelegateToAll() { + public function testDelegateToAll(): void { $reporter1 = $this->createMock(IReporter::class); $reporter2 = $this->createMock(IReporter::class); $exception = new Exception('test'); @@ -82,7 +120,7 @@ class RegistryTest extends TestCase { $this->registry->delegateReport($exception); } - public function testDelegateMessage() { + public function testDelegateMessage(): void { $reporter1 = $this->createMock(IReporter::class); $reporter2 = $this->createMock(IMessageReporter::class); $message = 'hello'; |