From 401d7154ed400669dcc190c97869278771f39ab8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 4 May 2026 12:48:10 +0200 Subject: [PATCH 1/3] fix: Dispatch old comment events Signed-off-by: Carl Schwan --- .../comments/lib/Listener/CommentsEventListener.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/comments/lib/Listener/CommentsEventListener.php b/apps/comments/lib/Listener/CommentsEventListener.php index 55a1190ea110f..61593d81107a9 100644 --- a/apps/comments/lib/Listener/CommentsEventListener.php +++ b/apps/comments/lib/Listener/CommentsEventListener.php @@ -13,7 +13,12 @@ use OCA\Comments\Activity\Listener as ActivityListener; use OCA\Comments\Notification\Listener as NotificationListener; use OCP\Comments\CommentsEvent; +use OCP\Comments\Events\BeforeCommentUpdatedEvent; +use OCP\Comments\Events\CommentAddedEvent; +use OCP\Comments\Events\CommentDeletedEvent; +use OCP\Comments\Events\CommentUpdatedEvent; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; /** @template-implements IEventListener */ @@ -21,6 +26,7 @@ class CommentsEventListener implements IEventListener { public function __construct( private ActivityListener $activityListener, private NotificationListener $notificationListener, + private IEventDispatcher $eventDispatcher, ) { } @@ -29,6 +35,13 @@ public function handle(Event $event): void { return; } + if ($event instanceof CommentAddedEvent + || $event instanceof CommentUpdatedEvent + || $event instanceof CommentDeletedEvent + || $event instanceof BeforeCommentUpdatedEvent) { + $this->eventDispatcher->dispatchTyped(new CommentsEvent($event->getEvent(), $event->getComment())); + } + if ($event->getComment()->getObjectType() !== 'files') { // this is a 'files'-specific Handler return; From 8121f293b52feb3ae7e24574571e33e33573448f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 4 May 2026 13:25:36 +0200 Subject: [PATCH 2/3] chore: Add comment about deprecation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Carl Schwan --- apps/comments/lib/Listener/CommentsEventListener.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/comments/lib/Listener/CommentsEventListener.php b/apps/comments/lib/Listener/CommentsEventListener.php index 61593d81107a9..544708c90bfe1 100644 --- a/apps/comments/lib/Listener/CommentsEventListener.php +++ b/apps/comments/lib/Listener/CommentsEventListener.php @@ -39,6 +39,7 @@ public function handle(Event $event): void { || $event instanceof CommentUpdatedEvent || $event instanceof CommentDeletedEvent || $event instanceof BeforeCommentUpdatedEvent) { + // Dispatch the deprecated event name for backward compatibility $this->eventDispatcher->dispatchTyped(new CommentsEvent($event->getEvent(), $event->getComment())); } From 1667c6472aa7515bc1c374a39864b1d15bc6914a Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 5 May 2026 12:50:59 +0200 Subject: [PATCH 3/3] fix(tests): Adapt tests for comments And make sure these are now covered by psalm Signed-off-by: Carl Schwan --- .../tests/Unit/Activity/ListenerTest.php | 1 + .../tests/Unit/AppInfo/ApplicationTest.php | 2 ++ .../Collaboration/CommentersSorterTest.php | 1 + .../Unit/Controller/NotificationsTest.php | 1 + apps/comments/tests/Unit/EventHandlerTest.php | 10 +++---- .../tests/Unit/Notification/ListenerTest.php | 1 + .../tests/Unit/Notification/NotifierTest.php | 1 + psalm.xml | 27 ++++++++++++++++++- 8 files changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/comments/tests/Unit/Activity/ListenerTest.php b/apps/comments/tests/Unit/Activity/ListenerTest.php index 358fd1b3af2f4..fbb1a3ef15279 100644 --- a/apps/comments/tests/Unit/Activity/ListenerTest.php +++ b/apps/comments/tests/Unit/Activity/ListenerTest.php @@ -35,6 +35,7 @@ class ListenerTest extends TestCase { protected IShareHelper&MockObject $shareHelper; protected Listener $listener; + #[\Override] protected function setUp(): void { parent::setUp(); diff --git a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php index 696057681acd9..a2af64b6cfb46 100644 --- a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php +++ b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php @@ -28,12 +28,14 @@ */ #[\PHPUnit\Framework\Attributes\Group(name: 'DB')] class ApplicationTest extends TestCase { + #[\Override] protected function setUp(): void { parent::setUp(); Server::get(IUserManager::class)->createUser('dummy', '456'); Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy')); } + #[\Override] protected function tearDown(): void { Server::get(IUserManager::class)->get('dummy')->delete(); parent::tearDown(); diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php index 0abc7f88c6a1c..c83bd283a0817 100644 --- a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php +++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php @@ -16,6 +16,7 @@ class CommentersSorterTest extends TestCase { protected ICommentsManager&MockObject $commentsManager; protected CommentersSorter $sorter; + #[\Override] protected function setUp(): void { parent::setUp(); diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php index 5b1180f662b60..0150884f1ccff 100644 --- a/apps/comments/tests/Unit/Controller/NotificationsTest.php +++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php @@ -35,6 +35,7 @@ class NotificationsTest extends TestCase { protected IURLGenerator&MockObject $urlGenerator; protected NotificationsController $notificationsController; + #[\Override] protected function setUp(): void { parent::setUp(); diff --git a/apps/comments/tests/Unit/EventHandlerTest.php b/apps/comments/tests/Unit/EventHandlerTest.php index 666b1623d97e4..ff7496c7e7dd2 100644 --- a/apps/comments/tests/Unit/EventHandlerTest.php +++ b/apps/comments/tests/Unit/EventHandlerTest.php @@ -17,6 +17,8 @@ use OCP\Comments\Events\CommentDeletedEvent; use OCP\Comments\Events\CommentUpdatedEvent; use OCP\Comments\IComment; +use OCP\EventDispatcher\IEventDispatcher; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -25,23 +27,22 @@ class EventHandlerTest extends TestCase { protected NotificationListener&MockObject $notificationListener; protected CommentsEventListener $eventHandler; + #[\Override] protected function setUp(): void { parent::setUp(); $this->activityListener = $this->createMock(ActivityListener::class); $this->notificationListener = $this->createMock(NotificationListener::class); - $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener); + $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener, $this->createMock(IEventDispatcher::class)); } public function testNotFiles(): void { - /** @var IComment|MockObject $comment */ $comment = $this->createMock(IComment::class); $comment->expects($this->once()) ->method('getObjectType') ->willReturn('smiles'); - /** @var CommentsEvent|MockObject $event */ $event = $this->createMock(CommentsEvent::class); $event->expects($this->once()) ->method('getComment') @@ -61,9 +62,8 @@ public static function handledProvider(): array { ]; } - #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'handledProvider')] + #[DataProvider(methodName: 'handledProvider')] public function testHandled(string $eventType): void { - /** @var IComment|MockObject $comment */ $comment = $this->createMock(IComment::class); $comment->expects($this->once()) ->method('getObjectType') diff --git a/apps/comments/tests/Unit/Notification/ListenerTest.php b/apps/comments/tests/Unit/Notification/ListenerTest.php index a84e86ef528a3..eac83c74855c8 100644 --- a/apps/comments/tests/Unit/Notification/ListenerTest.php +++ b/apps/comments/tests/Unit/Notification/ListenerTest.php @@ -26,6 +26,7 @@ class ListenerTest extends TestCase { protected IURLGenerator&MockObject $urlGenerator; protected Listener $listener; + #[\Override] protected function setUp(): void { parent::setUp(); diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index cd2d1be14080d..03ebc87c95063 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -37,6 +37,7 @@ class NotifierTest extends TestCase { protected Notifier $notifier; protected string $lc = 'tlh_KX'; + #[\Override] protected function setUp(): void { parent::setUp(); diff --git a/psalm.xml b/psalm.xml index 9b029ce31d497..dbe8723dcf830 100644 --- a/psalm.xml +++ b/psalm.xml @@ -64,7 +64,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + +