fix(tests): Adapt tests for comments

And make sure these are now covered by psalm

Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
Carl Schwan 2026-05-05 12:50:59 +02:00 committed by Anna
parent 4a48172af8
commit f00b956237
8 changed files with 38 additions and 6 deletions

View file

@ -35,6 +35,7 @@ class ListenerTest extends TestCase {
protected IShareHelper&MockObject $shareHelper;
protected Listener $listener;
#[\Override]
protected function setUp(): void {
parent::setUp();

View file

@ -28,12 +28,14 @@ use Test\TestCase;
*/
#[\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();

View file

@ -16,6 +16,7 @@ class CommentersSorterTest extends TestCase {
protected ICommentsManager&MockObject $commentsManager;
protected CommentersSorter $sorter;
#[\Override]
protected function setUp(): void {
parent::setUp();

View file

@ -35,6 +35,7 @@ class NotificationsTest extends TestCase {
protected IURLGenerator&MockObject $urlGenerator;
protected NotificationsController $notificationsController;
#[\Override]
protected function setUp(): void {
parent::setUp();

View file

@ -17,6 +17,8 @@ use OCP\Comments\Events\CommentAddedEvent;
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 @@ class EventHandlerTest extends TestCase {
];
}
#[\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')

View file

@ -26,6 +26,7 @@ class ListenerTest extends TestCase {
protected IURLGenerator&MockObject $urlGenerator;
protected Listener $listener;
#[\Override]
protected function setUp(): void {
parent::setUp();

View file

@ -37,6 +37,7 @@ class NotifierTest extends TestCase {
protected Notifier $notifier;
protected string $lc = 'tlh_KX';
#[\Override]
protected function setUp(): void {
parent::setUp();

View file

@ -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"/>