From 181aab416a5f3032034273b5eaa2eb6654982482 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Jun 2021 10:57:09 +0200 Subject: [PATCH 1/3] Fix warnings about logException Signed-off-by: Joas Schilling --- tests/lib/AppFramework/Bootstrap/CoordinatorTest.php | 2 +- .../Bootstrap/RegistrationContextTest.php | 12 ++++++------ .../Middleware/Security/SecurityMiddlewareTest.php | 4 ++-- tests/lib/CapabilitiesManagerTest.php | 2 +- .../Collaboration/Resources/ProviderManagerTest.php | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 05442455cb721..d6ceefa42684d 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -89,7 +89,7 @@ public function testBootAppNotLoadable(): void { ->with(\OCA\Settings\AppInfo\Application::class) ->willThrowException(new QueryException("")); $this->logger->expects($this->once()) - ->method('logException'); + ->method('error'); $this->coordinator->bootApp($appId); } diff --git a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php index f97ac92e8876b..067e9a0967311 100644 --- a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php +++ b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php @@ -61,7 +61,7 @@ public function testRegisterCapability(): void { ->method('registerCapability') ->with($name); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerCapability($name); $this->context->delegateCapabilityRegistrations([ @@ -77,7 +77,7 @@ public function testRegisterEventListener(): void { ->method('addServiceListener') ->with($event, $service, 0); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerEventListener($event, $service); $this->context->delegateEventListenerRegistrations($dispatcher); @@ -99,7 +99,7 @@ public function testRegisterService(bool $shared): void { ->method('registerService') ->with($service, $factory, $shared); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerService($service, $factory, $shared); $this->context->delegateContainerRegistrations([ @@ -118,7 +118,7 @@ public function testRegisterServiceAlias(): void { ->method('registerAlias') ->with($alias, $target); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerServiceAlias($alias, $target); $this->context->delegateContainerRegistrations([ @@ -137,7 +137,7 @@ public function testRegisterParameter(): void { ->method('registerParameter') ->with($name, $value); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerParameter($name, $value); $this->context->delegateContainerRegistrations([ @@ -155,7 +155,7 @@ public function testRegisterMiddleware(): void { ->method('registerMiddleware') ->with($name); $this->logger->expects($this->never()) - ->method('logException'); + ->method('error'); $this->context->for('myapp')->registerMiddleware($name); $this->context->delegateMiddlewareRegistrations([ diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 076f6588d94bc..8f55f90d3772e 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -506,7 +506,7 @@ public function testAfterExceptionReturnsRedirectForNotLoggedInUser() { ->willReturn('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp'); $this->logger ->expects($this->once()) - ->method('logException'); + ->method('debug'); $response = $this->middleware->afterException( $this->controller, 'test', @@ -576,7 +576,7 @@ public function testAfterExceptionReturnsTemplateResponse(SecurityException $exc $this->middleware = $this->getMiddleware(false, false, false); $this->logger ->expects($this->once()) - ->method('logException'); + ->method('debug'); $response = $this->middleware->afterException( $this->controller, 'test', diff --git a/tests/lib/CapabilitiesManagerTest.php b/tests/lib/CapabilitiesManagerTest.php index 4909272c4a82b..ec07f3dfa3641 100644 --- a/tests/lib/CapabilitiesManagerTest.php +++ b/tests/lib/CapabilitiesManagerTest.php @@ -149,7 +149,7 @@ public function testInvalidCapability() { }); $this->logger->expects($this->once()) - ->method('logException'); + ->method('error'); $res = $this->manager->getCapabilities(); diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 19a34962a564a..01e45de9fdfec 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -82,7 +82,7 @@ public function testGetResourceProvidersInvalidProvider(): void { ->willThrowException(new QueryException('A meaningful error message')); $this->logger->expects($this->once()) - ->method('logException'); + ->method('error'); $this->providerManager->registerResourceProvider('InvalidResourceProvider'); $resourceProviders = $this->providerManager->getResourceProviders(); @@ -101,7 +101,7 @@ public function testGetResourceProvidersValidAndInvalidProvider(): void { ->willReturn($this->createMock(ResourceProvider::class)); $this->logger->expects($this->once()) - ->method('logException'); + ->method('error'); $this->providerManager->registerResourceProvider('InvalidResourceProvider'); $this->providerManager->registerResourceProvider(ResourceProvider::class); From e1e5026df28b9311e241788ba86b4ab2fcec3592 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Jun 2021 10:57:41 +0200 Subject: [PATCH 2/3] Fix dispatcher handling in CalDavBackendTest Signed-off-by: Joas Schilling --- .../unit/CalDAV/AbstractCalDavBackend.php | 29 +++--- .../tests/unit/CalDAV/CalDavBackendTest.php | 93 ++++++------------- 2 files changed, 40 insertions(+), 82 deletions(-) diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index eb0530a8b3d4b..8ac4aa3789988 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -33,7 +33,9 @@ use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\Events\CalendarCreatedEvent; use OCA\DAV\Events\CalendarDeletedEvent; +use OCA\DAV\Events\CalendarMovedToTrashEvent; use OCA\DAV\Events\CalendarObjectCreatedEvent; +use OCA\DAV\Events\SubscriptionCreatedEvent; use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; @@ -66,9 +68,9 @@ abstract class AbstractCalDavBackend extends TestCase { protected $userManager; /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ protected $groupManager; - /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $dispatcher; /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + protected $dispatcher; + /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $legacyDispatcher; /** @var ISecureRandom */ @@ -147,11 +149,10 @@ public function cleanUpBackend() { private function cleanupForPrincipal($principal): void { $calendars = $this->backend->getCalendarsForUser($principal); - $this->legacyDispatcher->expects(self::exactly(count($calendars))) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::any()) + ->method('dispatchTyped'); + $this->legacyDispatcher->expects(self::any()) + ->method('dispatch'); foreach ($calendars as $calendar) { $this->backend->deleteCalendar($calendar['id'], true); } @@ -162,11 +163,8 @@ private function cleanupForPrincipal($principal): void { } protected function createTestCalendar() { - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarCreatedEvent; - })); + $this->dispatcher->expects(self::any()) + ->method('dispatchTyped'); $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [ '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' @@ -221,11 +219,8 @@ protected function createEvent($calendarId, $start = '20130912T130000Z', $end = EOD; $uri0 = $this->getUniqueID('event'); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri0, $calData); diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 03abd554e2b43..ffa74de19aa04 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -40,6 +40,8 @@ use OCA\DAV\Events\CalendarDeletedEvent; use OCA\DAV\Events\CalendarObjectCreatedEvent; use OCA\DAV\Events\CalendarUpdatedEvent; +use OCA\DAV\Events\SubscriptionDeletedEvent; +use OCA\DAV\Events\SubscriptionUpdatedEvent; use OCP\IConfig; use OCP\IL10N; use Sabre\DAV\Exception\NotFound; @@ -63,11 +65,8 @@ public function testCalendarOperations() { '{DAV:}displayname' => 'Unit test', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing' ]); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarUpdatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->updateCalendar($calendarId, $patch); $patch->commit(); $this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER)); @@ -78,11 +77,8 @@ public function testCalendarOperations() { $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']); // delete the address book - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->deleteCalendar($calendars[0]['id'], true); $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); self::assertEmpty($calendars); @@ -191,11 +187,8 @@ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, END:VCALENDAR EOD; - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri, $calData); /** @var IACL $child */ @@ -239,11 +232,8 @@ public function testCalendarObjectsOperations() { END:VCALENDAR EOD; - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri, $calData); // get all the cards @@ -279,21 +269,15 @@ public function testCalendarObjectsOperations() { END:VEVENT END:VCALENDAR EOD; - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarUpdatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->updateCalendarObject($calendarId, $uri, $calData); $calendarObject = $this->backend->getCalendarObject($calendarId, $uri); $this->assertEquals($calData, $calendarObject['calendardata']); // delete the card - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->deleteCalendarObject($calendarId, $uri); $calendarObjects = $this->backend->getCalendarObjects($calendarId); $this->assertCount(0, $calendarObjects); @@ -386,25 +370,16 @@ public function testMultiCalendarObjects() { EOD; $uri0 = static::getUniqueID('card'); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]); $uri1 = static::getUniqueID('card'); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]); $uri2 = static::getUniqueID('card'); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarObjectCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]); // get all the cards @@ -431,23 +406,14 @@ public function testMultiCalendarObjects() { $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']); // delete the card - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->deleteCalendarObject($calendarId, $uri0); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->deleteCalendarObject($calendarId, $uri1); - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarDeletedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->deleteCalendarObject($calendarId, $uri2); $calendarObjects = $this->backend->getCalendarObjects($calendarId); $this->assertCount(0, $calendarObjects); @@ -530,11 +496,8 @@ public function testSyncSupport() { } public function testPublications() { - $this->dispatcher->expects(self::once()) - ->method('dispatchTyped') - ->with(self::callback(function ($event) { - return $event instanceof CalendarCreatedEvent; - })); + $this->dispatcher->expects(self::atLeastOnce()) + ->method('dispatchTyped'); $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); From e238b93234549a3d6234b06dc8f83dbe053ada2e Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 7 Jun 2021 10:31:14 +0200 Subject: [PATCH 3/3] Code style fixes Signed-off-by: Morris Jobke --- apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php | 5 ----- apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 5 ----- 2 files changed, 10 deletions(-) diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index 8ac4aa3789988..1c044f2e28aad 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -31,11 +31,6 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\Connector\Sabre\Principal; -use OCA\DAV\Events\CalendarCreatedEvent; -use OCA\DAV\Events\CalendarDeletedEvent; -use OCA\DAV\Events\CalendarMovedToTrashEvent; -use OCA\DAV\Events\CalendarObjectCreatedEvent; -use OCA\DAV\Events\SubscriptionCreatedEvent; use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index ffa74de19aa04..dc370197fc1ee 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -36,12 +36,7 @@ use DateTimeZone; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; -use OCA\DAV\Events\CalendarCreatedEvent; use OCA\DAV\Events\CalendarDeletedEvent; -use OCA\DAV\Events\CalendarObjectCreatedEvent; -use OCA\DAV\Events\CalendarUpdatedEvent; -use OCA\DAV\Events\SubscriptionDeletedEvent; -use OCA\DAV\Events\SubscriptionUpdatedEvent; use OCP\IConfig; use OCP\IL10N; use Sabre\DAV\Exception\NotFound;