aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-06-25 11:20:48 +0200
committerJoas Schilling <coding@schilljs.com>2024-06-25 11:56:24 +0200
commit8130968a352bcf66606a076598fa4a58a291bc6d (patch)
treeed7d9c5bfc0d7e1b3c63348f0416d96cb51fb6ef /apps/comments
parent9496ce6c7a35f5a6d151b78d78a45b1c900b3b2a (diff)
downloadnextcloud-server-8130968a352bcf66606a076598fa4a58a291bc6d.tar.gz
nextcloud-server-8130968a352bcf66606a076598fa4a58a291bc6d.zip
feat(notifications): Migrate server INotifiers to new exceptions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/comments')
-rw-r--r--apps/comments/lib/Notification/Notifier.php11
-rw-r--r--apps/comments/tests/Unit/Notification/NotifierTest.php12
2 files changed, 13 insertions, 10 deletions
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php
index 4f114f22ef8..d5563ef7d85 100644
--- a/apps/comments/lib/Notification/Notifier.php
+++ b/apps/comments/lib/Notification/Notifier.php
@@ -17,6 +17,7 @@ use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
+use OCP\Notification\UnknownNotificationException;
class Notifier implements INotifier {
public function __construct(
@@ -52,19 +53,19 @@ class Notifier implements INotifier {
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
- * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws UnknownNotificationException When the notification was not prepared by a notifier
* @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'comments') {
- throw new \InvalidArgumentException();
+ throw new UnknownNotificationException();
}
try {
$comment = $this->commentsManager->get($notification->getObjectId());
} catch (NotFoundException $e) {
// needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all
- throw new \InvalidArgumentException('Comment not found', 0, $e);
+ throw new UnknownNotificationException('Comment not found', 0, $e);
}
$l = $this->l10nFactory->get('comments', $languageCode);
$displayName = $comment->getActorId();
@@ -80,7 +81,7 @@ class Notifier implements INotifier {
case 'mention':
$parameters = $notification->getSubjectParameters();
if ($parameters[0] !== 'files') {
- throw new \InvalidArgumentException('Unsupported comment object');
+ throw new UnknownNotificationException('Unsupported comment object');
}
$userFolder = $this->rootFolder->getUserFolder($notification->getUser());
$nodes = $userFolder->getById((int)$parameters[1]);
@@ -128,7 +129,7 @@ class Notifier implements INotifier {
break;
default:
- throw new \InvalidArgumentException('Invalid subject');
+ throw new UnknownNotificationException('Invalid subject');
}
}
diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php
index 8830ca37265..a01c08a6760 100644
--- a/apps/comments/tests/Unit/Notification/NotifierTest.php
+++ b/apps/comments/tests/Unit/Notification/NotifierTest.php
@@ -16,7 +16,9 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
+use OCP\Notification\UnknownNotificationException;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -304,7 +306,7 @@ class NotifierTest extends TestCase {
public function testPrepareDifferentApp() {
- $this->expectException(\InvalidArgumentException::class);
+ $this->expectException(UnknownNotificationException::class);
$this->folder
->expects($this->never())
@@ -341,7 +343,7 @@ class NotifierTest extends TestCase {
public function testPrepareNotFound() {
- $this->expectException(\InvalidArgumentException::class);
+ $this->expectException(UnknownNotificationException::class);
$this->folder
->expects($this->never())
@@ -379,7 +381,7 @@ class NotifierTest extends TestCase {
public function testPrepareDifferentSubject() {
- $this->expectException(\InvalidArgumentException::class);
+ $this->expectException(UnknownNotificationException::class);
$displayName = 'Huraga';
@@ -436,7 +438,7 @@ class NotifierTest extends TestCase {
public function testPrepareNotFiles() {
- $this->expectException(\InvalidArgumentException::class);
+ $this->expectException(UnknownNotificationException::class);
$displayName = 'Huraga';
@@ -494,7 +496,7 @@ class NotifierTest extends TestCase {
public function testPrepareUnresolvableFileID() {
- $this->expectException(\OCP\Notification\AlreadyProcessedException::class);
+ $this->expectException(AlreadyProcessedException::class);
$displayName = 'Huraga';