diff options
Diffstat (limited to 'apps/twofactor_backupcodes/tests/Unit/BackgroundJob')
-rw-r--r-- | apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php | 56 | ||||
-rw-r--r-- | apps/twofactor_backupcodes/tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php | 78 |
2 files changed, 38 insertions, 96 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php index 57dbb5674cb..87bc65e4309 100644 --- a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\BackgroundJob; @@ -38,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(); @@ -68,7 +38,7 @@ class CheckBackupCodeTest extends TestCase { $this->user = $this->createMock(IUser::class); $this->userManager->method('callForSeenUsers') - ->willReturnCallback(function (\Closure $e) { + ->willReturnCallback(function (\Closure $e): void { $e($this->user); }); @@ -81,7 +51,7 @@ class CheckBackupCodeTest extends TestCase { ); } - public function testRunAlreadyGenerated() { + public function testRunAlreadyGenerated(): void { $this->user->method('isEnabled') ->willReturn(true); @@ -97,7 +67,7 @@ class CheckBackupCodeTest extends TestCase { $this->invokePrivate($this->checkBackupCodes, 'run', [[]]); } - public function testRun() { + public function testRun(): void { $this->user->method('getUID') ->willReturn('myUID'); $this->user->method('isEnabled') @@ -122,7 +92,7 @@ class CheckBackupCodeTest extends TestCase { $this->invokePrivate($this->checkBackupCodes, 'run', [[]]); } - public function testRunDisabledUser() { + public function testRunDisabledUser(): void { $this->user->method('getUID') ->willReturn('myUID'); $this->user->method('isEnabled') @@ -138,7 +108,7 @@ class CheckBackupCodeTest extends TestCase { $this->invokePrivate($this->checkBackupCodes, 'run', [[]]); } - public function testRunNoProviders() { + public function testRunNoProviders(): void { $this->user->method('isEnabled') ->willReturn(true); diff --git a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php index 3640cb29187..6b162894258 100644 --- a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\BackgroundJob; @@ -34,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(); @@ -76,7 +48,7 @@ class RememberBackupCodesJobTest extends TestCase { ); } - public function testInvalidUID() { + public function testInvalidUID(): void { $this->userManager->method('get') ->with('invalidUID') ->willReturn(null); @@ -95,7 +67,7 @@ class RememberBackupCodesJobTest extends TestCase { self::invokePrivate($this->job, 'run', [['uid' => 'invalidUID']]); } - public function testBackupCodesGenerated() { + public function testBackupCodesGenerated(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('validUID'); @@ -125,7 +97,7 @@ class RememberBackupCodesJobTest extends TestCase { self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]); } - public function testNoActiveProvider() { + public function testNoActiveProvider(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('validUID'); @@ -153,7 +125,7 @@ class RememberBackupCodesJobTest extends TestCase { self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]); } - public function testNotificationSend() { + public function testNotificationSend(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('validUID'); @@ -182,18 +154,18 @@ class RememberBackupCodesJobTest extends TestCase { $this->notificationManager->expects($this->once()) ->method('notify') ->with($this->callback(function (INotification $n) { - return $n->getApp() === 'twofactor_backupcodes' && - $n->getUser() === 'validUID' && - $n->getDateTime()->getTimestamp() === 10000000 && - $n->getObjectType() === 'create' && - $n->getObjectId() === 'codes' && - $n->getSubject() === 'create_backupcodes'; + return $n->getApp() === 'twofactor_backupcodes' + && $n->getUser() === 'validUID' + && $n->getDateTime()->getTimestamp() === 10000000 + && $n->getObjectType() === 'create' + && $n->getObjectId() === 'codes' + && $n->getSubject() === 'create_backupcodes'; })); self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]); } - public function testNotificationNotSendForDisabledUser() { + public function testNotificationNotSendForDisabledUser(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('validUID'); @@ -226,11 +198,11 @@ class RememberBackupCodesJobTest extends TestCase { $this->notificationManager->expects($this->once()) ->method('markProcessed') ->with($this->callback(function (INotification $n) { - return $n->getApp() === 'twofactor_backupcodes' && - $n->getUser() === 'validUID' && - $n->getObjectType() === 'create' && - $n->getObjectId() === 'codes' && - $n->getSubject() === 'create_backupcodes'; + return $n->getApp() === 'twofactor_backupcodes' + && $n->getUser() === 'validUID' + && $n->getObjectType() === 'create' + && $n->getObjectId() === 'codes' + && $n->getSubject() === 'create_backupcodes'; })); $this->notificationManager->expects($this->never()) |