From 565838da9c279fe071a9cdfbfd9cf574893a61f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Jul 2019 13:32:44 +0200 Subject: [PATCH] Update unit tests Signed-off-by: Joas Schilling --- .../tests/Unit/Controller/NotificationsTest.php | 6 ++++++ .../tests/Unit/Notification/ListenerTest.php | 6 ++++++ .../tests/Unit/Notification/NotifierTest.php | 5 ++++- .../tests/Notification/NotifierTest.php | 12 ++---------- .../Listeners/RemoteWipeNotificationsListener.php | 2 +- .../RemoteWipeNotificationsListenerTest.php | 4 ++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php index c5209b9f9d..9df81f01b0 100644 --- a/apps/comments/tests/Unit/Controller/NotificationsTest.php +++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php @@ -117,6 +117,9 @@ class NotificationsTest extends TestCase { $comment->expects($this->any()) ->method('getObjectType') ->willReturn('files'); + $comment->expects($this->any()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager->expects($this->any()) ->method('get') @@ -192,6 +195,9 @@ class NotificationsTest extends TestCase { $comment->expects($this->any()) ->method('getObjectType') ->willReturn('files'); + $comment->expects($this->any()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager->expects($this->any()) ->method('get') diff --git a/apps/comments/tests/Unit/Notification/ListenerTest.php b/apps/comments/tests/Unit/Notification/ListenerTest.php index d6f83262f3..e31b227bce 100644 --- a/apps/comments/tests/Unit/Notification/ListenerTest.php +++ b/apps/comments/tests/Unit/Notification/ListenerTest.php @@ -91,6 +91,9 @@ class ListenerTest extends TestCase { [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], [ 'type' => 'user', 'id' => 'yolo'], ]); + $comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder(CommentsEvent::class) @@ -186,6 +189,9 @@ class ListenerTest extends TestCase { $comment->expects($this->once()) ->method('getMentions') ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); + $comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder(CommentsEvent::class) diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index 6eceed4491..d008c4c312 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -195,6 +195,9 @@ class NotifierTest extends TestCase { ->expects($this->any()) ->method('getMentions') ->willReturn([['type' => 'user', 'id' => 'you']]); + $this->comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager ->expects($this->once()) @@ -539,7 +542,7 @@ class NotifierTest extends TestCase { } /** - * @expectedException \InvalidArgumentException + * @expectedException \OCP\Notification\AlreadyProcessedException */ public function testPrepareUnresolvableFileID() { $displayName = 'Huraga'; diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index b1ddf7b478..f97ff776c9 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -30,6 +30,7 @@ use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IManager; use OCP\Notification\INotification; use Test\TestCase; @@ -112,21 +113,12 @@ class NotifierTest extends TestCase { ->method('getObjectId') ->willReturn($versionNotification); - if ($exception) { - $this->notificationManager->expects($this->once()) - ->method('markProcessed') - ->with($notification); - } else { - $this->notificationManager->expects($this->never()) - ->method('markProcessed'); - } - try { self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]); $this->assertFalse($exception); } catch (\Exception $e) { $this->assertTrue($exception); - $this->assertInstanceOf('InvalidArgumentException', $e); + $this->assertInstanceOf(AlreadyProcessedException::class, $e); } } } diff --git a/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php index ffddddff1d..57213a8a19 100644 --- a/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php +++ b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php @@ -61,7 +61,7 @@ class RemoteWipeNotificationsListener implements IEventListener { $notification->setApp('auth') ->setUser($token->getUID()) ->setDateTime($this->timeFactory->getDateTime()) - ->setObject('token', $token->getId()) + ->setObject('token', (string) $token->getId()) ->setSubject($event, [ 'name' => $token->getName(), ]); diff --git a/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php b/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php index 27d386ca5b..e3e526e401 100644 --- a/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php +++ b/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php @@ -92,7 +92,7 @@ class RemoteWipeNotificationListenerTests extends TestCase { $token->method('getId')->willReturn(123); $notification->expects($this->once()) ->method('setObject') - ->with('token', 123) + ->with('token', '123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $notification->expects($this->once()) @@ -132,7 +132,7 @@ class RemoteWipeNotificationListenerTests extends TestCase { $token->method('getId')->willReturn(123); $notification->expects($this->once()) ->method('setObject') - ->with('token', 123) + ->with('token', '123') ->willReturnSelf(); $token->method('getName')->willReturn('Token 1'); $notification->expects($this->once())