Skip to content
Merged
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
40 changes: 15 additions & 25 deletions apps/comments/tests/Unit/Activity/ListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -20,30 +23,17 @@
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShareHelper;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class ListenerTest extends TestCase {

/** @var Listener */
protected $listener;

/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $activityManager;

/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $session;

/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
protected $appManager;

/** @var IMountProviderCollection|\PHPUnit\Framework\MockObject\MockObject */
protected $mountProviderCollection;

/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
protected $rootFolder;

/** @var IShareHelper|\PHPUnit\Framework\MockObject\MockObject */
protected $shareHelper;
protected IManager&MockObject $activityManager;
protected IUserSession&MockObject $session;
protected IAppManager&MockObject $appManager;
protected IMountProviderCollection&MockObject $mountProviderCollection;
protected IRootFolder&MockObject $rootFolder;
protected IShareHelper&MockObject $shareHelper;
protected Listener $listener;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -76,7 +66,7 @@ public function testCommentEvent(): void {
->method('getObjectType')
->willReturn('files');

/** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
/** @var CommentsEvent|MockObject $event */
$event = $this->createMock(CommentsEvent::class);
$event->expects($this->any())
->method('getComment')
Expand All @@ -85,13 +75,13 @@ public function testCommentEvent(): void {
->method('getEvent')
->willReturn(CommentsEvent::EVENT_ADD);

/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $ownerUser */
/** @var IUser|MockObject $ownerUser */
$ownerUser = $this->createMock(IUser::class);
$ownerUser->expects($this->any())
->method('getUID')
->willReturn('937393');

/** @var \PHPUnit\Framework\MockObject\MockObject $mount */
/** @var MockObject $mount */
$mount = $this->createMock(ICachedMountFileInfo::class);
$mount->expects($this->any())
->method('getUser')
Expand Down Expand Up @@ -133,7 +123,7 @@ public function testCommentEvent(): void {
->method('getUser')
->willReturn($ownerUser);

/** @var \PHPUnit\Framework\MockObject\MockObject $activity */
/** @var MockObject $activity */
$activity = $this->createMock(IEvent::class);
$activity->expects($this->exactly(count($al['users'])))
->method('setAffectedUser');
Expand Down
19 changes: 13 additions & 6 deletions apps/comments/tests/Unit/AppInfo/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Comments\Tests\Unit\AppInfo;

use OCA\Comments\Activity\Filter;
use OCA\Comments\Activity\Listener;
use OCA\Comments\Activity\Provider;
use OCA\Comments\Activity\Setting;
use OCA\Comments\AppInfo\Application;
use OCA\Comments\Controller\NotificationsController;
use OCA\Comments\Notification\Notifier;
use OCP\IUserManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -38,12 +45,12 @@ public function test(): void {
$c = $app->getContainer();

$services = [
'OCA\Comments\Controller\NotificationsController',
'OCA\Comments\Activity\Filter',
'OCA\Comments\Activity\Listener',
'OCA\Comments\Activity\Provider',
'OCA\Comments\Activity\Setting',
'OCA\Comments\Notification\Listener',
NotificationsController::class,
Filter::class,
Listener::class,
Provider::class,
Setting::class,
\OCA\Comments\Notification\Listener::class,
Notifier::class,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
use OCA\Comments\Collaboration\CommentersSorter;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class CommentersSorterTest extends TestCase {
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
protected $commentsManager;
/** @var CommentersSorter */
protected $sorter;
protected ICommentsManager&MockObject $commentsManager;
protected CommentersSorter $sorter;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -55,7 +54,7 @@ public function testSort($data): void {
$this->assertEquals($data['expected'], $workArray);
}

public function sortDataProvider() {
public static function sortDataProvider(): array {
return [[
[
#1 – sort properly and otherwise keep existing order
Expand Down
30 changes: 9 additions & 21 deletions apps/comments/tests/Unit/Controller/NotificationsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -22,26 +24,16 @@
use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class NotificationsTest extends TestCase {
/** @var NotificationsController */
protected $notificationsController;

/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
protected $commentsManager;

/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
protected $rootFolder;

/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $session;

/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $notificationManager;

/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
protected $urlGenerator;
protected ICommentsManager&MockObject $commentsManager;
protected IRootFolder&MockObject $rootFolder;
protected IUserSession&MockObject $session;
protected IManager&MockObject $notificationManager;
protected IURLGenerator&MockObject $urlGenerator;
protected NotificationsController $notificationsController;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -81,10 +73,6 @@ public function testViewGuestRedirect(): void {

$this->urlGenerator->expects($this->exactly(2))
->method('linkToRoute')
->withConsecutive(
['comments.Notifications.view', ['id' => '42']],
['core.login.showLoginForm', ['redirect_url' => 'link-to-comment']]
)
->willReturnMap([
['comments.Notifications.view', ['id' => '42'], 'link-to-comment'],
['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'],
Expand Down
49 changes: 19 additions & 30 deletions apps/comments/tests/Unit/EventHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -10,43 +13,32 @@
use OCA\Comments\Notification\Listener as NotificationListener;
use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class EventHandlerTest extends TestCase {
/** @var CommentsEventListener */
protected $eventHandler;

/** @var ActivityListener|\PHPUnit\Framework\MockObject\MockObject */
protected $activityListener;

/** @var NotificationListener|\PHPUnit\Framework\MockObject\MockObject */
protected $notificationListener;
protected ActivityListener&MockObject $activityListener;
protected NotificationListener&MockObject $notificationListener;
protected CommentsEventListener $eventHandler;

protected function setUp(): void {
parent::setUp();

$this->activityListener = $this->getMockBuilder(ActivityListener::class)
->disableOriginalConstructor()
->getMock();

$this->notificationListener = $this->getMockBuilder(NotificationListener::class)
->disableOriginalConstructor()
->getMock();
$this->activityListener = $this->createMock(ActivityListener::class);
$this->notificationListener = $this->createMock(NotificationListener::class);

$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
}

public function testNotFiles(): void {
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
$comment = $this->getMockBuilder(IComment::class)->getMock();
/** @var IComment|MockObject $comment */
$comment = $this->createMock(IComment::class);
$comment->expects($this->once())
->method('getObjectType')
->willReturn('smiles');

/** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
$event = $this->getMockBuilder(CommentsEvent::class)
->disableOriginalConstructor()
->getMock();
/** @var CommentsEvent|MockObject $event */
$event = $this->createMock(CommentsEvent::class);
$event->expects($this->once())
->method('getComment')
->willReturn($comment);
Expand All @@ -56,7 +48,7 @@ public function testNotFiles(): void {
$this->eventHandler->handle($event);
}

public function handledProvider() {
public static function handledProvider(): array {
return [
[CommentsEvent::EVENT_DELETE],
[CommentsEvent::EVENT_UPDATE],
Expand All @@ -67,19 +59,16 @@ public function handledProvider() {

/**
* @dataProvider handledProvider
* @param string $eventType
*/
public function testHandled($eventType): void {
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
$comment = $this->getMockBuilder(IComment::class)->getMock();
public function testHandled(string $eventType): void {
/** @var IComment|MockObject $comment */
$comment = $this->createMock(IComment::class);
$comment->expects($this->once())
->method('getObjectType')
->willReturn('files');

/** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
$event = $this->getMockBuilder(CommentsEvent::class)
->disableOriginalConstructor()
->getMock();
/** @var CommentsEvent|MockObject $event */
$event = $this->createMock(CommentsEvent::class);
$event->expects($this->atLeastOnce())
->method('getComment')
->willReturn($comment);
Expand Down
Loading
Loading