Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/announcementcenter.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-12-16 00:57:23 +0300
committerJoas Schilling <coding@schilljs.com>2020-12-16 00:57:23 +0300
commita7d853436c55903833e09951e60105254e8da1fd (patch)
tree33cdbec7873cb3bb9193f1289c3079e890b248f2 /tests
parent0d1aec675b7385a467d54176c89745c0f5ca7818 (diff)
Make PHPUnit calls static
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Activity/SettingTest.php20
-rw-r--r--tests/AppInfo/ApplicationTest.php4
-rw-r--r--tests/AppInfo/RoutesTest.php16
-rw-r--r--tests/BackgroundJobTest.php70
-rw-r--r--tests/Controller/PageControllerTest.php88
-rw-r--r--tests/ManagerTest.php78
-rw-r--r--tests/Notification/NotifierTest.php50
-rw-r--r--tests/Settings/AdminTest.php8
8 files changed, 167 insertions, 167 deletions
diff --git a/tests/Activity/SettingTest.php b/tests/Activity/SettingTest.php
index 8ec21b6..7b0879f 100644
--- a/tests/Activity/SettingTest.php
+++ b/tests/Activity/SettingTest.php
@@ -38,7 +38,7 @@ class SettingTest extends TestCase {
*/
public function testImplementsInterface($settingClass) {
$setting = \OC::$server->query($settingClass);
- $this->assertInstanceOf(ISetting::class, $setting);
+ self::assertInstanceOf(ISetting::class, $setting);
}
/**
@@ -48,7 +48,7 @@ class SettingTest extends TestCase {
public function testGetIdentifier($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsString($setting->getIdentifier());
+ self::assertIsString($setting->getIdentifier());
}
/**
@@ -58,7 +58,7 @@ class SettingTest extends TestCase {
public function testGetName($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsString($setting->getName());
+ self::assertIsString($setting->getName());
}
/**
@@ -69,9 +69,9 @@ class SettingTest extends TestCase {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
$priority = $setting->getPriority();
- $this->assertIsInt($setting->getPriority());
- $this->assertGreaterThanOrEqual(0, $priority);
- $this->assertLessThanOrEqual(100, $priority);
+ self::assertIsInt($setting->getPriority());
+ self::assertGreaterThanOrEqual(0, $priority);
+ self::assertLessThanOrEqual(100, $priority);
}
/**
@@ -81,7 +81,7 @@ class SettingTest extends TestCase {
public function testCanChangeStream($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsBool($setting->canChangeStream());
+ self::assertIsBool($setting->canChangeStream());
}
/**
@@ -91,7 +91,7 @@ class SettingTest extends TestCase {
public function testIsDefaultEnabledStream($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsBool($setting->isDefaultEnabledStream());
+ self::assertIsBool($setting->isDefaultEnabledStream());
}
/**
@@ -101,7 +101,7 @@ class SettingTest extends TestCase {
public function testCanChangeMail($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsBool($setting->canChangeMail());
+ self::assertIsBool($setting->canChangeMail());
}
/**
@@ -111,6 +111,6 @@ class SettingTest extends TestCase {
public function testIsDefaultEnabledMail($settingClass) {
/** @var ISetting $setting */
$setting = \OC::$server->query($settingClass);
- $this->assertIsBool($setting->isDefaultEnabledMail());
+ self::assertIsBool($setting->isDefaultEnabledMail());
}
}
diff --git a/tests/AppInfo/ApplicationTest.php b/tests/AppInfo/ApplicationTest.php
index 6052471..f5be0d9 100644
--- a/tests/AppInfo/ApplicationTest.php
+++ b/tests/AppInfo/ApplicationTest.php
@@ -69,7 +69,7 @@ class ApplicationTest extends TestCase {
public function testContainerAppName() {
$this->app = new Application();
- $this->assertEquals('announcementcenter', $this->container->getAppName());
+ self::assertEquals('announcementcenter', $this->container->getAppName());
}
public function dataContainerQuery(): array {
@@ -96,6 +96,6 @@ class ApplicationTest extends TestCase {
* @param string $expected
*/
public function testContainerQuery(string $service, string $expected) {
- $this->assertInstanceOf($expected, $this->container->query($service));
+ self::assertInstanceOf($expected, $this->container->query($service));
}
}
diff --git a/tests/AppInfo/RoutesTest.php b/tests/AppInfo/RoutesTest.php
index 5b58c9e..937e1a9 100644
--- a/tests/AppInfo/RoutesTest.php
+++ b/tests/AppInfo/RoutesTest.php
@@ -26,13 +26,13 @@ namespace OCA\AnnouncementCenter\Tests;
class RoutesTest extends TestCase {
public function testRoutes() {
$routes = include __DIR__ . '/../../appinfo/routes.php';
- $this->assertIsArray($routes);
- $this->assertCount(2, $routes);
- $this->assertArrayHasKey('routes', $routes);
- $this->assertIsArray($routes['routes']);
- $this->assertGreaterThanOrEqual(1, \count($routes['routes']));
- $this->assertArrayHasKey('ocs', $routes);
- $this->assertIsArray($routes['ocs']);
- $this->assertGreaterThanOrEqual(1, \count($routes['ocs']));
+ self::assertIsArray($routes);
+ self::assertCount(2, $routes);
+ self::assertArrayHasKey('routes', $routes);
+ self::assertIsArray($routes['routes']);
+ self::assertGreaterThanOrEqual(1, \count($routes['routes']));
+ self::assertArrayHasKey('ocs', $routes);
+ self::assertIsArray($routes['ocs']);
+ self::assertGreaterThanOrEqual(1, \count($routes['ocs']));
}
}
diff --git a/tests/BackgroundJobTest.php b/tests/BackgroundJobTest.php
index 7bad761..091761d 100644
--- a/tests/BackgroundJobTest.php
+++ b/tests/BackgroundJobTest.php
@@ -94,12 +94,12 @@ class BackgroundJobTest extends TestCase {
public function testRunThrows(): void {
$job = $this->getJob(['createPublicity']);
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('getAnnouncement')
->with(23, true)
->willThrowException(new AnnouncementDoesNotExistException());
- $job->expects($this->never())
+ $job->expects(self::never())
->method('createPublicity');
self::invokePrivate($job, 'run', [[
@@ -128,12 +128,12 @@ class BackgroundJobTest extends TestCase {
$announcement = $this->createMock(Announcement::class);
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('getAnnouncement')
->with($id, true)
->willReturn($announcement);
- $job->expects($this->once())
+ $job->expects(self::once())
->method('createPublicity')
->with($announcement, [
'id' => $id,
@@ -156,13 +156,13 @@ class BackgroundJobTest extends TestCase {
*/
protected function getUserMock($uid, $displayName, $loggedIn = true) {
$user = $this->createMock(IUser::class);
- $user->expects($this->any())
+ $user
->method('getUID')
->willReturn($uid);
- $user->expects($this->any())
+ $user
->method('getDisplayName')
->willReturn($displayName);
- $user->expects($this->any())
+ $user
->method('getLastLogin')
->willReturn($loggedIn ? 1234 : 0);
return $user;
@@ -174,7 +174,7 @@ class BackgroundJobTest extends TestCase {
*/
protected function getGroupMock(array $users) {
$group = $this->createMock(IGroup::class);
- $group->expects($this->any())
+ $group
->method('getUsers')
->willReturn($users);
return $group;
@@ -201,51 +201,51 @@ class BackgroundJobTest extends TestCase {
*/
public function testCreatePublicity(array $groups, bool $everyone, array $publicity): void {
$event = $this->createMock(IEvent::class);
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setApp')
->with('announcementcenter')
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setType')
->with('announcementcenter')
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setAuthor')
->with('author')
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setTimestamp')
->with(1337)
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setSubject')
->with('announcementsubject', ['author' => 'author', 'announcement' => 10])
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setMessage')
->with('announcementmessage', [])
->willReturnSelf();
- $event->expects($this->once())
+ $event->expects(self::once())
->method('setObject')
->with('announcement', 10)
->willReturnSelf();
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setApp')
->with('announcementcenter')
->willReturnSelf();
$dateTime = new \DateTime();
$dateTime->setTimestamp(1337);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setDateTime')
->with($dateTime)
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setSubject')
->with('announced', ['author'])
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setObject')
->with('announcement', 10)
->willReturnSelf();
@@ -256,19 +256,19 @@ class BackgroundJobTest extends TestCase {
]);
if ($everyone) {
- $job->expects($this->once())
+ $job->expects(self::once())
->method('createPublicityEveryone')
->with('author', $event, $notification, $publicity);
} else {
- $job->expects($this->once())
+ $job->expects(self::once())
->method('createPublicityGroups')
->with('author', $event, $notification, $groups, $publicity);
}
- $this->activityManager->expects($this->once())
+ $this->activityManager->expects(self::once())
->method('generateEvent')
->willReturn($event);
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('createNotification')
->willReturn($notification);
@@ -278,7 +278,7 @@ class BackgroundJobTest extends TestCase {
'time' => 1337,
]);
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('getGroups')
->willReturn($groups);
@@ -307,19 +307,19 @@ class BackgroundJobTest extends TestCase {
*/
public function testCreatePublicityEveryone(array $publicity, $activities, $notifications): void {
$event = $this->createMock(IEvent::class);
- $event->expects($activities ? $this->exactly(5) : $this->never())
+ $event->expects($activities ? self::exactly(5) : self::never())
->method('setAffectedUser')
->willReturnSelf();
$notification = $this->createMock(INotification::class);
- $notification->expects($notifications ? $this->exactly(4) : $this->never())
+ $notification->expects($notifications ? self::exactly(4) : self::never())
->method('setUser')
->willReturnSelf();
$job = $this->getJob();
- $this->userManager->expects($this->once())
+ $this->userManager->expects(self::once())
->method('callForSeenUsers')
- ->with($this->anything())
+ ->with(self::anything())
->willReturnCallback(function ($callback) {
$users = [
$this->getUserMock('author', 'User One'),
@@ -334,9 +334,9 @@ class BackgroundJobTest extends TestCase {
})
;
- $this->activityManager->expects($activities ? $this->exactly(5) : $this->never())
+ $this->activityManager->expects($activities ? self::exactly(5) : self::never())
->method('publish');
- $this->notificationManager->expects($notifications ? $this->exactly(4) : $this->never())
+ $this->notificationManager->expects($notifications ? self::exactly(4) : self::never())
->method('notify');
self::invokePrivate($job, 'createPublicityEveryone', ['author', $event, $notification, $publicity]);
@@ -351,17 +351,17 @@ class BackgroundJobTest extends TestCase {
*/
public function testCreatePublicityGroups(array $publicity, $activities, $notifications): void {
$event = $this->createMock(IEvent::class);
- $event->expects($activities ? $this->exactly(4) : $this->never())
+ $event->expects($activities ? self::exactly(4) : self::never())
->method('setAffectedUser')
->willReturnSelf();
$notification = $this->createMock(INotification::class);
- $notification->expects($notifications ? $this->exactly(3) : $this->never())
+ $notification->expects($notifications ? self::exactly(3) : self::never())
->method('setUser')
->willReturnSelf();
$job = $this->getJob();
- $this->groupManager->expects($this->exactly(4))
+ $this->groupManager->expects(self::exactly(4))
->method('get')
->willReturnMap([
['gid0', null],
@@ -378,9 +378,9 @@ class BackgroundJobTest extends TestCase {
])],
]);
- $this->activityManager->expects($activities ? $this->exactly(4) : $this->never())
+ $this->activityManager->expects($activities ? self::exactly(4) : self::never())
->method('publish');
- $this->notificationManager->expects($notifications ? $this->exactly(3) : $this->never())
+ $this->notificationManager->expects($notifications ? self::exactly(3) : self::never())
->method('notify');
self::invokePrivate($job, 'createPublicityGroups', ['author', $event, $notification, ['gid0', 'gid1', 'gid2', 'gid3'], $publicity]);
diff --git a/tests/Controller/PageControllerTest.php b/tests/Controller/PageControllerTest.php
index cc1a353..d4755c5 100644
--- a/tests/Controller/PageControllerTest.php
+++ b/tests/Controller/PageControllerTest.php
@@ -86,7 +86,7 @@ class PageControllerTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->initialStateService = $this->createMock(IInitialStateService::class);
- $this->l->expects($this->any())
+ $this->l
->method('t')
->willReturnCallback(function ($string, $args) {
return vsprintf($string, $args);
@@ -134,10 +134,10 @@ class PageControllerTest extends TestCase {
protected function getUserMock(string $uid, string $displayName): IUser {
/** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
- $user->expects($this->any())
+ $user
->method('getUID')
->willReturn($uid);
- $user->expects($this->any())
+ $user
->method('getDisplayName')
->willReturn($displayName);
return $user;
@@ -190,7 +190,7 @@ class PageControllerTest extends TestCase {
* @param array $expected
*/
public function legacyTestGet($offset, $announcements, $userMap, $expected) {
- $this->userManager->expects($this->any())
+ $this->userManager
->method('get')
->willReturnMap($userMap);
@@ -211,19 +211,19 @@ class PageControllerTest extends TestCase {
return $announcement;
}, $announcements);
- $this->manager->expects($this->any())
+ $this->manager
->method('getAnnouncements')
->with($offset)
->willReturn($announcements);
- $this->manager->expects($this->exactly(count($comments)))
+ $this->manager->expects(self::exactly(count($comments)))
->method('getNumberOfComments')
->willReturnMap($comments);
$controller = $this->getController();
$jsonResponse = $controller->get($offset);
- $this->assertEquals($expected, $jsonResponse->getData());
+ self::assertEquals($expected, $jsonResponse->getData());
}
public function dataDelete(): array {
@@ -240,23 +240,23 @@ class PageControllerTest extends TestCase {
* @param int $statusCode
*/
public function testDelete($id, $isAdmin, $statusCode) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn($isAdmin);
if ($isAdmin) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('delete')
->with($id);
} else {
- $this->manager->expects($this->never())
+ $this->manager->expects(self::never())
->method('delete');
}
$controller = $this->getController();
$response = $controller->delete($id);
- $this->assertEquals($statusCode, $response->getStatus());
+ self::assertEquals($statusCode, $response->getStatus());
}
public function dataAddThrows() {
@@ -272,46 +272,46 @@ class PageControllerTest extends TestCase {
* @param array $expectedData
*/
public function testAddThrows($subject, array $expectedData) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn(true);
- $this->userSession->expects($this->once())
+ $this->userSession->expects(self::once())
->method('getUser')
->willReturn($this->getUserMock('author', 'author'));
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('announce')
- ->with($subject, '', 'author', $this->anything())
+ ->with($subject, '', 'author', self::anything())
->willThrowException(new \InvalidArgumentException());
$controller = $this->getController(['createPublicity']);
- $controller->expects($this->never())
+ $controller->expects(self::never())
->method('createPublicity');
$response = $controller->add($subject, '', [], true, true, true);
- $this->assertInstanceOf(JSONResponse::class, $response);
- $this->assertSame($expectedData, $response->getData());
+ self::assertInstanceOf(JSONResponse::class, $response);
+ self::assertSame($expectedData, $response->getData());
}
public function testAddNoAdmin() {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn(false);
- $this->manager->expects($this->never())
+ $this->manager->expects(self::never())
->method('announce');
- $this->jobList->expects($this->never())
+ $this->jobList->expects(self::never())
->method('add');
$controller = $this->getController(['createPublicity']);
- $controller->expects($this->never())
+ $controller->expects(self::never())
->method('createPublicity');
$response = $controller->add('subject', '', [], true, true, true);
- $this->assertInstanceOf(JSONResponse::class, $response);
- $this->assertSame(Http::STATUS_FORBIDDEN, $response->getStatus());
+ self::assertInstanceOf(JSONResponse::class, $response);
+ self::assertSame(Http::STATUS_FORBIDDEN, $response->getStatus());
}
public function dataAdd() {
@@ -335,16 +335,16 @@ class PageControllerTest extends TestCase {
* @param bool $comments
*/
public function legacyTestAdd($subject, $message, array $groups, $activities, $notifications, $comments) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn(true);
- $this->userSession->expects($this->once())
+ $this->userSession->expects(self::once())
->method('getUser')
->willReturn($this->getUserMock('author', 'author'));
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('announce')
- ->with($subject, $message, 'author', $this->anything(), $groups, $comments)
+ ->with($subject, $message, 'author', self::anything(), $groups, $comments)
->willReturn([
'author' => 'author',
'subject' => $subject,
@@ -353,11 +353,11 @@ class PageControllerTest extends TestCase {
'id' => 10,
'comments' => $comments,
]);
- $this->userManager->expects($this->once())
+ $this->userManager->expects(self::once())
->method('get')
->with('author')
->willReturn($this->getUserMock('author', 'Author'));
- $this->jobList->expects(($activities || $notifications) ? $this->once() : $this->never())
+ $this->jobList->expects(($activities || $notifications) ? self::once() : self::never())
->method('add')
->with('OCA\AnnouncementCenter\BackgroundJob', [
'id' => 10,
@@ -369,12 +369,12 @@ class PageControllerTest extends TestCase {
$response = $controller->add($subject, $message, $groups, $activities, $notifications, $comments);
- $this->assertInstanceOf(JSONResponse::class, $response);
+ self::assertInstanceOf(JSONResponse::class, $response);
$data = $response->getData();
- $this->assertArrayHasKey('time', $data);
- $this->assertInternalType('int', $data['time']);
+ self::assertArrayHasKey('time', $data);
+ self::assertInternalType('int', $data['time']);
unset($data['time']);
- $this->assertEquals([
+ self::assertEquals([
'author' => 'Author',
'author_id' => 'author',
'subject' => $subject,
@@ -404,10 +404,10 @@ class PageControllerTest extends TestCase {
* @param bool $allowComments
*/
public function testIndex(bool $isAdmin, string $createActivitiesConfig, bool $createActivities, string $createNotificationsConfig, bool $createNotifications, string $allowCommentsConfig, bool $allowComments) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn($isAdmin);
- $this->config->expects($this->exactly(3))
+ $this->config->expects(self::exactly(3))
->method('getAppValue')
->willReturnMap([
['announcementcenter', 'create_activities', 'yes', $createActivitiesConfig],
@@ -426,15 +426,15 @@ class PageControllerTest extends TestCase {
$controller = $this->getController();
$response = $controller->index();
- $this->assertSame('user', $response->getRenderAs());
- $this->assertSame('main', $response->getTemplateName());
+ self::assertSame('user', $response->getRenderAs());
+ self::assertSame('main', $response->getTemplateName());
}
protected function getGroupMock(string $gid): IGroup {
/** @var IGroup|MockObject $group */
$group = $this->createMock(IGroup::class);
- $group->expects($this->any())
+ $group
->method('getGID')
->willReturn($gid);
@@ -458,22 +458,22 @@ class PageControllerTest extends TestCase {
* @param int $code
*/
public function testSearchGroup(bool $isAdmin, string $pattern, $groupSearch, array $expected, int $code) {
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('checkIsAdmin')
->willReturn($isAdmin);
if ($groupSearch !== null) {
- $this->groupManager->expects($this->once())
+ $this->groupManager->expects(self::once())
->method('search')
->willReturn($groupSearch);
} else {
- $this->groupManager->expects($this->never())
+ $this->groupManager->expects(self::never())
->method('search');
}
$controller = $this->getController();
$response = $controller->searchGroups($pattern);
- $this->assertSame($code, $response->getStatus());
- $this->assertSame($expected, $response->getData());
+ self::assertSame($code, $response->getStatus());
+ self::assertSame($expected, $response->getData());
}
}
diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php
index e5360bc..d0eee91 100644
--- a/tests/ManagerTest.php
+++ b/tests/ManagerTest.php
@@ -104,7 +104,7 @@ class ManagerTest extends TestCase {
}
public function testGetAnnouncementNotExist(): void {
- $this->announcementMapper->expects($this->once())
+ $this->announcementMapper->expects(self::once())
->method('getById')
->with(42)
->willThrowException(new DoesNotExistException('Entity does not exist'));
@@ -129,35 +129,35 @@ class ManagerTest extends TestCase {
public function testDelete(): void {
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setApp')
->with('announcementcenter')
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setObject')
->with('announcement', 23)
->willReturnSelf();
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('createNotification')
->willReturn($notification);
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('markProcessed')
->with($notification);
- $this->commentsManager->expects($this->once())
+ $this->commentsManager->expects(self::once())
->method('deleteCommentsAtObject')
->with('announcement', $this->identicalTo('23'));
$announcement = $this->createMock(Announcement::class);
- $this->announcementMapper->expects($this->once())
+ $this->announcementMapper->expects(self::once())
->method('getById')
->with(23)
->willReturn($announcement);
- $this->announcementMapper->expects($this->once())
+ $this->announcementMapper->expects(self::once())
->method('delete')
->with($announcement);
- $this->groupMapper->expects($this->once())
+ $this->groupMapper->expects(self::once())
->method('deleteGroupsForAnnouncement')
->with($announcement);
@@ -166,7 +166,7 @@ class ManagerTest extends TestCase {
protected function getUserMock($uid) {
$user = $this->createMock(IUser::class);
- $user->expects($this->any())
+ $user
->method('getUID')
->willReturn($uid);
return $user;
@@ -174,15 +174,15 @@ class ManagerTest extends TestCase {
protected function setUserGroups($groups) {
if ($groups === null) {
- $this->userSession->expects($this->any())
+ $this->userSession
->method('getUser')
->willReturn(null);
} else {
$user = $this->getUserMock('uid');
- $this->userSession->expects($this->any())
+ $this->userSession
->method('getUser')
->willReturn($user);
- $this->groupManager->expects($this->any())
+ $this->groupManager
->method('getUserGroupIds')
->with($user)
->willReturn($groups);
@@ -204,11 +204,11 @@ class ManagerTest extends TestCase {
/** @var Announcement $announcement */
$announcement = Announcement::fromParams([]);
- $this->groupMapper->expects($this->once())
+ $this->groupMapper->expects(self::once())
->method('getGroupsForAnnouncement')
->willReturn($groups);
- $this->assertSame($groups, $this->manager->getGroups($announcement));
+ self::assertSame($groups, $this->manager->getGroups($announcement));
}
public function dataHasNotifications(): array {
@@ -228,7 +228,7 @@ class ManagerTest extends TestCase {
* @param int $numNotifications
*/
public function testHasNotifications(int $id, bool $hasActivityJob, bool $hasNotificationJob, int $numNotifications): void {
- $this->jobList->expects($hasActivityJob ? $this->once() : $this->exactly(2))
+ $this->jobList->expects($hasActivityJob ? self::once() : self::exactly(2))
->method('has')
->willReturnMap([
[BackgroundJob::class, [
@@ -245,26 +245,26 @@ class ManagerTest extends TestCase {
if (!$hasNotificationJob) {
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setApp')
->with('announcementcenter')
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setObject')
->with('announcement', $id)
->willReturnSelf();
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('createNotification')
->willReturn($notification);
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('getCount')
->with($notification)
->willReturn($numNotifications);
} else {
- $this->notificationManager->expects($this->never())
+ $this->notificationManager->expects(self::never())
->method('createNotification');
- $this->notificationManager->expects($this->never())
+ $this->notificationManager->expects(self::never())
->method('getCount');
}
@@ -288,7 +288,7 @@ class ManagerTest extends TestCase {
* @param bool $hasActivity
*/
public function testRemoveNotifications(int $id, bool $hasActivity): void {
- $this->jobList->expects($this->once())
+ $this->jobList->expects(self::once())
->method('has')
->with(BackgroundJob::class, [
'id' => $id,
@@ -298,14 +298,14 @@ class ManagerTest extends TestCase {
->willReturn($hasActivity);
if ($hasActivity) {
- $this->jobList->expects($this->once())
+ $this->jobList->expects(self::once())
->method('remove')
->with(BackgroundJob::class, [
'id' => $id,
'activities' => true,
'notifications' => true,
]);
- $this->jobList->expects($this->once())
+ $this->jobList->expects(self::once())
->method('add')
->with(BackgroundJob::class, [
'id' => $id,
@@ -313,7 +313,7 @@ class ManagerTest extends TestCase {
'notifications' => false,
]);
} else {
- $this->jobList->expects($this->once())
+ $this->jobList->expects(self::once())
->method('remove')
->with(BackgroundJob::class, [
'id' => $id,
@@ -323,19 +323,19 @@ class ManagerTest extends TestCase {
}
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setApp')
->with('announcementcenter')
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setObject')
->with('announcement', $id)
->willReturnSelf();
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('createNotification')
->willReturn($notification);
- $this->notificationManager->expects($this->once())
+ $this->notificationManager->expects(self::once())
->method('markProcessed')
->with($notification);
@@ -391,32 +391,32 @@ class ManagerTest extends TestCase {
* @param bool $expected
*/
public function testCheckIsAdmin($adminGroups, $inGroupMap, $expected) {
- $this->config->expects($this->any())
+ $this->config
->method('getAppValue')
->with('announcementcenter', 'admin_groups', '["admin"]')
->willReturn(json_encode($adminGroups));
$user = $this->getUserMock('uid');
- $this->userSession->expects($this->any())
+ $this->userSession
->method('getUser')
->willReturn($user);
- $this->groupManager->expects($this->exactly(sizeof($inGroupMap)))
+ $this->groupManager->expects(self::exactly(sizeof($inGroupMap)))
->method('isInGroup')
->willReturnMap($inGroupMap);
- $this->assertEquals($expected, $this->manager->checkIsAdmin());
+ self::assertEquals($expected, $this->manager->checkIsAdmin());
}
public function testCheckIsAdminNoUser() {
- $this->userSession->expects($this->any())
+ $this->userSession
->method('getUser')
->willReturn(null);
- $this->groupManager->expects($this->never())
+ $this->groupManager->expects(self::never())
->method('isInGroup');
- $this->assertEquals(false, $this->manager->checkIsAdmin());
+ self::assertEquals(false, $this->manager->checkIsAdmin());
}
protected function assertDeleteMetaData($id) {
@@ -457,7 +457,7 @@ class ManagerTest extends TestCase {
->willReturnSelf();
$notification->expects($this->at(1))
->method('setObject')
- ->with('announcement', $this->anything())
+ ->with('announcement', self::anything())
->willReturnSelf();
$this->notificationManager->expects($this->at($offset + 0))
@@ -469,7 +469,7 @@ class ManagerTest extends TestCase {
->willReturn(0);
if ($calls > 1) {
- $this->assertHasNotification($calls - 1, $offset + 2);
+ self::assertHasNotification($calls - 1, $offset + 2);
}
}
}
diff --git a/tests/Notification/NotifierTest.php b/tests/Notification/NotifierTest.php
index d2ad92f..4cdc303 100644
--- a/tests/Notification/NotifierTest.php
+++ b/tests/Notification/NotifierTest.php
@@ -63,13 +63,13 @@ class NotifierTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class);
- $this->l->expects($this->any())
+ $this->l
->method('t')
->willReturnCallback(function ($string, $args) {
return vsprintf($string, $args);
});
$this->factory = $this->createMock(IFactory::class);
- $this->factory->expects($this->any())
+ $this->factory
->method('get')
->willReturn($this->l);
@@ -86,10 +86,10 @@ class NotifierTest extends TestCase {
/** @var \OCP\Notification\INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getApp')
->willReturn('notifications');
- $notification->expects($this->never())
+ $notification->expects(self::never())
->method('getSubject');
$this->expectException(\InvalidArgumentException::class);
@@ -101,10 +101,10 @@ class NotifierTest extends TestCase {
/** @var \OCP\Notification\INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getApp')
->willReturn('announcementcenter');
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getSubject')
->willReturn('wrong subject');
@@ -117,17 +117,17 @@ class NotifierTest extends TestCase {
/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getApp')
->willReturn('announcementcenter');
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getSubject')
->willReturn('announced');
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getObjectId')
->willReturn('42');
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('getAnnouncement')
->with(42, false)
->willThrowException(new AnnouncementDoesNotExistException());
@@ -141,7 +141,7 @@ class NotifierTest extends TestCase {
*/
protected function getUserMock() {
$user = $this->createMock(IUser::class);
- $user->expects($this->exactly(2))
+ $user->expects(self::exactly(2))
->method('getDisplayName')
->willReturn('Author');
return $user;
@@ -171,16 +171,16 @@ class NotifierTest extends TestCase {
/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getApp')
->willReturn('announcementcenter');
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getSubject')
->willReturn('announced');
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getSubjectParameters')
->willReturn([$author]);
- $notification->expects($this->exactly(3))
+ $notification->expects(self::exactly(3))
->method('getObjectId')
->willReturn($objectId);
@@ -189,25 +189,25 @@ class NotifierTest extends TestCase {
'message' => $message,
]);
- $this->manager->expects($this->once())
+ $this->manager->expects(self::once())
->method('getAnnouncement')
->with($objectId, false)
->willReturn($announcement);
- $this->userManager->expects($this->once())
+ $this->userManager->expects(self::once())
->method('get')
->with($author)
->willReturn($userObject);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setParsedMessage')
->with($expectedMessage)
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setRichSubject')
- ->with('{user} announced {announcement}', $this->anything())
+ ->with('{user} announced {announcement}', self::anything())
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('getRichSubjectParameters')
->willReturn([
'user' => [
@@ -222,19 +222,19 @@ class NotifierTest extends TestCase {
],
]);
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setParsedSubject')
->with($expectedSubject)
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setLink')
->willReturnSelf();
- $notification->expects($this->once())
+ $notification->expects(self::once())
->method('setIcon')
->willReturnSelf();
$return = $this->notifier->prepare($notification, 'en');
- $this->assertEquals($notification, $return);
+ self::assertEquals($notification, $return);
}
}
diff --git a/tests/Settings/AdminTest.php b/tests/Settings/AdminTest.php
index 38ef5f6..44f0f5d 100644
--- a/tests/Settings/AdminTest.php
+++ b/tests/Settings/AdminTest.php
@@ -101,7 +101,7 @@ class AdminTest extends TestCase {
* @param bool $allowComments
*/
public function testGetForm(array $configMap, $adminGroups, $createActivities, $createNotifications, $allowComments) {
- $this->config->expects($this->exactly(4))
+ $this->config->expects(self::exactly(4))
->method('getAppValue')
->willReturnMap($configMap);
@@ -111,14 +111,14 @@ class AdminTest extends TestCase {
'createNotifications' => $createNotifications,
'allowComments' => $allowComments,
], 'blank');
- $this->assertEquals($expected, $this->admin->getForm());
+ self::assertEquals($expected, $this->admin->getForm());
}
public function testGetSection() {
- $this->assertSame('additional', $this->admin->getSection());
+ self::assertSame('additional', $this->admin->getSection());
}
public function testGetPriority() {
- $this->assertSame(55, $this->admin->getPriority());
+ self::assertSame(55, $this->admin->getPriority());
}
}