mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
test: Fix some apps/*/tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
437f380fd9
commit
ea0229dc86
45 changed files with 359 additions and 719 deletions
|
|
@ -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
|
||||
|
|
@ -20,30 +23,17 @@ use OCP\Files\Node;
|
|||
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();
|
||||
|
|
@ -76,7 +66,7 @@ class ListenerTest extends TestCase {
|
|||
->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')
|
||||
|
|
@ -85,13 +75,13 @@ class ListenerTest extends TestCase {
|
|||
->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')
|
||||
|
|
@ -133,7 +123,7 @@ class ListenerTest extends TestCase {
|
|||
->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');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -13,6 +15,11 @@ use OCP\IUserManager;
|
|||
use OCP\IUserSession;
|
||||
use OCP\Server;
|
||||
use Test\TestCase;
|
||||
use OCA\Comments\Controller\NotificationsController;
|
||||
use OCA\Comments\Activity\Filter;
|
||||
use OCA\Comments\Activity\Listener;
|
||||
use OCA\Comments\Activity\Provider;
|
||||
use OCA\Comments\Activity\Setting;
|
||||
|
||||
/**
|
||||
* Class ApplicationTest
|
||||
|
|
@ -38,12 +45,12 @@ class ApplicationTest extends TestCase {
|
|||
$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,
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@ namespace OCA\Comments\Tests\Unit\Collaboration;
|
|||
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();
|
||||
|
|
@ -55,7 +54,7 @@ class CommentersSorterTest extends TestCase {
|
|||
$this->assertEquals($data['expected'], $workArray);
|
||||
}
|
||||
|
||||
public function sortDataProvider() {
|
||||
public static function sortDataProvider(): array {
|
||||
return [[
|
||||
[
|
||||
#1 – sort properly and otherwise keep existing order
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -22,26 +24,16 @@ use OCP\IUser;
|
|||
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();
|
||||
|
|
@ -81,10 +73,6 @@ class NotificationsTest extends TestCase {
|
|||
|
||||
$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'],
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -10,43 +13,32 @@ use OCA\Comments\Listener\CommentsEventListener;
|
|||
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);
|
||||
|
|
@ -56,7 +48,7 @@ class EventHandlerTest extends TestCase {
|
|||
$this->eventHandler->handle($event);
|
||||
}
|
||||
|
||||
public function handledProvider() {
|
||||
public static function handledProvider(): array {
|
||||
return [
|
||||
[CommentsEvent::EVENT_DELETE],
|
||||
[CommentsEvent::EVENT_UPDATE],
|
||||
|
|
@ -67,19 +59,16 @@ class EventHandlerTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @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);
|
||||
|
|
|
|||
|
|
@ -14,25 +14,19 @@ use OCP\IURLGenerator;
|
|||
use OCP\IUserManager;
|
||||
use OCP\Notification\IManager;
|
||||
use OCP\Notification\INotification;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ListenerTest extends TestCase {
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $notificationManager;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userManager;
|
||||
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $urlGenerator;
|
||||
|
||||
/** @var Listener */
|
||||
protected $listener;
|
||||
protected IManager&MockObject $notificationManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected IURLGenerator&MockObject $urlGenerator;
|
||||
protected Listener $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->notificationManager = $this->createMock(\OCP\Notification\IManager::class);
|
||||
$this->notificationManager = $this->createMock(IManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
|
||||
$this->listener = new Listener(
|
||||
|
|
@ -41,7 +35,7 @@ class ListenerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function eventProvider() {
|
||||
public static function eventProvider(): array {
|
||||
return [
|
||||
[CommentsEvent::EVENT_ADD, 'notify'],
|
||||
[CommentsEvent::EVENT_UPDATE, 'notify'],
|
||||
|
|
@ -56,8 +50,8 @@ class ListenerTest extends TestCase {
|
|||
* @param string $notificationMethod
|
||||
*/
|
||||
public function testEvaluate($eventType, $notificationMethod): 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->any())
|
||||
->method('getObjectType')
|
||||
->willReturn('files');
|
||||
|
|
@ -78,10 +72,8 @@ class ListenerTest extends TestCase {
|
|||
->method('getId')
|
||||
->willReturn('1234');
|
||||
|
||||
/** @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);
|
||||
|
|
@ -89,8 +81,8 @@ class ListenerTest extends TestCase {
|
|||
->method(('getEvent'))
|
||||
->willReturn($eventType);
|
||||
|
||||
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
|
||||
$notification = $this->getMockBuilder(INotification::class)->getMock();
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->any())
|
||||
->method($this->anything())
|
||||
->willReturn($notification);
|
||||
|
|
@ -106,26 +98,24 @@ class ListenerTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->exactly(6))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['foobar'],
|
||||
['barfoo'],
|
||||
['foo@bar.com'],
|
||||
['bar@foo.org@foobar.io'],
|
||||
['23452-4333-54353-2342'],
|
||||
['yolo']
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['foobar', true],
|
||||
['barfoo', true],
|
||||
['foo@bar.com', true],
|
||||
['bar@foo.org@foobar.io', true],
|
||||
['23452-4333-54353-2342', true],
|
||||
['yolo', true]
|
||||
]);
|
||||
|
||||
$this->listener->evaluate($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider eventProvider
|
||||
* @param string $eventType
|
||||
*/
|
||||
public function testEvaluateNoMentions($eventType): void {
|
||||
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
|
||||
$comment = $this->getMockBuilder(IComment::class)->getMock();
|
||||
public function testEvaluateNoMentions(string $eventType): void {
|
||||
/** @var IComment|MockObject $comment */
|
||||
$comment = $this->createMock(IComment::class);
|
||||
$comment->expects($this->any())
|
||||
->method('getObjectType')
|
||||
->willReturn('files');
|
||||
|
|
@ -136,10 +126,8 @@ class ListenerTest extends TestCase {
|
|||
->method('getMentions')
|
||||
->willReturn([]);
|
||||
|
||||
/** @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);
|
||||
|
|
@ -161,8 +149,8 @@ class ListenerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testEvaluateUserDoesNotExist(): 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->any())
|
||||
->method('getObjectType')
|
||||
->willReturn('files');
|
||||
|
|
@ -176,10 +164,8 @@ class ListenerTest extends TestCase {
|
|||
->method('getId')
|
||||
->willReturn('1234');
|
||||
|
||||
/** @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);
|
||||
|
|
@ -187,8 +173,8 @@ class ListenerTest extends TestCase {
|
|||
->method(('getEvent'))
|
||||
->willReturn(CommentsEvent::EVENT_ADD);
|
||||
|
||||
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
|
||||
$notification = $this->getMockBuilder(INotification::class)->getMock();
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->any())
|
||||
->method($this->anything())
|
||||
->willReturn($notification);
|
||||
|
|
@ -203,9 +189,7 @@ class ListenerTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->once())
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['foobar']
|
||||
)
|
||||
->with('foobar')
|
||||
->willReturn(false);
|
||||
|
||||
$this->listener->evaluate($event);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -23,26 +26,16 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class NotifierTest extends TestCase {
|
||||
/** @var Notifier */
|
||||
protected $notifier;
|
||||
/** @var IFactory|MockObject */
|
||||
protected $l10nFactory;
|
||||
/** @var IL10N|MockObject */
|
||||
protected $l;
|
||||
/** @var IRootFolder|MockObject */
|
||||
protected $folder;
|
||||
/** @var ICommentsManager|MockObject */
|
||||
protected $commentsManager;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
protected $url;
|
||||
/** @var IUserManager|MockObject */
|
||||
protected $userManager;
|
||||
/** @var INotification|MockObject */
|
||||
protected $notification;
|
||||
/** @var IComment|MockObject */
|
||||
protected $comment;
|
||||
/** @var string */
|
||||
protected $lc = 'tlh_KX';
|
||||
protected IFactory&MockObject $l10nFactory;
|
||||
protected IL10N&MockObject $l;
|
||||
protected IRootFolder&MockObject $folder;
|
||||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected IURLGenerator&MockObject $url;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected INotification&MockObject $notification;
|
||||
protected IComment&MockObject $comment;
|
||||
protected Notifier $notifier;
|
||||
protected string $lc = 'tlh_KX';
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -75,9 +68,8 @@ class NotifierTest extends TestCase {
|
|||
public function testPrepareSuccess(): void {
|
||||
$fileName = 'Gre\'thor.odp';
|
||||
$displayName = 'Huraga';
|
||||
$message = '@Huraga mentioned you in a comment on "Gre\'thor.odp"';
|
||||
|
||||
/** @var Node|MockObject $node */
|
||||
/** @var Node&MockObject $node */
|
||||
$node = $this->createMock(Node::class);
|
||||
$node
|
||||
->expects($this->atLeastOnce())
|
||||
|
|
@ -192,7 +184,6 @@ class NotifierTest extends TestCase {
|
|||
|
||||
public function testPrepareSuccessDeletedUser(): void {
|
||||
$fileName = 'Gre\'thor.odp';
|
||||
$message = 'You were mentioned on "Gre\'thor.odp", in a comment by an account that has since been deleted';
|
||||
|
||||
/** @var Node|MockObject $node */
|
||||
$node = $this->createMock(Node::class);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,8 @@ use Test\TestCase;
|
|||
* @group DB
|
||||
*/
|
||||
class RecentContactMapperTest extends TestCase {
|
||||
|
||||
/** @var RecentContactMapper */
|
||||
private $recentContactMapper;
|
||||
|
||||
/** @var ITimeFactory */
|
||||
private $time;
|
||||
private RecentContactMapper $recentContactMapper;
|
||||
private ITimeFactory $time;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class DashboardServiceTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function testGetBirthdate() {
|
||||
public function testGetBirthdate(): void {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$this->userManager->method('get')
|
||||
->willReturn($user);
|
||||
|
|
@ -61,7 +61,7 @@ class DashboardServiceTest extends TestCase {
|
|||
$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
|
||||
}
|
||||
|
||||
public function testGetBirthdatePropertyDoesNotExist() {
|
||||
public function testGetBirthdatePropertyDoesNotExist(): void {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$this->userManager->method('get')
|
||||
->willReturn($user);
|
||||
|
|
@ -75,7 +75,7 @@ class DashboardServiceTest extends TestCase {
|
|||
$this->assertEquals('', $birthdate);
|
||||
}
|
||||
|
||||
public function testGetBirthdateUserNotFound() {
|
||||
public function testGetBirthdateUserNotFound(): void {
|
||||
$this->userManager->method('get')
|
||||
->willReturn(null);
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class DashboardServiceTest extends TestCase {
|
|||
$this->assertEquals('', $birthdate);
|
||||
}
|
||||
|
||||
public function testGetBirthdateNoUserId() {
|
||||
public function testGetBirthdateNoUserId(): void {
|
||||
$service = new DashboardService(
|
||||
$this->config,
|
||||
null,
|
||||
|
|
|
|||
|
|
@ -19,15 +19,9 @@ use Test\TestCase;
|
|||
* @group DB
|
||||
*/
|
||||
class BackupCodeMapperTest extends TestCase {
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
|
||||
/** @var BackupCodeMapper */
|
||||
private $mapper;
|
||||
|
||||
/** @var string */
|
||||
private $testUID = 'test123456';
|
||||
private IDBConnection $db;
|
||||
private BackupCodeMapper $mapper;
|
||||
private string $testUID = 'test123456';
|
||||
|
||||
private function resetDB() {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
|
|
|||
|
|
@ -13,21 +13,16 @@ use OCP\IUser;
|
|||
use OCP\Notification\IManager;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
class BackupCodeStorageTest extends TestCase {
|
||||
|
||||
/** @var BackupCodeStorage */
|
||||
private $storage;
|
||||
|
||||
/** @var string */
|
||||
private $testUID = 'test123456789';
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $notificationManager;
|
||||
private IManager&MockObject $notificationManager;
|
||||
private string $testUID = 'test123456789';
|
||||
private BackupCodeStorage $storage;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -15,21 +15,14 @@ use OCP\Activity\IManager;
|
|||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\L10N\IFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ProviderTest extends TestCase {
|
||||
|
||||
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10n;
|
||||
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $activityManager;
|
||||
|
||||
/** @var Provider */
|
||||
private $provider;
|
||||
private IFactory&MockObject $l10n;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private IManager&MockObject $activityManager;
|
||||
private Provider $provider;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -52,7 +45,7 @@ class ProviderTest extends TestCase {
|
|||
$this->provider->parse($lang, $event);
|
||||
}
|
||||
|
||||
public function subjectData() {
|
||||
public static function subjectData(): array {
|
||||
return [
|
||||
['codes_generated'],
|
||||
];
|
||||
|
|
@ -61,7 +54,7 @@ class ProviderTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider subjectData
|
||||
*/
|
||||
public function testParse($subject): void {
|
||||
public function testParse(string $subject): void {
|
||||
$lang = 'ru';
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$l = $this->createMock(IL10N::class);
|
||||
|
|
|
|||
|
|
@ -20,24 +20,12 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class CheckBackupCodeTest extends TestCase {
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var IJobList|MockObject */
|
||||
private $jobList;
|
||||
|
||||
/** @var IRegistry|MockObject */
|
||||
private $registry;
|
||||
|
||||
/** @var Manager|MockObject */
|
||||
private $manager;
|
||||
|
||||
/** @var IUser|MockObject */
|
||||
private $user;
|
||||
|
||||
/** @var CheckBackupCodes */
|
||||
private $checkBackupCodes;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IJobList&MockObject $jobList;
|
||||
private IRegistry&MockObject $registry;
|
||||
private Manager&MockObject $manager;
|
||||
private IUser&MockObject $user;
|
||||
private CheckBackupCodes $checkBackupCodes;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -17,27 +17,16 @@ use OCP\IUserManager;
|
|||
use OCP\Notification\IManager;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class RememberBackupCodesJobTest extends TestCase {
|
||||
|
||||
/** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $registry;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $time;
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $notificationManager;
|
||||
|
||||
/** @var IJobList|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $jobList;
|
||||
|
||||
/** @var RememberBackupCodesJob */
|
||||
private $job;
|
||||
private IRegistry&MockObject $registry;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private ITimeFactory&MockObject $time;
|
||||
private IManager&MockObject $notificationManager;
|
||||
private IJobList&MockObject $jobList;
|
||||
private RememberBackupCodesJob $job;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -14,36 +14,27 @@ use OCP\AppFramework\Http\JSONResponse;
|
|||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class SettingsControllerTest extends TestCase {
|
||||
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $request;
|
||||
|
||||
/** @var BackupCodeStorage|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $storage;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSession;
|
||||
|
||||
/** @var SettingsController */
|
||||
private $controller;
|
||||
private IRequest&MockObject $request;
|
||||
private BackupCodeStorage&MockObject $storage;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private SettingsController $controller;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->request = $this->getMockBuilder(IRequest::class)->getMock();
|
||||
$this->storage = $this->getMockBuilder(BackupCodeStorage::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
$this->storage = $this->createMock(BackupCodeStorage::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
|
||||
$this->controller = new SettingsController('twofactor_backupcodes', $this->request, $this->storage, $this->userSession);
|
||||
}
|
||||
|
||||
public function testCreateCodes(): void {
|
||||
$user = $this->getMockBuilder(IUser::class)->getMock();
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$codes = ['a', 'b'];
|
||||
$this->userSession->expects($this->once())
|
||||
|
|
|
|||
|
|
@ -19,14 +19,9 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class ActivityPublisherTest extends TestCase {
|
||||
/** @var IManager|MockObject */
|
||||
private $activityManager;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var ActivityPublisher */
|
||||
private $listener;
|
||||
private IManager&MockObject $activityManager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private ActivityPublisher $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -15,15 +15,12 @@ use OCP\IUser;
|
|||
use OCP\Notification\IManager;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ClearNotificationsTest extends TestCase {
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $notificationManager;
|
||||
|
||||
/** @var ClearNotifications */
|
||||
private $listener;
|
||||
private IManager&MockObject $notificationManager;
|
||||
private ClearNotifications$listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ use OCP\Authentication\TwoFactorAuth\TwoFactorProviderForUserUnregistered;
|
|||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ProviderDisabledTest extends TestCase {
|
||||
private IRegistry $registy;
|
||||
private IJobList $jobList;
|
||||
private IRegistry&MockObject $registy;
|
||||
private IJobList&MockObject $jobList;
|
||||
private ProviderDisabled $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ use OCP\Authentication\TwoFactorAuth\TwoFactorProviderForUserRegistered;
|
|||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ProviderEnabledTest extends TestCase {
|
||||
private IRegistry $registy;
|
||||
private IJobList $jobList;
|
||||
private IRegistry&MockObject $registy;
|
||||
private IJobList&MockObject $jobList;
|
||||
private ProviderEnabled $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
|
|||
|
|
@ -14,18 +14,13 @@ use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
|||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class RegistryUpdaterTest extends TestCase {
|
||||
|
||||
/** @var IRegistry */
|
||||
private $registry;
|
||||
|
||||
/** @var BackupCodesProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var RegistryUpdater */
|
||||
private $listener;
|
||||
private IRegistry&MockObject $registry;
|
||||
private BackupCodesProvider&MockObject $provider;
|
||||
private RegistryUpdater $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -11,15 +11,12 @@ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Migration;
|
|||
use OCA\TwoFactorBackupCodes\Migration\CheckBackupCodes;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Migration\IOutput;
|
||||
use PHPunit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class CheckBackupCodeTest extends TestCase {
|
||||
|
||||
/** @var IJobList|\PHPunit\Framework\MockObject\MockObject */
|
||||
private $jobList;
|
||||
|
||||
/** @var CheckBackupCodes */
|
||||
private $checkBackupsCodes;
|
||||
private IJobList&MockObject $jobList;
|
||||
private CheckBackupCodes $checkBackupsCodes;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -17,15 +17,10 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class NotifierTest extends TestCase {
|
||||
/** @var Notifier */
|
||||
protected $notifier;
|
||||
|
||||
/** @var IFactory|MockObject */
|
||||
protected $factory;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
protected $url;
|
||||
/** @var IL10N|MockObject */
|
||||
protected $l;
|
||||
protected IFactory&MockObject $factory;
|
||||
protected IURLGenerator&MockObject $url;
|
||||
protected IL10N&MockObject $l;
|
||||
protected Notifier $notifier;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -52,7 +47,7 @@ class NotifierTest extends TestCase {
|
|||
public function testPrepareWrongApp(): void {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
|
|
@ -67,7 +62,7 @@ class NotifierTest extends TestCase {
|
|||
public function testPrepareWrongSubject(): void {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
|
||||
/** @var INotification|MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->once())
|
||||
->method('getApp')
|
||||
|
|
@ -80,7 +75,7 @@ class NotifierTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testPrepare(): void {
|
||||
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
|
||||
/** @var INotification&MockObject $notification */
|
||||
$notification = $this->createMock(INotification::class);
|
||||
|
||||
$notification->expects($this->once())
|
||||
|
|
|
|||
|
|
@ -16,24 +16,15 @@ use OCP\EventDispatcher\IEventDispatcher;
|
|||
use OCP\IUser;
|
||||
use OCP\Security\IHasher;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class BackupCodeStorageTest extends TestCase {
|
||||
|
||||
/** @var BackupCodeMapper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $mapper;
|
||||
|
||||
/** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $random;
|
||||
|
||||
/** @var IHasher|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $hasher;
|
||||
|
||||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $eventDispatcher;
|
||||
|
||||
/** @var BackupCodeStorage */
|
||||
private $storage;
|
||||
private BackupCodeMapper&MockObject $mapper;
|
||||
private ISecureRandom&MockObject $random;
|
||||
private IHasher&MockObject $hasher;
|
||||
private IEventDispatcher&MockObject $eventDispatcher;
|
||||
private BackupCodeStorage $storage;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class ResetTokenTest extends TestCase {
|
||||
private IConfig|MockObject $config;
|
||||
private IAppConfig|MockObject $appConfig;
|
||||
private ITimeFactory|MockObject $timeFactory;
|
||||
private IConfig&MockObject $config;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private BackgroundJobResetToken $resetTokenBackgroundJob;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ use Test\TestCase;
|
|||
|
||||
class UpdateAvailableNotificationsTest extends TestCase {
|
||||
private ServerVersion&MockObject $serverVersion;
|
||||
private IConfig|MockObject $config;
|
||||
private IManager|MockObject $notificationManager;
|
||||
private IGroupManager|MockObject $groupManager;
|
||||
private IAppManager|MockObject $appManager;
|
||||
private IAppConfig|MockObject $appConfig;
|
||||
private ITimeFactory|MockObject $timeFactory;
|
||||
private Installer|MockObject $installer;
|
||||
private VersionCheck|MockObject $versionCheck;
|
||||
private IConfig&MockObject $config;
|
||||
private IManager&MockObject $notificationManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private Installer&MockObject $installer;
|
||||
private VersionCheck&MockObject $versionCheck;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -50,10 +50,9 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $methods
|
||||
* @return UpdateAvailableNotifications|MockObject
|
||||
*/
|
||||
protected function getJob(array $methods = []) {
|
||||
protected function getJob(array $methods = []): UpdateAvailableNotifications {
|
||||
if (empty($methods)) {
|
||||
return new UpdateAvailableNotifications(
|
||||
$this->timeFactory,
|
||||
|
|
@ -125,7 +124,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
self::invokePrivate($job, 'run', [null]);
|
||||
}
|
||||
|
||||
public function dataCheckCoreUpdate(): array {
|
||||
public static function dataCheckCoreUpdate(): array {
|
||||
return [
|
||||
['daily', null, null, null, null],
|
||||
['git', null, null, null, null],
|
||||
|
|
@ -155,14 +154,8 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataCheckCoreUpdate
|
||||
*
|
||||
* @param string $channel
|
||||
* @param mixed $versionCheck
|
||||
* @param null|string $version
|
||||
* @param null|string $readableVersion
|
||||
* @param null|int $errorDays
|
||||
*/
|
||||
public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays): void {
|
||||
public function testCheckCoreUpdate(string $channel, mixed $versionCheck, mixed $version, ?string $readableVersion, ?int $errorDays): void {
|
||||
$job = $this->getJob([
|
||||
'createNotifications',
|
||||
'clearErrorNotifications',
|
||||
|
|
@ -223,7 +216,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
self::invokePrivate($job, 'checkCoreUpdate');
|
||||
}
|
||||
|
||||
public function dataCheckAppUpdates(): array {
|
||||
public static function dataCheckAppUpdates(): array {
|
||||
return [
|
||||
[
|
||||
['app1', 'app2'],
|
||||
|
|
@ -240,10 +233,6 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataCheckAppUpdates
|
||||
*
|
||||
* @param string[] $apps
|
||||
* @param array $isUpdateAvailable
|
||||
* @param array $notifications
|
||||
*/
|
||||
public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications): void {
|
||||
$job = $this->getJob([
|
||||
|
|
@ -271,7 +260,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
self::invokePrivate($job, 'checkAppUpdates');
|
||||
}
|
||||
|
||||
public function dataCreateNotifications(): array {
|
||||
public static function dataCreateNotifications(): array {
|
||||
return [
|
||||
['app1', '1.0.0', '1.0.0', false, false, null, null],
|
||||
['app2', '1.0.1', '1.0.0', '1.0.0', true, ['user1'], [['user1']]],
|
||||
|
|
@ -281,16 +270,8 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataCreateNotifications
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $version
|
||||
* @param string|false $lastNotification
|
||||
* @param string|false $callDelete
|
||||
* @param bool $createNotification
|
||||
* @param string[]|null $users
|
||||
* @param array|null $userNotifications
|
||||
*/
|
||||
public function testCreateNotifications(string $app, string $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications): void {
|
||||
public function testCreateNotifications(string $app, string $version, string|false $lastNotification, string|false $callDelete, bool $createNotification, ?array $users, ?array $userNotifications): void {
|
||||
$job = $this->getJob([
|
||||
'deleteOutdatedNotifications',
|
||||
'getUsersToNotify',
|
||||
|
|
@ -363,7 +344,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
self::invokePrivate($job, 'createNotifications', [$app, $version]);
|
||||
}
|
||||
|
||||
public function dataGetUsersToNotify(): array {
|
||||
public static function dataGetUsersToNotify(): array {
|
||||
return [
|
||||
[['g1', 'g2'], ['g1' => null, 'g2' => ['u1', 'u2']], ['u1', 'u2']],
|
||||
[['g3', 'g4'], ['g3' => ['u1', 'u2'], 'g4' => ['u2', 'u3']], ['u1', 'u2', 'u3']],
|
||||
|
|
@ -372,9 +353,6 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataGetUsersToNotify
|
||||
* @param string[] $groups
|
||||
* @param array $groupUsers
|
||||
* @param string[] $expected
|
||||
*/
|
||||
public function testGetUsersToNotify(array $groups, array $groupUsers, array $expected): void {
|
||||
$job = $this->getJob();
|
||||
|
|
@ -408,7 +386,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function dataDeleteOutdatedNotifications(): array {
|
||||
public static function dataDeleteOutdatedNotifications(): array {
|
||||
return [
|
||||
['app1', '1.1.0'],
|
||||
['app2', '1.2.0'],
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class AdminControllerTest extends TestCase {
|
||||
private IRequest|MockObject $request;
|
||||
private IJobList|MockObject $jobList;
|
||||
private ISecureRandom|MockObject $secureRandom;
|
||||
private IConfig|MockObject $config;
|
||||
private ITimeFactory|MockObject $timeFactory;
|
||||
private IL10N|MockObject $l10n;
|
||||
private IAppConfig|MockObject $appConfig;
|
||||
private IRequest&MockObject $request;
|
||||
private IJobList&MockObject $jobList;
|
||||
private ISecureRandom&MockObject $secureRandom;
|
||||
private IConfig&MockObject $config;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
|
||||
private AdminController $adminController;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ class NotifierTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @param array $methods
|
||||
* @return Notifier|\PHPUnit\Framework\MockObject\MockObject
|
||||
* @return Notifier|MockObject
|
||||
*/
|
||||
protected function getNotifier(array $methods = []) {
|
||||
protected function getNotifier(array $methods = []): Notifier {
|
||||
if (empty($methods)) {
|
||||
return new Notifier(
|
||||
$this->urlGenerator,
|
||||
|
|
@ -81,7 +81,7 @@ class NotifierTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataUpdateAlreadyInstalledCheck(): array {
|
||||
public static function dataUpdateAlreadyInstalledCheck(): array {
|
||||
return [
|
||||
['1.1.0', '1.0.0', false],
|
||||
['1.1.0', '1.1.0', true],
|
||||
|
|
@ -91,10 +91,6 @@ class NotifierTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataUpdateAlreadyInstalledCheck
|
||||
*
|
||||
* @param string $versionNotification
|
||||
* @param string $versionInstalled
|
||||
* @param bool $exception
|
||||
*/
|
||||
public function testUpdateAlreadyInstalledCheck(string $versionNotification, string $versionInstalled, bool $exception): void {
|
||||
$notifier = $this->getNotifier();
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
|
||||
private Admin $admin;
|
||||
|
||||
private IFactory&MockObject $l10nFactory;
|
||||
private IConfig&MockObject $config;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
|
|
@ -43,6 +40,7 @@ class AdminTest extends TestCase {
|
|||
private LoggerInterface&MockObject $logger;
|
||||
private IInitialState&MockObject $initialState;
|
||||
private ServerVersion&MockObject $serverVersion;
|
||||
private Admin $admin;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -395,7 +393,7 @@ class AdminTest extends TestCase {
|
|||
$this->assertSame(11, $this->admin->getPriority());
|
||||
}
|
||||
|
||||
public function changesProvider() {
|
||||
public static function changesProvider(): array {
|
||||
return [
|
||||
[ #0, all info, en
|
||||
[
|
||||
|
|
|
|||
|
|
@ -11,18 +11,13 @@ namespace OCA\UserStatus\Tests\BackgroundJob;
|
|||
use OCA\UserStatus\BackgroundJob\ClearOldStatusesBackgroundJob;
|
||||
use OCA\UserStatus\Db\UserStatusMapper;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ClearOldStatusesBackgroundJobTest extends TestCase {
|
||||
|
||||
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $time;
|
||||
|
||||
/** @var UserStatusMapper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $mapper;
|
||||
|
||||
/** @var ClearOldStatusesBackgroundJob */
|
||||
private $job;
|
||||
private ITimeFactory&MockObject $time;
|
||||
private UserStatusMapper&MockObject $mapper;
|
||||
private ClearOldStatusesBackgroundJob $job;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -10,15 +10,12 @@ namespace OCA\UserStatus\Tests;
|
|||
|
||||
use OCA\UserStatus\Capabilities;
|
||||
use OCP\IEmojiHelper;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class CapabilitiesTest extends TestCase {
|
||||
|
||||
/** @var IEmojiHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $emojiHelper;
|
||||
|
||||
/** @var Capabilities */
|
||||
private $capabilities;
|
||||
private IEmojiHelper&MockObject $emojiHelper;
|
||||
private Capabilities $capabilities;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -28,8 +25,6 @@ class CapabilitiesTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $supportsEmojis
|
||||
*
|
||||
* @dataProvider getCapabilitiesDataProvider
|
||||
*/
|
||||
public function testGetCapabilities(bool $supportsEmojis): void {
|
||||
|
|
@ -46,7 +41,7 @@ class CapabilitiesTest extends TestCase {
|
|||
], $this->capabilities->getCapabilities());
|
||||
}
|
||||
|
||||
public function getCapabilitiesDataProvider(): array {
|
||||
public static function getCapabilitiesDataProvider(): array {
|
||||
return [
|
||||
[true],
|
||||
[false],
|
||||
|
|
|
|||
|
|
@ -11,15 +11,12 @@ namespace OCA\UserStatus\Tests\Connector;
|
|||
use OCA\UserStatus\Connector\UserStatusProvider;
|
||||
use OCA\UserStatus\Db\UserStatus;
|
||||
use OCA\UserStatus\Service\StatusService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class UserStatusProviderTest extends TestCase {
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $service;
|
||||
|
||||
/** @var UserStatusProvider */
|
||||
private $provider;
|
||||
private StatusService&MockObject $service;
|
||||
private UserStatusProvider$provider;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -11,15 +11,12 @@ namespace OCA\UserStatus\Tests\Controller;
|
|||
use OCA\UserStatus\Controller\PredefinedStatusController;
|
||||
use OCA\UserStatus\Service\PredefinedStatusService;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class PredefinedStatusControllerTest extends TestCase {
|
||||
|
||||
/** @var PredefinedStatusService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $service;
|
||||
|
||||
/** @var PredefinedStatusController */
|
||||
private $controller;
|
||||
private PredefinedStatusService&MockObject $service;
|
||||
private PredefinedStatusController$controller;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -27,8 +24,7 @@ class PredefinedStatusControllerTest extends TestCase {
|
|||
$request = $this->createMock(IRequest::class);
|
||||
$this->service = $this->createMock(PredefinedStatusService::class);
|
||||
|
||||
$this->controller = new PredefinedStatusController('user_status', $request,
|
||||
$this->service);
|
||||
$this->controller = new PredefinedStatusController('user_status', $request, $this->service);
|
||||
}
|
||||
|
||||
public function testFindAll(): void {
|
||||
|
|
|
|||
|
|
@ -14,15 +14,12 @@ use OCA\UserStatus\Service\StatusService;
|
|||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class StatusesControllerTest extends TestCase {
|
||||
|
||||
/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $service;
|
||||
|
||||
/** @var StatusesController */
|
||||
private $controller;
|
||||
private StatusService&MockObject $service;
|
||||
private StatusesController $controller;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -21,22 +21,16 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
|||
use OCP\AppFramework\OCS\OCSBadRequestException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
use Throwable;
|
||||
|
||||
class UserStatusControllerTest extends TestCase {
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $statusService;
|
||||
|
||||
/** @var CalendarStatusService|\PHPUnit\Framework\MockObject\MockObject $calendarStatusService */
|
||||
private $calendarStatusService;
|
||||
|
||||
/** @var UserStatusController */
|
||||
private $controller;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private StatusService&MockObject $statusService;
|
||||
private CalendarStatusService&MockObject $calendarStatusService;
|
||||
private UserStatusController $controller;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -94,19 +88,10 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $statusType
|
||||
* @param string|null $statusIcon
|
||||
* @param string|null $message
|
||||
* @param int|null $clearAt
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectException
|
||||
* @param Throwable|null $exception
|
||||
* @param bool $expectLogger
|
||||
* @param string|null $expectedLogMessage
|
||||
*
|
||||
* @dataProvider setStatusDataProvider
|
||||
*/
|
||||
public function testSetStatus(string $statusType,
|
||||
public function testSetStatus(
|
||||
string $statusType,
|
||||
?string $statusIcon,
|
||||
?string $message,
|
||||
?int $clearAt,
|
||||
|
|
@ -114,7 +99,8 @@ class UserStatusControllerTest extends TestCase {
|
|||
bool $expectException,
|
||||
?Throwable $exception,
|
||||
bool $expectLogger,
|
||||
?string $expectedLogMessage): void {
|
||||
?string $expectedLogMessage,
|
||||
): void {
|
||||
$userStatus = $this->getUserStatus();
|
||||
|
||||
if ($expectException) {
|
||||
|
|
@ -155,7 +141,7 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setStatusDataProvider(): array {
|
||||
public static function setStatusDataProvider(): array {
|
||||
return [
|
||||
['busy', '👨🏽💻', 'Busy developing the status feature', 500, true, false, null, false, null],
|
||||
['busy', '👨🏽💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusTypeException('Original exception message'), true,
|
||||
|
|
@ -164,23 +150,17 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $messageId
|
||||
* @param int|null $clearAt
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectException
|
||||
* @param Throwable|null $exception
|
||||
* @param bool $expectLogger
|
||||
* @param string|null $expectedLogMessage
|
||||
*
|
||||
* @dataProvider setPredefinedMessageDataProvider
|
||||
*/
|
||||
public function testSetPredefinedMessage(string $messageId,
|
||||
public function testSetPredefinedMessage(
|
||||
string $messageId,
|
||||
?int $clearAt,
|
||||
bool $expectSuccess,
|
||||
bool $expectException,
|
||||
?Throwable $exception,
|
||||
bool $expectLogger,
|
||||
?string $expectedLogMessage): void {
|
||||
?string $expectedLogMessage,
|
||||
): void {
|
||||
$userStatus = $this->getUserStatus();
|
||||
|
||||
if ($expectException) {
|
||||
|
|
@ -221,7 +201,7 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setPredefinedMessageDataProvider(): array {
|
||||
public static function setPredefinedMessageDataProvider(): array {
|
||||
return [
|
||||
['messageId-42', 500, true, false, null, false, null],
|
||||
['messageId-42', 500, false, true, new InvalidClearAtException('Original exception message'), true,
|
||||
|
|
@ -232,19 +212,10 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string|null $statusIcon
|
||||
* @param string $message
|
||||
* @param int|null $clearAt
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectException
|
||||
* @param Throwable|null $exception
|
||||
* @param bool $expectLogger
|
||||
* @param string|null $expectedLogMessage
|
||||
* @param bool $expectSuccessAsReset
|
||||
*
|
||||
* @dataProvider setCustomMessageDataProvider
|
||||
*/
|
||||
public function testSetCustomMessage(?string $statusIcon,
|
||||
public function testSetCustomMessage(
|
||||
?string $statusIcon,
|
||||
string $message,
|
||||
?int $clearAt,
|
||||
bool $expectSuccess,
|
||||
|
|
@ -252,7 +223,8 @@ class UserStatusControllerTest extends TestCase {
|
|||
?Throwable $exception,
|
||||
bool $expectLogger,
|
||||
?string $expectedLogMessage,
|
||||
bool $expectSuccessAsReset = false): void {
|
||||
bool $expectSuccessAsReset = false,
|
||||
): void {
|
||||
$userStatus = $this->getUserStatus();
|
||||
|
||||
if ($expectException) {
|
||||
|
|
@ -308,7 +280,7 @@ class UserStatusControllerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setCustomMessageDataProvider(): array {
|
||||
public static function setCustomMessageDataProvider(): array {
|
||||
return [
|
||||
['👨🏽💻', 'Busy developing the status feature', 500, true, false, null, false, null],
|
||||
['👨🏽💻', '', 500, true, false, null, false, null, false],
|
||||
|
|
|
|||
|
|
@ -16,33 +16,18 @@ use OCP\IL10N;
|
|||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class UserStatusWidgetTest extends TestCase {
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10n;
|
||||
|
||||
/** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $dateTimeFormatter;
|
||||
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $initialState;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSession;
|
||||
|
||||
/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $service;
|
||||
|
||||
/** @var UserStatusWidget */
|
||||
private $widget;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IDateTimeFormatter&MockObject $dateTimeFormatter;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private IInitialState&MockObject $initialState;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private StatusService&MockObject $service;
|
||||
private UserStatusWidget $widget;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ use OCP\DB\Exception;
|
|||
use Test\TestCase;
|
||||
|
||||
class UserStatusMapperTest extends TestCase {
|
||||
|
||||
/** @var UserStatusMapper */
|
||||
private $mapper;
|
||||
private UserStatusMapper $mapper;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -137,11 +135,6 @@ class UserStatusMapperTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @param bool $isUserDefined
|
||||
* @param int $timestamp
|
||||
* @param bool $expectsClean
|
||||
*
|
||||
* @dataProvider clearStatusesOlderThanDataProvider
|
||||
*/
|
||||
public function testClearStatusesOlderThan(string $status, bool $isUserDefined, int $timestamp, bool $expectsClean): void {
|
||||
|
|
@ -169,7 +162,7 @@ class UserStatusMapperTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function clearStatusesOlderThanDataProvider(): array {
|
||||
public static function clearStatusesOlderThanDataProvider(): array {
|
||||
return [
|
||||
['offline', false, 6000, false],
|
||||
['online', true, 6000, false],
|
||||
|
|
@ -231,7 +224,7 @@ class UserStatusMapperTest extends TestCase {
|
|||
$this->mapper->insert($userStatus3);
|
||||
}
|
||||
|
||||
public function dataCreateBackupStatus(): array {
|
||||
public static function dataCreateBackupStatus(): array {
|
||||
return [
|
||||
[false, false, false],
|
||||
[true, false, true],
|
||||
|
|
@ -242,9 +235,6 @@ class UserStatusMapperTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataCreateBackupStatus
|
||||
* @param bool $hasStatus
|
||||
* @param bool $hasBackup
|
||||
* @param bool $backupCreated
|
||||
*/
|
||||
public function testCreateBackupStatus(bool $hasStatus, bool $hasBackup, bool $backupCreated): void {
|
||||
if ($hasStatus) {
|
||||
|
|
|
|||
|
|
@ -13,15 +13,12 @@ use OCA\UserStatus\Service\StatusService;
|
|||
use OCP\EventDispatcher\GenericEvent;
|
||||
use OCP\IUser;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class UserDeletedListenerTest extends TestCase {
|
||||
|
||||
/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $service;
|
||||
|
||||
/** @var UserDeletedListener */
|
||||
private $listener;
|
||||
private StatusService&MockObject $service;
|
||||
private UserDeletedListener $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -24,20 +24,13 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class UserLiveStatusListenerTest extends TestCase {
|
||||
private UserStatusMapper&MockObject $mapper;
|
||||
private StatusService&MockObject $statusService;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private CalendarStatusService&MockObject $calendarStatusService;
|
||||
|
||||
/** @var UserStatusMapper|MockObject */
|
||||
private $mapper;
|
||||
/** @var StatusService|MockObject */
|
||||
private $statusService;
|
||||
/** @var ITimeFactory|MockObject */
|
||||
private $timeFactory;
|
||||
|
||||
/** @var UserDeletedListener */
|
||||
private $listener;
|
||||
|
||||
private CalendarStatusService|MockObject $calendarStatusService;
|
||||
|
||||
private LoggerInterface|MockObject $logger;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private UserLiveStatusListener $listener;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -58,25 +51,18 @@ class UserLiveStatusListenerTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param string $previousStatus
|
||||
* @param int $previousTimestamp
|
||||
* @param bool $previousIsUserDefined
|
||||
* @param string $eventStatus
|
||||
* @param int $eventTimestamp
|
||||
* @param bool $expectExisting
|
||||
* @param bool $expectUpdate
|
||||
*
|
||||
* @dataProvider handleEventWithCorrectEventDataProvider
|
||||
*/
|
||||
public function testHandleWithCorrectEvent(string $userId,
|
||||
public function testHandleWithCorrectEvent(
|
||||
string $userId,
|
||||
string $previousStatus,
|
||||
int $previousTimestamp,
|
||||
bool $previousIsUserDefined,
|
||||
string $eventStatus,
|
||||
int $eventTimestamp,
|
||||
bool $expectExisting,
|
||||
bool $expectUpdate): void {
|
||||
bool $expectUpdate,
|
||||
): void {
|
||||
$userStatus = new UserStatus();
|
||||
|
||||
if ($expectExisting) {
|
||||
|
|
@ -143,7 +129,7 @@ class UserLiveStatusListenerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function handleEventWithCorrectEventDataProvider(): array {
|
||||
public static function handleEventWithCorrectEventDataProvider(): array {
|
||||
return [
|
||||
['john.doe', 'offline', 0, false, 'online', 5000, true, true],
|
||||
['john.doe', 'offline', 0, false, 'online', 5000, false, true],
|
||||
|
|
|
|||
|
|
@ -10,15 +10,12 @@ namespace OCA\UserStatus\Tests\Service;
|
|||
|
||||
use OCA\UserStatus\Service\PredefinedStatusService;
|
||||
use OCP\IL10N;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class PredefinedStatusServiceTest extends TestCase {
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $l10n;
|
||||
|
||||
/** @var PredefinedStatusService */
|
||||
protected $service;
|
||||
protected IL10N&MockObject $l10n;
|
||||
protected PredefinedStatusService $service;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -97,9 +94,6 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string|null $expectedIcon
|
||||
*
|
||||
* @dataProvider getIconForIdDataProvider
|
||||
*/
|
||||
public function testGetIconForId(string $id, ?string $expectedIcon): void {
|
||||
|
|
@ -107,10 +101,7 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
$this->assertEquals($expectedIcon, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getIconForIdDataProvider(): array {
|
||||
public static function getIconForIdDataProvider(): array {
|
||||
return [
|
||||
['meeting', '📅'],
|
||||
['commuting', '🚌'],
|
||||
|
|
@ -123,9 +114,6 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string|null $expected
|
||||
*
|
||||
* @dataProvider getTranslatedStatusForIdDataProvider
|
||||
*/
|
||||
public function testGetTranslatedStatusForId(string $id, ?string $expected): void {
|
||||
|
|
@ -136,10 +124,7 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTranslatedStatusForIdDataProvider(): array {
|
||||
public static function getTranslatedStatusForIdDataProvider(): array {
|
||||
return [
|
||||
['meeting', 'In a meeting'],
|
||||
['commuting', 'Commuting'],
|
||||
|
|
@ -152,9 +137,6 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param bool $expected
|
||||
*
|
||||
* @dataProvider isValidIdDataProvider
|
||||
*/
|
||||
public function testIsValidId(string $id, bool $expected): void {
|
||||
|
|
@ -162,10 +144,7 @@ class PredefinedStatusServiceTest extends TestCase {
|
|||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function isValidIdDataProvider(): array {
|
||||
public static function isValidIdDataProvider(): array {
|
||||
return [
|
||||
['meeting', true],
|
||||
['commuting', true],
|
||||
|
|
|
|||
|
|
@ -31,27 +31,13 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class StatusServiceTest extends TestCase {
|
||||
|
||||
/** @var UserStatusMapper|MockObject */
|
||||
private $mapper;
|
||||
|
||||
/** @var ITimeFactory|MockObject */
|
||||
private $timeFactory;
|
||||
|
||||
/** @var PredefinedStatusService|MockObject */
|
||||
private $predefinedStatusService;
|
||||
|
||||
/** @var IEmojiHelper|MockObject */
|
||||
private $emojiHelper;
|
||||
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
private UserStatusMapper&MockObject $mapper;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private PredefinedStatusService&MockObject $predefinedStatusService;
|
||||
private IEmojiHelper&MockObject $emojiHelper;
|
||||
private IConfig&MockObject $config;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
private StatusService $service;
|
||||
|
||||
|
|
@ -236,20 +222,10 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param string $status
|
||||
* @param int|null $statusTimestamp
|
||||
* @param bool $isUserDefined
|
||||
* @param bool $expectExisting
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectTimeFactory
|
||||
* @param bool $expectException
|
||||
* @param string|null $expectedExceptionClass
|
||||
* @param string|null $expectedExceptionMessage
|
||||
*
|
||||
* @dataProvider setStatusDataProvider
|
||||
*/
|
||||
public function testSetStatus(string $userId,
|
||||
public function testSetStatus(
|
||||
string $userId,
|
||||
string $status,
|
||||
?int $statusTimestamp,
|
||||
bool $isUserDefined,
|
||||
|
|
@ -258,7 +234,8 @@ class StatusServiceTest extends TestCase {
|
|||
bool $expectTimeFactory,
|
||||
bool $expectException,
|
||||
?string $expectedExceptionClass,
|
||||
?string $expectedExceptionMessage): void {
|
||||
?string $expectedExceptionMessage,
|
||||
): void {
|
||||
$userStatus = new UserStatus();
|
||||
|
||||
if ($expectExisting) {
|
||||
|
|
@ -309,7 +286,7 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setStatusDataProvider(): array {
|
||||
public static function setStatusDataProvider(): array {
|
||||
return [
|
||||
['john.doe', 'online', 50, true, true, true, false, false, null, null],
|
||||
['john.doe', 'online', 50, true, false, true, false, false, null, null],
|
||||
|
|
@ -368,19 +345,10 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param string $messageId
|
||||
* @param bool $isValidMessageId
|
||||
* @param int|null $clearAt
|
||||
* @param bool $expectExisting
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectException
|
||||
* @param string|null $expectedExceptionClass
|
||||
* @param string|null $expectedExceptionMessage
|
||||
*
|
||||
* @dataProvider setPredefinedMessageDataProvider
|
||||
*/
|
||||
public function testSetPredefinedMessage(string $userId,
|
||||
public function testSetPredefinedMessage(
|
||||
string $userId,
|
||||
string $messageId,
|
||||
bool $isValidMessageId,
|
||||
?int $clearAt,
|
||||
|
|
@ -388,7 +356,8 @@ class StatusServiceTest extends TestCase {
|
|||
bool $expectSuccess,
|
||||
bool $expectException,
|
||||
?string $expectedExceptionClass,
|
||||
?string $expectedExceptionMessage): void {
|
||||
?string $expectedExceptionMessage,
|
||||
): void {
|
||||
$userStatus = new UserStatus();
|
||||
|
||||
if ($expectExisting) {
|
||||
|
|
@ -451,7 +420,7 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setPredefinedMessageDataProvider(): array {
|
||||
public static function setPredefinedMessageDataProvider(): array {
|
||||
return [
|
||||
['john.doe', 'sick-leave', true, null, true, true, false, null, null],
|
||||
['john.doe', 'sick-leave', true, null, false, true, false, null, null],
|
||||
|
|
@ -465,20 +434,10 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param string|null $statusIcon
|
||||
* @param bool $supportsEmoji
|
||||
* @param string $message
|
||||
* @param int|null $clearAt
|
||||
* @param bool $expectExisting
|
||||
* @param bool $expectSuccess
|
||||
* @param bool $expectException
|
||||
* @param string|null $expectedExceptionClass
|
||||
* @param string|null $expectedExceptionMessage
|
||||
*
|
||||
* @dataProvider setCustomMessageDataProvider
|
||||
*/
|
||||
public function testSetCustomMessage(string $userId,
|
||||
public function testSetCustomMessage(
|
||||
string $userId,
|
||||
?string $statusIcon,
|
||||
bool $supportsEmoji,
|
||||
string $message,
|
||||
|
|
@ -487,7 +446,8 @@ class StatusServiceTest extends TestCase {
|
|||
bool $expectSuccess,
|
||||
bool $expectException,
|
||||
?string $expectedExceptionClass,
|
||||
?string $expectedExceptionMessage): void {
|
||||
?string $expectedExceptionMessage,
|
||||
): void {
|
||||
$userStatus = new UserStatus();
|
||||
|
||||
if ($expectExisting) {
|
||||
|
|
@ -548,7 +508,7 @@ class StatusServiceTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function setCustomMessageDataProvider(): array {
|
||||
public static function setCustomMessageDataProvider(): array {
|
||||
return [
|
||||
['john.doe', '😁', true, 'Custom message', null, true, true, false, null, null],
|
||||
['john.doe', '😁', true, 'Custom message', null, false, true, false, null, null],
|
||||
|
|
@ -815,7 +775,7 @@ class StatusServiceTest extends TestCase {
|
|||
$this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly', 'nobackupanddnd'], 'call');
|
||||
}
|
||||
|
||||
public function dataSetUserStatus(): array {
|
||||
public static function dataSetUserStatus(): array {
|
||||
return [
|
||||
[IUserStatus::MESSAGE_CALENDAR_BUSY, '', false],
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class WebhookListenerMapperTest extends TestCase {
|
|||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function pruneTables() {
|
||||
protected function pruneTables(): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->delete(WebhookListenerMapper::TABLE_NAME)->executeStatement();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -7,9 +10,10 @@ namespace OCA\WorkflowEngine\Tests\Check;
|
|||
|
||||
use OCA\WorkflowEngine\Check\AbstractStringCheck;
|
||||
use OCP\IL10N;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class AbstractStringCheckTest extends \Test\TestCase {
|
||||
protected function getCheckMock() {
|
||||
protected function getCheckMock(): AbstractStringCheck|MockObject {
|
||||
$l = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
@ -19,7 +23,7 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
return sprintf($string, $args);
|
||||
});
|
||||
|
||||
$check = $this->getMockBuilder('OCA\WorkflowEngine\Check\AbstractStringCheck')
|
||||
$check = $this->getMockBuilder(AbstractStringCheck::class)
|
||||
->setConstructorArgs([
|
||||
$l,
|
||||
])
|
||||
|
|
@ -32,7 +36,7 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
return $check;
|
||||
}
|
||||
|
||||
public function dataExecuteStringCheck() {
|
||||
public static function dataExecuteStringCheck(): array {
|
||||
return [
|
||||
['is', 'same', 'same', true],
|
||||
['is', 'different', 'not the same', false],
|
||||
|
|
@ -48,19 +52,15 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteStringCheck
|
||||
* @param string $operation
|
||||
* @param string $checkValue
|
||||
* @param string $actualValue
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteStringCheck($operation, $checkValue, $actualValue, $expected): void {
|
||||
public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
|
||||
$check = $this->getCheckMock();
|
||||
|
||||
/** @var AbstractStringCheck $check */
|
||||
$this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue]));
|
||||
}
|
||||
|
||||
public function dataValidateCheck() {
|
||||
public static function dataValidateCheck(): array {
|
||||
return [
|
||||
['is', '/Invalid(Regex/'],
|
||||
['!is', '/Invalid(Regex/'],
|
||||
|
|
@ -71,10 +71,8 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataValidateCheck
|
||||
* @param string $operator
|
||||
* @param string $value
|
||||
*/
|
||||
public function testValidateCheck($operator, $value): void {
|
||||
public function testValidateCheck(string $operator, string $value): void {
|
||||
$check = $this->getCheckMock();
|
||||
|
||||
/** @var AbstractStringCheck $check */
|
||||
|
|
@ -83,7 +81,7 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function dataValidateCheckInvalid() {
|
||||
public static function dataValidateCheckInvalid(): array {
|
||||
return [
|
||||
['!!is', '', 1, 'The given operator is invalid'],
|
||||
['less', '', 1, 'The given operator is invalid'],
|
||||
|
|
@ -94,12 +92,8 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataValidateCheckInvalid
|
||||
* @param $operator
|
||||
* @param $value
|
||||
* @param $exceptionCode
|
||||
* @param $exceptionMessage
|
||||
*/
|
||||
public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage): void {
|
||||
public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
|
||||
$check = $this->getCheckMock();
|
||||
|
||||
try {
|
||||
|
|
@ -111,7 +105,7 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataMatch() {
|
||||
public static function dataMatch(): array {
|
||||
return [
|
||||
['/valid/', 'valid', [], true],
|
||||
['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit
|
||||
|
|
@ -120,12 +114,8 @@ class AbstractStringCheckTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataMatch
|
||||
* @param string $pattern
|
||||
* @param string $subject
|
||||
* @param array[] $matches
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testMatch($pattern, $subject, $matches, $expected): void {
|
||||
public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void {
|
||||
$check = $this->getCheckMock();
|
||||
|
||||
$this->invokePrivate($check, 'matches', [$matches]);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -8,19 +11,14 @@ namespace OCA\WorkflowEngine\Tests\Check;
|
|||
use OCA\WorkflowEngine\Check\RequestRemoteAddress;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class RequestRemoteAddressTest extends \Test\TestCase {
|
||||
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $request;
|
||||
protected IRequest&MockObject $request;
|
||||
|
||||
/**
|
||||
* @return IL10N|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected function getL10NMock() {
|
||||
$l = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
protected function getL10NMock(): IL10N&MockObject {
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->expects($this->any())
|
||||
->method('t')
|
||||
->willReturnCallback(function ($string, $args) {
|
||||
|
|
@ -32,11 +30,10 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->request = $this->getMockBuilder(IRequest::class)
|
||||
->getMock();
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
}
|
||||
|
||||
public function dataExecuteCheckIPv4() {
|
||||
public static function dataExecuteCheckIPv4(): array {
|
||||
return [
|
||||
['127.0.0.1/32', '127.0.0.1', true],
|
||||
['127.0.0.1/32', '127.0.0.0', false],
|
||||
|
|
@ -49,11 +46,8 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheckIPv4
|
||||
* @param string $value
|
||||
* @param string $ip
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckMatchesIPv4($value, $ip, $expected): void {
|
||||
public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void {
|
||||
$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
|
||||
|
||||
$this->request->expects($this->once())
|
||||
|
|
@ -65,11 +59,8 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheckIPv4
|
||||
* @param string $value
|
||||
* @param string $ip
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckNotMatchesIPv4($value, $ip, $expected): void {
|
||||
public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void {
|
||||
$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
|
||||
|
||||
$this->request->expects($this->once())
|
||||
|
|
@ -79,7 +70,7 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
$this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value));
|
||||
}
|
||||
|
||||
public function dataExecuteCheckIPv6() {
|
||||
public static function dataExecuteCheckIPv6(): array {
|
||||
return [
|
||||
['::1/128', '::1', true],
|
||||
['::2/128', '::3', false],
|
||||
|
|
@ -93,11 +84,8 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheckIPv6
|
||||
* @param string $value
|
||||
* @param string $ip
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckMatchesIPv6($value, $ip, $expected): void {
|
||||
public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void {
|
||||
$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
|
||||
|
||||
$this->request->expects($this->once())
|
||||
|
|
@ -109,11 +97,8 @@ class RequestRemoteAddressTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheckIPv6
|
||||
* @param string $value
|
||||
* @param string $ip
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckNotMatchesIPv6($value, $ip, $expected): void {
|
||||
public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void {
|
||||
$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
|
||||
|
||||
$this->request->expects($this->once())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -8,19 +11,13 @@ namespace OCA\WorkflowEngine\Tests\Check;
|
|||
use OCA\WorkflowEngine\Check\RequestTime;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IL10N;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class RequestTimeTest extends \Test\TestCase {
|
||||
protected ITimeFactory&MockObject $timeFactory;
|
||||
|
||||
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $timeFactory;
|
||||
|
||||
/**
|
||||
* @return IL10N|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected function getL10NMock() {
|
||||
$l = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
protected function getL10NMock(): IL10N&MockObject {
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->expects($this->any())
|
||||
->method('t')
|
||||
->willReturnCallback(function ($string, $args) {
|
||||
|
|
@ -32,11 +29,10 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory')
|
||||
->getMock();
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
}
|
||||
|
||||
public function dataExecuteCheck() {
|
||||
public static function dataExecuteCheck(): array {
|
||||
return [
|
||||
[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00
|
||||
[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00
|
||||
|
|
@ -69,11 +65,8 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheck
|
||||
* @param string $value
|
||||
* @param int $timestamp
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckIn($value, $timestamp, $expected): void {
|
||||
public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void {
|
||||
$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
|
||||
|
||||
$this->timeFactory->expects($this->once())
|
||||
|
|
@ -85,11 +78,8 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheck
|
||||
* @param string $value
|
||||
* @param int $timestamp
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheckNotIn($value, $timestamp, $expected): void {
|
||||
public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void {
|
||||
$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
|
||||
|
||||
$this->timeFactory->expects($this->once())
|
||||
|
|
@ -99,7 +89,7 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
$this->assertEquals(!$expected, $check->executeCheck('!in', $value));
|
||||
}
|
||||
|
||||
public function dataValidateCheck() {
|
||||
public static function dataValidateCheck(): array {
|
||||
return [
|
||||
['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'],
|
||||
['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'],
|
||||
|
|
@ -109,16 +99,14 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataValidateCheck
|
||||
* @param string $operator
|
||||
* @param string $value
|
||||
*/
|
||||
public function testValidateCheck($operator, $value): void {
|
||||
public function testValidateCheck(string $operator, string $value): void {
|
||||
$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
|
||||
$check->validateCheck($operator, $value);
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function dataValidateCheckInvalid() {
|
||||
public static function dataValidateCheckInvalid(): array {
|
||||
return [
|
||||
['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'],
|
||||
['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
|
||||
|
|
@ -132,12 +120,8 @@ class RequestTimeTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataValidateCheckInvalid
|
||||
* @param string $operator
|
||||
* @param string $value
|
||||
* @param int $exceptionCode
|
||||
* @param string $exceptionMessage
|
||||
*/
|
||||
public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage): void {
|
||||
public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
|
||||
$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -9,24 +12,19 @@ use OCA\WorkflowEngine\Check\AbstractStringCheck;
|
|||
use OCA\WorkflowEngine\Check\RequestUserAgent;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class RequestUserAgentTest extends TestCase {
|
||||
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $request;
|
||||
|
||||
/** @var RequestUserAgent */
|
||||
protected $check;
|
||||
protected IRequest&MockObject $request;
|
||||
protected RequestUserAgent $check;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l */
|
||||
$l = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
/** @var IL10N&MockObject $l */
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->expects($this->any())
|
||||
->method('t')
|
||||
->willReturnCallback(function ($string, $args) {
|
||||
|
|
@ -36,7 +34,7 @@ class RequestUserAgentTest extends TestCase {
|
|||
$this->check = new RequestUserAgent($l, $this->request);
|
||||
}
|
||||
|
||||
public function dataExecuteCheck() {
|
||||
public static function dataExecuteCheck(): array {
|
||||
return [
|
||||
['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
|
||||
['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
|
||||
|
|
@ -86,12 +84,8 @@ class RequestUserAgentTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecuteCheck
|
||||
* @param string $operation
|
||||
* @param string $checkValue
|
||||
* @param string $actualValue
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testExecuteCheck($operation, $checkValue, $actualValue, $expected): void {
|
||||
public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
|
||||
$this->request->expects($this->once())
|
||||
->method('getHeader')
|
||||
->willReturn($actualValue);
|
||||
|
|
|
|||
Loading…
Reference in a new issue