Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/comments/lib/Listener/CommentsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
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<CommentsEvent|Event> */
class CommentsEventListener implements IEventListener {
public function __construct(
private ActivityListener $activityListener,
private NotificationListener $notificationListener,
private IEventDispatcher $eventDispatcher,
) {
}

Expand All @@ -29,6 +35,14 @@ public function handle(Event $event): void {
return;
}

if ($event instanceof CommentAddedEvent
|| $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()));
}

if ($event->getComment()->getObjectType() !== 'files') {
// this is a 'files'-specific Handler
return;
Expand Down
1 change: 1 addition & 0 deletions apps/comments/tests/Unit/Activity/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ListenerTest extends TestCase {
protected IShareHelper&MockObject $shareHelper;
protected Listener $listener;

#[\Override]
protected function setUp(): void {
parent::setUp();

Expand Down
2 changes: 2 additions & 0 deletions apps/comments/tests/Unit/AppInfo/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CommentersSorterTest extends TestCase {
protected ICommentsManager&MockObject $commentsManager;
protected CommentersSorter $sorter;

#[\Override]
protected function setUp(): void {
parent::setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class NotificationsTest extends TestCase {
protected IURLGenerator&MockObject $urlGenerator;
protected NotificationsController $notificationsController;

#[\Override]
protected function setUp(): void {
parent::setUp();

Expand Down
10 changes: 5 additions & 5 deletions apps/comments/tests/Unit/EventHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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')
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions apps/comments/tests/Unit/Notification/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ListenerTest extends TestCase {
protected IURLGenerator&MockObject $urlGenerator;
protected Listener $listener;

#[\Override]
protected function setUp(): void {
parent::setUp();

Expand Down
1 change: 1 addition & 0 deletions apps/comments/tests/Unit/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NotifierTest extends TestCase {
protected Notifier $notifier;
protected string $lc = 'tlh_KX';

#[\Override]
protected function setUp(): void {
parent::setUp();

Expand Down
27 changes: 26 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,32 @@
<file name="version.php"/>
<file name="tests/lib/TestCase.php"/>
<ignoreFiles>
<directory name="apps/**/tests"/>
<directory name="apps/admin_audit/tests"/>
<directory name="apps/cloud_federation_api/tests"/>
<directory name="apps/contactsinteraction/tests"/>
<directory name="apps/dashboard/tests"/>
<directory name="apps/dav/tests"/>
<directory name="apps/encryption/tests"/>
<directory name="apps/federatedfilesharing/tests"/>
<directory name="apps/federation/tests"/>
<directory name="apps/files/tests"/>
<directory name="apps/files_external/tests"/>
<directory name="apps/files_sharing/tests"/>
<directory name="apps/files_trashbin/tests"/>
<directory name="apps/files_versions/tests"/>
<directory name="apps/oauth2/tests"/>
<directory name="apps/profile/tests"/>
<directory name="apps/provisioning_api/tests"/>
<directory name="apps/settings/tests"/>
<directory name="apps/sharebymail/tests"/>
<directory name="apps/systemtags/tests"/>
<directory name="apps/theming/tests"/>
<directory name="apps/twofactor_backupcodes/tests"/>
<directory name="apps/updatenotification/tests"/>
<directory name="apps/user_ldap/tests"/>
<directory name="apps/user_status/tests"/>
<directory name="apps/webhook_listeners/tests"/>
<directory name="apps/workflowengine/tests"/>
<directory name="apps/**/composer"/>
<directory name="lib/composer"/>
<directory name="lib/l10n"/>
Expand Down
Loading