Skip to content

Commit 92d19bd

Browse files
authored
Merge pull request #27374 from nextcloud/bugfix/noid/adjust-unit-tests
Bugfix/noid/adjust unit tests
2 parents d1d4725 + e238b93 commit 92d19bd

7 files changed

Lines changed: 48 additions & 100 deletions

File tree

apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
use OCA\DAV\CalDAV\CalDavBackend;
3131
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
3232
use OCA\DAV\Connector\Sabre\Principal;
33-
use OCA\DAV\Events\CalendarCreatedEvent;
34-
use OCA\DAV\Events\CalendarDeletedEvent;
35-
use OCA\DAV\Events\CalendarObjectCreatedEvent;
3633
use OCP\App\IAppManager;
3734
use OCP\EventDispatcher\IEventDispatcher;
3835
use OCP\IConfig;
@@ -65,9 +62,9 @@ abstract class AbstractCalDavBackend extends TestCase {
6562
protected $userManager;
6663
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
6764
protected $groupManager;
68-
/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
69-
protected $dispatcher;
7065
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
66+
protected $dispatcher;
67+
/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
7168
protected $legacyDispatcher;
7269

7370
/** @var ISecureRandom */
@@ -146,11 +143,10 @@ public function cleanUpBackend() {
146143

147144
private function cleanupForPrincipal($principal): void {
148145
$calendars = $this->backend->getCalendarsForUser($principal);
149-
$this->legacyDispatcher->expects(self::exactly(count($calendars)))
150-
->method('dispatchTyped')
151-
->with(self::callback(function ($event) {
152-
return $event instanceof CalendarDeletedEvent;
153-
}));
146+
$this->dispatcher->expects(self::any())
147+
->method('dispatchTyped');
148+
$this->legacyDispatcher->expects(self::any())
149+
->method('dispatch');
154150
foreach ($calendars as $calendar) {
155151
$this->backend->deleteCalendar($calendar['id'], true);
156152
}
@@ -161,11 +157,8 @@ private function cleanupForPrincipal($principal): void {
161157
}
162158

163159
protected function createTestCalendar() {
164-
$this->dispatcher->expects(self::once())
165-
->method('dispatchTyped')
166-
->with(self::callback(function ($event) {
167-
return $event instanceof CalendarCreatedEvent;
168-
}));
160+
$this->dispatcher->expects(self::any())
161+
->method('dispatchTyped');
169162

170163
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
171164
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
@@ -220,11 +213,8 @@ protected function createEvent($calendarId, $start = '20130912T130000Z', $end =
220213
EOD;
221214
$uri0 = $this->getUniqueID('event');
222215

223-
$this->dispatcher->expects(self::once())
224-
->method('dispatchTyped')
225-
->with(self::callback(function ($event) {
226-
return $event instanceof CalendarObjectCreatedEvent;
227-
}));
216+
$this->dispatcher->expects(self::atLeastOnce())
217+
->method('dispatchTyped');
228218

229219
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
230220

apps/dav/tests/unit/CalDAV/CalDavBackendTest.php

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
use DateTimeZone;
3636
use OCA\DAV\CalDAV\CalDavBackend;
3737
use OCA\DAV\CalDAV\Calendar;
38-
use OCA\DAV\Events\CalendarCreatedEvent;
3938
use OCA\DAV\Events\CalendarDeletedEvent;
40-
use OCA\DAV\Events\CalendarObjectCreatedEvent;
41-
use OCA\DAV\Events\CalendarUpdatedEvent;
4239
use OCP\IConfig;
4340
use OCP\IL10N;
4441
use Sabre\DAV\Exception\NotFound;
@@ -62,11 +59,8 @@ public function testCalendarOperations() {
6259
'{DAV:}displayname' => 'Unit test',
6360
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
6461
]);
65-
$this->dispatcher->expects(self::once())
66-
->method('dispatchTyped')
67-
->with(self::callback(function ($event) {
68-
return $event instanceof CalendarUpdatedEvent;
69-
}));
62+
$this->dispatcher->expects(self::atLeastOnce())
63+
->method('dispatchTyped');
7064
$this->backend->updateCalendar($calendarId, $patch);
7165
$patch->commit();
7266
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
@@ -77,11 +71,8 @@ public function testCalendarOperations() {
7771
$this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']);
7872

7973
// delete the address book
80-
$this->dispatcher->expects(self::once())
81-
->method('dispatchTyped')
82-
->with(self::callback(function ($event) {
83-
return $event instanceof CalendarDeletedEvent;
84-
}));
74+
$this->dispatcher->expects(self::atLeastOnce())
75+
->method('dispatchTyped');
8576
$this->backend->deleteCalendar($calendars[0]['id'], true);
8677
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
8778
self::assertEmpty($calendars);
@@ -190,11 +181,8 @@ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead,
190181
END:VCALENDAR
191182
EOD;
192183

193-
$this->dispatcher->expects(self::once())
194-
->method('dispatchTyped')
195-
->with(self::callback(function ($event) {
196-
return $event instanceof CalendarObjectCreatedEvent;
197-
}));
184+
$this->dispatcher->expects(self::atLeastOnce())
185+
->method('dispatchTyped');
198186
$this->backend->createCalendarObject($calendarId, $uri, $calData);
199187

200188
/** @var IACL $child */
@@ -238,11 +226,8 @@ public function testCalendarObjectsOperations() {
238226
END:VCALENDAR
239227
EOD;
240228

241-
$this->dispatcher->expects(self::once())
242-
->method('dispatchTyped')
243-
->with(self::callback(function ($event) {
244-
return $event instanceof CalendarObjectCreatedEvent;
245-
}));
229+
$this->dispatcher->expects(self::atLeastOnce())
230+
->method('dispatchTyped');
246231
$this->backend->createCalendarObject($calendarId, $uri, $calData);
247232

248233
// get all the cards
@@ -278,21 +263,15 @@ public function testCalendarObjectsOperations() {
278263
END:VEVENT
279264
END:VCALENDAR
280265
EOD;
281-
$this->dispatcher->expects(self::once())
282-
->method('dispatchTyped')
283-
->with(self::callback(function ($event) {
284-
return $event instanceof CalendarUpdatedEvent;
285-
}));
266+
$this->dispatcher->expects(self::atLeastOnce())
267+
->method('dispatchTyped');
286268
$this->backend->updateCalendarObject($calendarId, $uri, $calData);
287269
$calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
288270
$this->assertEquals($calData, $calendarObject['calendardata']);
289271

290272
// delete the card
291-
$this->dispatcher->expects(self::once())
292-
->method('dispatchTyped')
293-
->with(self::callback(function ($event) {
294-
return $event instanceof CalendarDeletedEvent;
295-
}));
273+
$this->dispatcher->expects(self::atLeastOnce())
274+
->method('dispatchTyped');
296275
$this->backend->deleteCalendarObject($calendarId, $uri);
297276
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
298277
$this->assertCount(0, $calendarObjects);
@@ -385,25 +364,16 @@ public function testMultiCalendarObjects() {
385364
EOD;
386365

387366
$uri0 = static::getUniqueID('card');
388-
$this->dispatcher->expects(self::once())
389-
->method('dispatchTyped')
390-
->with(self::callback(function ($event) {
391-
return $event instanceof CalendarObjectCreatedEvent;
392-
}));
367+
$this->dispatcher->expects(self::atLeastOnce())
368+
->method('dispatchTyped');
393369
$this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
394370
$uri1 = static::getUniqueID('card');
395-
$this->dispatcher->expects(self::once())
396-
->method('dispatchTyped')
397-
->with(self::callback(function ($event) {
398-
return $event instanceof CalendarObjectCreatedEvent;
399-
}));
371+
$this->dispatcher->expects(self::atLeastOnce())
372+
->method('dispatchTyped');
400373
$this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
401374
$uri2 = static::getUniqueID('card');
402-
$this->dispatcher->expects(self::once())
403-
->method('dispatchTyped')
404-
->with(self::callback(function ($event) {
405-
return $event instanceof CalendarObjectCreatedEvent;
406-
}));
375+
$this->dispatcher->expects(self::atLeastOnce())
376+
->method('dispatchTyped');
407377
$this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
408378

409379
// get all the cards
@@ -430,23 +400,14 @@ public function testMultiCalendarObjects() {
430400
$this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
431401

432402
// delete the card
433-
$this->dispatcher->expects(self::once())
434-
->method('dispatchTyped')
435-
->with(self::callback(function ($event) {
436-
return $event instanceof CalendarDeletedEvent;
437-
}));
403+
$this->dispatcher->expects(self::atLeastOnce())
404+
->method('dispatchTyped');
438405
$this->backend->deleteCalendarObject($calendarId, $uri0);
439-
$this->dispatcher->expects(self::once())
440-
->method('dispatchTyped')
441-
->with(self::callback(function ($event) {
442-
return $event instanceof CalendarDeletedEvent;
443-
}));
406+
$this->dispatcher->expects(self::atLeastOnce())
407+
->method('dispatchTyped');
444408
$this->backend->deleteCalendarObject($calendarId, $uri1);
445-
$this->dispatcher->expects(self::once())
446-
->method('dispatchTyped')
447-
->with(self::callback(function ($event) {
448-
return $event instanceof CalendarDeletedEvent;
449-
}));
409+
$this->dispatcher->expects(self::atLeastOnce())
410+
->method('dispatchTyped');
450411
$this->backend->deleteCalendarObject($calendarId, $uri2);
451412
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
452413
$this->assertCount(0, $calendarObjects);
@@ -529,11 +490,8 @@ public function testSyncSupport() {
529490
}
530491

531492
public function testPublications() {
532-
$this->dispatcher->expects(self::once())
533-
->method('dispatchTyped')
534-
->with(self::callback(function ($event) {
535-
return $event instanceof CalendarCreatedEvent;
536-
}));
493+
$this->dispatcher->expects(self::atLeastOnce())
494+
->method('dispatchTyped');
537495

538496
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
539497

tests/lib/AppFramework/Bootstrap/CoordinatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testBootAppNotLoadable(): void {
8989
->with(\OCA\Settings\AppInfo\Application::class)
9090
->willThrowException(new QueryException(""));
9191
$this->logger->expects($this->once())
92-
->method('logException');
92+
->method('error');
9393

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

tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testRegisterCapability(): void {
6161
->method('registerCapability')
6262
->with($name);
6363
$this->logger->expects($this->never())
64-
->method('logException');
64+
->method('error');
6565

6666
$this->context->for('myapp')->registerCapability($name);
6767
$this->context->delegateCapabilityRegistrations([
@@ -77,7 +77,7 @@ public function testRegisterEventListener(): void {
7777
->method('addServiceListener')
7878
->with($event, $service, 0);
7979
$this->logger->expects($this->never())
80-
->method('logException');
80+
->method('error');
8181

8282
$this->context->for('myapp')->registerEventListener($event, $service);
8383
$this->context->delegateEventListenerRegistrations($dispatcher);
@@ -99,7 +99,7 @@ public function testRegisterService(bool $shared): void {
9999
->method('registerService')
100100
->with($service, $factory, $shared);
101101
$this->logger->expects($this->never())
102-
->method('logException');
102+
->method('error');
103103

104104
$this->context->for('myapp')->registerService($service, $factory, $shared);
105105
$this->context->delegateContainerRegistrations([
@@ -118,7 +118,7 @@ public function testRegisterServiceAlias(): void {
118118
->method('registerAlias')
119119
->with($alias, $target);
120120
$this->logger->expects($this->never())
121-
->method('logException');
121+
->method('error');
122122

123123
$this->context->for('myapp')->registerServiceAlias($alias, $target);
124124
$this->context->delegateContainerRegistrations([
@@ -137,7 +137,7 @@ public function testRegisterParameter(): void {
137137
->method('registerParameter')
138138
->with($name, $value);
139139
$this->logger->expects($this->never())
140-
->method('logException');
140+
->method('error');
141141

142142
$this->context->for('myapp')->registerParameter($name, $value);
143143
$this->context->delegateContainerRegistrations([
@@ -155,7 +155,7 @@ public function testRegisterMiddleware(): void {
155155
->method('registerMiddleware')
156156
->with($name);
157157
$this->logger->expects($this->never())
158-
->method('logException');
158+
->method('error');
159159

160160
$this->context->for('myapp')->registerMiddleware($name);
161161
$this->context->delegateMiddlewareRegistrations([

tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public function testAfterExceptionReturnsRedirectForNotLoggedInUser() {
506506
->willReturn('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp');
507507
$this->logger
508508
->expects($this->once())
509-
->method('logException');
509+
->method('debug');
510510
$response = $this->middleware->afterException(
511511
$this->controller,
512512
'test',
@@ -576,7 +576,7 @@ public function testAfterExceptionReturnsTemplateResponse(SecurityException $exc
576576
$this->middleware = $this->getMiddleware(false, false, false);
577577
$this->logger
578578
->expects($this->once())
579-
->method('logException');
579+
->method('debug');
580580
$response = $this->middleware->afterException(
581581
$this->controller,
582582
'test',

tests/lib/CapabilitiesManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testInvalidCapability() {
149149
});
150150

151151
$this->logger->expects($this->once())
152-
->method('logException');
152+
->method('error');
153153

154154
$res = $this->manager->getCapabilities();
155155

tests/lib/Collaboration/Resources/ProviderManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testGetResourceProvidersInvalidProvider(): void {
8282
->willThrowException(new QueryException('A meaningful error message'));
8383

8484
$this->logger->expects($this->once())
85-
->method('logException');
85+
->method('error');
8686

8787
$this->providerManager->registerResourceProvider('InvalidResourceProvider');
8888
$resourceProviders = $this->providerManager->getResourceProviders();
@@ -101,7 +101,7 @@ public function testGetResourceProvidersValidAndInvalidProvider(): void {
101101
->willReturn($this->createMock(ResourceProvider::class));
102102

103103
$this->logger->expects($this->once())
104-
->method('logException');
104+
->method('error');
105105

106106
$this->providerManager->registerResourceProvider('InvalidResourceProvider');
107107
$this->providerManager->registerResourceProvider(ResourceProvider::class);

0 commit comments

Comments
 (0)