diff options
Diffstat (limited to 'apps/twofactor_backupcodes/tests/Unit')
14 files changed, 181 insertions, 507 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php b/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php index 0ff833280db..152ff80194a 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php @@ -3,53 +3,26 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity; -use InvalidArgumentException; use OCA\TwoFactorBackupCodes\Activity\Provider; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; 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(); @@ -61,27 +34,25 @@ class ProviderTest extends TestCase { $this->provider = new Provider($this->l10n, $this->urlGenerator, $this->activityManager); } - public function testParseUnrelated() { + public function testParseUnrelated(): void { $lang = 'ru'; $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getApp') ->willReturn('comments'); - $this->expectException(InvalidArgumentException::class); + $this->expectException(UnknownActivityException::class); $this->provider->parse($lang, $event); } - public function subjectData() { + public static function subjectData(): array { return [ ['codes_generated'], ]; } - /** - * @dataProvider subjectData - */ - public function testParse($subject) { + #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')] + public function testParse(string $subject): void { $lang = 'ru'; $event = $this->createMock(IEvent::class); $l = $this->createMock(IL10N::class); @@ -113,7 +84,7 @@ class ProviderTest extends TestCase { $this->provider->parse($lang, $event); } - public function testParseInvalidSubject() { + public function testParseInvalidSubject(): void { $lang = 'ru'; $l = $this->createMock(IL10N::class); $event = $this->createMock(IEvent::class); @@ -129,7 +100,7 @@ class ProviderTest extends TestCase { ->method('getSubject') ->willReturn('unrelated'); - $this->expectException(InvalidArgumentException::class); + $this->expectException(UnknownActivityException::class); $this->provider->parse($lang, $event); } } 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()) diff --git a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php index 15b25f3915c..02c42b65148 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php @@ -3,28 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Controller; @@ -34,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() { - $user = $this->getMockBuilder(IUser::class)->getMock(); + public function testCreateCodes(): void { + $user = $this->createMock(IUser::class); $codes = ['a', 'b']; $this->userSession->expects($this->once()) diff --git a/apps/twofactor_backupcodes/tests/Unit/Event/CodesGeneratedTest.php b/apps/twofactor_backupcodes/tests/Unit/Event/CodesGeneratedTest.php index c75a2c034c5..3f619e387e9 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Event/CodesGeneratedTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Event/CodesGeneratedTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Event; @@ -30,7 +13,7 @@ use OCP\IUser; use Test\TestCase; class CodesGeneratedTest extends TestCase { - public function testCodeGeneratedEvent() { + public function testCodeGeneratedEvent(): void { $user = $this->createMock(IUser::class); $event = new CodesGenerated($user); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php index 68fb89907f8..bd944dc2396 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Listener; @@ -38,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(); @@ -56,7 +32,7 @@ class ActivityPublisherTest extends TestCase { $this->listener = new ActivityPublisher($this->activityManager, $this->logger); } - public function testHandleGenericEvent() { + public function testHandleGenericEvent(): void { $event = $this->createMock(Event::class); $this->activityManager->expects($this->never()) ->method('publish'); @@ -64,7 +40,7 @@ class ActivityPublisherTest extends TestCase { $this->listener->handle($event); } - public function testHandleCodesGeneratedEvent() { + public function testHandleCodesGeneratedEvent(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('fritz'); $event = new CodesGenerated($user); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/ClearNotificationsTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/ClearNotificationsTest.php index cf9f9a6c123..229d8df05d3 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/ClearNotificationsTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/ClearNotificationsTest.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\Listener; @@ -32,27 +14,25 @@ use OCP\EventDispatcher\Event; 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(); $this->notificationManager = $this->createMock(IManager::class); $this->notificationManager->method('createNotification') - ->willReturn(\OC::$server->query(IManager::class)->createNotification()); + ->willReturn(Server::get(IManager::class)->createNotification()); $this->listener = new ClearNotifications($this->notificationManager); } - public function testHandleGenericEvent() { + public function testHandleGenericEvent(): void { $event = $this->createMock(Event::class); $this->notificationManager->expects($this->never()) ->method($this->anything()); @@ -60,7 +40,7 @@ class ClearNotificationsTest extends TestCase { $this->listener->handle($event); } - public function testHandleCodesGeneratedEvent() { + public function testHandleCodesGeneratedEvent(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('fritz'); $event = new CodesGenerated($user); @@ -68,10 +48,10 @@ class ClearNotificationsTest extends TestCase { $this->notificationManager->expects($this->once()) ->method('markProcessed') ->with($this->callback(function (INotification $n) { - return $n->getUser() === 'fritz' && - $n->getApp() === 'twofactor_backupcodes' && - $n->getObjectType() === 'create' && - $n->getObjectId() === 'codes'; + return $n->getUser() === 'fritz' + && $n->getApp() === 'twofactor_backupcodes' + && $n->getObjectType() === 'create' + && $n->getObjectId() === 'codes'; })); $this->listener->handle($event); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderDisabledTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderDisabledTest.php index 4ebd94d96bd..ea4f530cab4 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderDisabledTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderDisabledTest.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019, 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: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Listener; @@ -33,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 { @@ -49,7 +32,7 @@ class ProviderDisabledTest extends TestCase { $this->listener = new ProviderDisabled($this->registy, $this->jobList); } - public function testHandleGenericEvent() { + public function testHandleGenericEvent(): void { $event = $this->createMock(Event::class); $this->jobList->expects($this->never()) ->method($this->anything()); @@ -57,7 +40,7 @@ class ProviderDisabledTest extends TestCase { $this->listener->handle($event); } - public function testHandleStillActiveProvider() { + public function testHandleStillActiveProvider(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('myUID'); @@ -78,7 +61,7 @@ class ProviderDisabledTest extends TestCase { $this->listener->handle($event); } - public function testHandleNoActiveProvider() { + public function testHandleNoActiveProvider(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('myUID'); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderEnabledTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderEnabledTest.php index a85d6734a07..50aac6139c0 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderEnabledTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/ProviderEnabledTest.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\Listener; @@ -33,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 { @@ -49,7 +32,7 @@ class ProviderEnabledTest extends TestCase { $this->listener = new ProviderEnabled($this->registy, $this->jobList); } - public function testHandleGenericEvent() { + public function testHandleGenericEvent(): void { $event = $this->createMock(Event::class); $this->jobList->expects($this->never()) ->method($this->anything()); @@ -57,7 +40,7 @@ class ProviderEnabledTest extends TestCase { $this->listener->handle($event); } - public function testHandleCodesGeneratedEventAlraedyBackupcodes() { + public function testHandleCodesGeneratedEventAlraedyBackupcodes(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('myUID'); @@ -77,7 +60,7 @@ class ProviderEnabledTest extends TestCase { $this->listener->handle($event); } - public function testHandleCodesGeneratedEventNoBackupcodes() { + public function testHandleCodesGeneratedEventNoBackupcodes(): void { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('myUID'); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/RegistryUpdaterTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/RegistryUpdaterTest.php index da330a971b5..86d890f0d5e 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/RegistryUpdaterTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/RegistryUpdaterTest.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Listener; @@ -32,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(); @@ -54,7 +31,7 @@ class RegistryUpdaterTest extends TestCase { $this->listener = new RegistryUpdater($this->registry, $this->provider); } - public function testHandleGenericEvent() { + public function testHandleGenericEvent(): void { $event = $this->createMock(Event::class); $this->registry->expects($this->never()) ->method('enableProviderFor'); @@ -62,7 +39,7 @@ class RegistryUpdaterTest extends TestCase { $this->listener->handle($event); } - public function testHandleCodesGeneratedEvent() { + public function testHandleCodesGeneratedEvent(): void { $user = $this->createMock(IUser::class); $event = new CodesGenerated($user); $this->registry->expects($this->once()) diff --git a/apps/twofactor_backupcodes/tests/Unit/Migration/CheckBackupCodeTest.php b/apps/twofactor_backupcodes/tests/Unit/Migration/CheckBackupCodeTest.php index cad9719aed2..c68ab185116 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Migration/CheckBackupCodeTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Migration/CheckBackupCodeTest.php @@ -3,40 +3,20 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ 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(); @@ -45,11 +25,11 @@ class CheckBackupCodeTest extends TestCase { $this->checkBackupsCodes = new CheckBackupCodes($this->jobList); } - public function testGetName() { + public function testGetName(): void { $this->assertSame('Add background job to check for backup codes', $this->checkBackupsCodes->getName()); } - public function testRun() { + public function testRun(): void { $this->jobList->expects($this->once()) ->method('add') ->with( diff --git a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php index d70252b5fbc..b091d57dbd2 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php @@ -3,29 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @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\Notification; @@ -38,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(); @@ -70,10 +44,10 @@ class NotifierTest extends TestCase { } - public function testPrepareWrongApp() { + 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') @@ -85,10 +59,10 @@ class NotifierTest extends TestCase { } - public function testPrepareWrongSubject() { + 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') @@ -100,8 +74,8 @@ class NotifierTest extends TestCase { $this->notifier->prepare($notification, 'en'); } - public function testPrepare() { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + public function testPrepare(): void { + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) diff --git a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php index bb4d7f662cb..512374fca8c 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php @@ -3,76 +3,58 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Provider; use OC\App\AppManager; use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider; use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage; -use OCP\IInitialStateService; +use OCP\AppFramework\Services\IInitialState; use OCP\IL10N; use OCP\IUser; -use OCP\Template; +use OCP\Server; +use OCP\Template\ITemplateManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class BackupCodesProviderTest extends TestCase { + private string $appName; - /** @var string */ - private $appName; + private BackupCodeStorage&MockObject $storage; + private IL10N&MockObject $l10n; + private AppManager&MockObject $appManager; + private IInitialState&MockObject $initialState; - /** @var BackupCodeStorage|\PHPUnit\Framework\MockObject\MockObject */ - private $storage; - - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ - private $l10n; - - /** @var AppManager|\PHPUnit\Framework\MockObject\MockObject */ - private $appManager; - - /** @var IInitialStateService|\PHPUnit\Framework\MockObject\MockObject */ - private $initialState; - - /** @var BackupCodesProvider */ - private $provider; + private ITemplateManager $templateManager; + private BackupCodesProvider $provider; protected function setUp(): void { parent::setUp(); - $this->appName = "twofactor_backupcodes"; + $this->appName = 'twofactor_backupcodes'; $this->storage = $this->createMock(BackupCodeStorage::class); $this->l10n = $this->createMock(IL10N::class); $this->appManager = $this->createMock(AppManager::class); - $this->initialState = $this->createMock(IInitialStateService::class); - - $this->provider = new BackupCodesProvider($this->appName, $this->storage, $this->l10n, $this->appManager, $this->initialState); + $this->initialState = $this->createMock(IInitialState::class); + $this->templateManager = Server::get(ITemplateManager::class); + + $this->provider = new BackupCodesProvider( + $this->appName, + $this->storage, + $this->l10n, + $this->appManager, + $this->initialState, + $this->templateManager, + ); } - public function testGetId() { + public function testGetId(): void { $this->assertEquals('backup_codes', $this->provider->getId()); } - public function testGetDisplayName() { + public function testGetDisplayName(): void { $this->l10n->expects($this->once()) ->method('t') ->with('Backup code') @@ -80,7 +62,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertSame('l10n backup code', $this->provider->getDisplayName()); } - public function testGetDescription() { + public function testGetDescription(): void { $this->l10n->expects($this->once()) ->method('t') ->with('Use backup code') @@ -88,14 +70,14 @@ class BackupCodesProviderTest extends TestCase { $this->assertSame('l10n use backup code', $this->provider->getDescription()); } - public function testGetTempalte() { + public function testGetTempalte(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); - $expected = new Template('twofactor_backupcodes', 'challenge'); + $expected = $this->templateManager->getTemplate('twofactor_backupcodes', 'challenge'); $this->assertEquals($expected, $this->provider->getTemplate($user)); } - public function testVerfiyChallenge() { + public function testVerfiyChallenge(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $challenge = 'xyz'; @@ -107,7 +89,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertFalse($this->provider->verifyChallenge($user, $challenge)); } - public function testIsTwoFactorEnabledForUser() { + public function testIsTwoFactorEnabledForUser(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->storage->expects($this->once()) @@ -118,7 +100,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertTrue($this->provider->isTwoFactorAuthEnabledForUser($user)); } - public function testIsActiveNoProviders() { + public function testIsActiveNoProviders(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->appManager->expects($this->once()) @@ -138,7 +120,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertFalse($this->provider->isActive($user)); } - public function testIsActiveWithProviders() { + public function testIsActiveWithProviders(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->appManager->expects($this->once()) diff --git a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php index 100b70583fe..069e50b71fd 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Service; @@ -35,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(); @@ -65,7 +37,7 @@ class BackupCodeStorageTest extends TestCase { $this->storage = new BackupCodeStorage($this->mapper, $this->random, $this->hasher, $this->eventDispatcher); } - public function testCreateCodes() { + public function testCreateCodes(): void { $user = $this->createMock(IUser::class); $number = 5; $user->method('getUID')->willReturn('fritz'); @@ -97,7 +69,7 @@ class BackupCodeStorageTest extends TestCase { } } - public function testHasBackupCodes() { + public function testHasBackupCodes(): void { $user = $this->createMock(IUser::class); $codes = [ new BackupCode(), @@ -112,7 +84,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertTrue($this->storage->hasBackupCodes($user)); } - public function testHasBackupCodesNoCodes() { + public function testHasBackupCodesNoCodes(): void { $user = $this->createMock(IUser::class); $codes = []; @@ -124,7 +96,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertFalse($this->storage->hasBackupCodes($user)); } - public function testGetBackupCodeState() { + public function testGetBackupCodeState(): void { $user = $this->createMock(IUser::class); $code1 = new BackupCode(); @@ -149,7 +121,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertEquals($expected, $this->storage->getBackupCodesState($user)); } - public function testGetBackupCodeDisabled() { + public function testGetBackupCodeDisabled(): void { $user = $this->createMock(IUser::class); $codes = []; @@ -167,7 +139,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertEquals($expected, $this->storage->getBackupCodesState($user)); } - public function testValidateCode() { + public function testValidateCode(): void { $user = $this->createMock(IUser::class); $code = new BackupCode(); $code->setUsed(0); @@ -193,7 +165,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertEquals(1, $code->getUsed()); } - public function testValidateUsedCode() { + public function testValidateUsedCode(): void { $user = $this->createMock(IUser::class); $code = new BackupCode(); $code->setUsed('1'); @@ -214,7 +186,7 @@ class BackupCodeStorageTest extends TestCase { $this->assertFalse($this->storage->validateCode($user, 'CHALLENGE')); } - public function testValidateCodeWithWrongHash() { + public function testValidateCodeWithWrongHash(): void { $user = $this->createMock(IUser::class); $code = new BackupCode(); $code->setUsed(0); |