From 2b7b7144d44cdb323039d8384f7a94fc6422e923 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 17 Jun 2020 15:17:59 +0200 Subject: Allow crash reporters registration during app bootstrap Signed-off-by: Christoph Wurst --- tests/lib/Support/CrashReport/RegistryTest.php | 48 +++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'tests/lib/Support') 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 @@ * @@ -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'; -- cgit v1.2.3