diff options
Diffstat (limited to 'tests/lib/Support')
-rw-r--r-- | tests/lib/Support/CrashReport/RegistryTest.php | 52 | ||||
-rw-r--r-- | tests/lib/Support/Subscription/DummySubscription.php | 37 | ||||
-rw-r--r-- | tests/lib/Support/Subscription/RegistryTest.php | 91 |
3 files changed, 47 insertions, 133 deletions
diff --git a/tests/lib/Support/CrashReport/RegistryTest.php b/tests/lib/Support/CrashReport/RegistryTest.php index 9424738cd70..adf7579b202 100644 --- a/tests/lib/Support/CrashReport/RegistryTest.php +++ b/tests/lib/Support/CrashReport/RegistryTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author 2017 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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Support\CrashReport; @@ -29,27 +12,18 @@ namespace Test\Support\CrashReport; use Exception; use OC\Support\CrashReport\Registry; use OCP\AppFramework\QueryException; -use OCP\IServerContainer; use OCP\Support\CrashReport\ICollectBreadcrumbs; use OCP\Support\CrashReport\IMessageReporter; use OCP\Support\CrashReport\IReporter; use Test\TestCase; class RegistryTest extends TestCase { - /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */ - private $serverContainer; - - /** @var Registry */ - private $registry; + private Registry $registry; protected function setUp(): void { parent::setUp(); - $this->serverContainer = $this->createMock(IServerContainer::class); - - $this->registry = new Registry( - $this->serverContainer - ); + $this->registry = new Registry(); } /** @@ -62,13 +36,10 @@ class RegistryTest extends TestCase { $this->addToAssertionCount(1); } - public function testRegisterLazyCantLoad(): void { + public function testRegisterLazy(): void { $reporterClass = '\OCA\MyApp\Reporter'; $reporter = $this->createMock(IReporter::class); - $this->serverContainer->expects($this->once()) - ->method('query') - ->with($reporterClass) - ->willReturn($reporter); + $this->overwriteService($reporterClass, $reporter); $reporter->expects($this->once()) ->method('report'); $exception = new Exception('test'); @@ -77,16 +48,17 @@ class RegistryTest extends TestCase { $this->registry->delegateReport($exception); } - public function testRegisterLazy(): void { + /** + * Doesn't assert anything, just checks whether anything "explodes" + */ + public function testRegisterLazyCantLoad(): void { $reporterClass = '\OCA\MyApp\Reporter'; - $this->serverContainer->expects($this->once()) - ->method('query') - ->with($reporterClass) - ->willThrowException(new QueryException()); + /* We do not register reporterClass in DI, so it will throw a QueryException queried */ $exception = new Exception('test'); $this->registry->registerLazy($reporterClass); $this->registry->delegateReport($exception); + $this->addToAssertionCount(1); } public function testDelegateBreadcrumbCollection(): void { diff --git a/tests/lib/Support/Subscription/DummySubscription.php b/tests/lib/Support/Subscription/DummySubscription.php index dfbee2e9a5e..4513bf278f6 100644 --- a/tests/lib/Support/Subscription/DummySubscription.php +++ b/tests/lib/Support/Subscription/DummySubscription.php @@ -3,45 +3,26 @@ declare(strict_types=1); /** - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * - * @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: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Support\Subscription; -class DummySubscription implements \OCP\Support\Subscription\ISubscription { - /** @var bool */ - private $hasValidSubscription; - /** @var bool */ - private $hasExtendedSupport; - /** @var bool */ - private $isHardUserLimitReached; +use OCP\Support\Subscription\ISubscription; +class DummySubscription implements ISubscription { /** * DummySubscription constructor. * * @param bool $hasValidSubscription * @param bool $hasExtendedSupport */ - public function __construct(bool $hasValidSubscription, bool $hasExtendedSupport, bool $isHardUserLimitReached) { - $this->hasValidSubscription = $hasValidSubscription; - $this->hasExtendedSupport = $hasExtendedSupport; - $this->isHardUserLimitReached = $isHardUserLimitReached; + public function __construct( + private bool $hasValidSubscription, + private bool $hasExtendedSupport, + private bool $isHardUserLimitReached, + ) { } /** diff --git a/tests/lib/Support/Subscription/RegistryTest.php b/tests/lib/Support/Subscription/RegistryTest.php index 2a6d5e5569f..e6e83d6038b 100644 --- a/tests/lib/Support/Subscription/RegistryTest.php +++ b/tests/lib/Support/Subscription/RegistryTest.php @@ -1,64 +1,35 @@ <?php /** - * @author Morris Jobke <hey@morrisjobke.de> - * - * @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 Test\Support\Subscription; use OC\Support\Subscription\Registry; -use OC\User\Database; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IServerContainer; use OCP\IUserManager; use OCP\Notification\IManager; +use OCP\Support\Subscription\Exception\AlreadyRegisteredException; use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISupportedApps; -use OCP\User\Backend\ICountUsersBackend; -use OCP\UserInterface; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; class RegistryTest extends TestCase { - /** @var Registry */ - private $registry; + private Registry $registry; - /** @var MockObject|IConfig */ - private $config; - - /** @var MockObject|IServerContainer */ - private $serverContainer; - - /** @var MockObject|IUserManager */ - private $userManager; - - /** @var MockObject|IGroupManager */ - private $groupManager; - - /** @var MockObject|LoggerInterface */ - private $logger; - - /** @var MockObject|IManager */ - private $notificationManager; + private MockObject&IConfig $config; + private MockObject&IServerContainer $serverContainer; + private MockObject&IUserManager $userManager; + private MockObject&IGroupManager $groupManager; + private MockObject&LoggerInterface $logger; + private MockObject&IManager $notificationManager; protected function setUp(): void { parent::setUp(); @@ -81,14 +52,14 @@ class RegistryTest extends TestCase { /** * Doesn't assert anything, just checks whether anything "explodes" */ - public function testDelegateToNone() { + public function testDelegateToNone(): void { $this->registry->delegateHasValidSubscription(); $this->addToAssertionCount(1); } - public function testDoubleRegistration() { - $this->expectException(\OCP\Support\Subscription\Exception\AlreadyRegisteredException::class); + public function testDoubleRegistration(): void { + $this->expectException(AlreadyRegisteredException::class); /* @var ISubscription $subscription1 */ $subscription1 = $this->createMock(ISubscription::class); @@ -98,12 +69,12 @@ class RegistryTest extends TestCase { $this->registry->register($subscription2); } - public function testNoSupportApp() { + public function testNoSupportApp(): void { $this->assertSame([], $this->registry->delegateGetSupportedApps()); $this->assertSame(false, $this->registry->delegateHasValidSubscription()); } - public function testDelegateHasValidSubscription() { + public function testDelegateHasValidSubscription(): void { /* @var ISubscription|\PHPUnit\Framework\MockObject\MockObject $subscription */ $subscription = $this->createMock(ISubscription::class); $subscription->expects($this->once()) @@ -114,7 +85,7 @@ class RegistryTest extends TestCase { $this->assertSame(true, $this->registry->delegateHasValidSubscription()); } - public function testDelegateHasValidSubscriptionConfig() { + public function testDelegateHasValidSubscriptionConfig(): void { /* @var ISubscription|\PHPUnit\Framework\MockObject\MockObject $subscription */ $this->config->expects($this->once()) ->method('getSystemValueBool') @@ -124,7 +95,7 @@ class RegistryTest extends TestCase { $this->assertSame(true, $this->registry->delegateHasValidSubscription()); } - public function testDelegateHasExtendedSupport() { + public function testDelegateHasExtendedSupport(): void { /* @var ISubscription|\PHPUnit\Framework\MockObject\MockObject $subscription */ $subscription = $this->createMock(ISubscription::class); $subscription->expects($this->once()) @@ -136,7 +107,7 @@ class RegistryTest extends TestCase { } - public function testDelegateGetSupportedApps() { + public function testDelegateGetSupportedApps(): void { /* @var ISupportedApps|\PHPUnit\Framework\MockObject\MockObject $subscription */ $subscription = $this->createMock(ISupportedApps::class); $subscription->expects($this->once()) @@ -147,7 +118,7 @@ class RegistryTest extends TestCase { $this->assertSame(['abc'], $this->registry->delegateGetSupportedApps()); } - public function testSubscriptionService() { + public function testSubscriptionService(): void { $this->serverContainer->method('query') ->with(DummySubscription::class) ->willReturn(new DummySubscription(true, false, false)); @@ -157,7 +128,7 @@ class RegistryTest extends TestCase { $this->assertFalse($this->registry->delegateHasExtendedSupport()); } - public function testDelegateIsHardUserLimitReached() { + public function testDelegateIsHardUserLimitReached(): void { /* @var ISubscription|\PHPUnit\Framework\MockObject\MockObject $subscription */ $subscription = $this->createMock(ISubscription::class); $subscription->expects($this->once()) @@ -178,7 +149,7 @@ class RegistryTest extends TestCase { $this->assertSame(true, $this->registry->delegateIsHardUserLimitReached($this->notificationManager)); } - public function testDelegateIsHardUserLimitReachedWithoutSupportApp() { + public function testDelegateIsHardUserLimitReachedWithoutSupportApp(): void { $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('one-click-instance') @@ -187,7 +158,7 @@ class RegistryTest extends TestCase { $this->assertSame(false, $this->registry->delegateIsHardUserLimitReached($this->notificationManager)); } - public function dataForUserLimitCheck() { + public static function dataForUserLimitCheck(): array { return [ // $userLimit, $userCount, $disabledUsers, $expectedResult [35, 15, 2, false], @@ -197,10 +168,8 @@ class RegistryTest extends TestCase { ]; } - /** - * @dataProvider dataForUserLimitCheck - */ - public function testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount($userLimit, $userCount, $disabledUsers, $expectedResult) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataForUserLimitCheck')] + public function testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount($userLimit, $userCount, $disabledUsers, $expectedResult): void { $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('one-click-instance') @@ -213,17 +182,9 @@ class RegistryTest extends TestCase { ->method('getUsersForUserValue') ->with('core', 'enabled', 'false') ->willReturn(array_fill(0, $disabledUsers, '')); - /* @var UserInterface|ICountUsersBackend|\PHPUnit\Framework\MockObject\MockObject $dummyBackend */ - $dummyBackend = $this->createMock(Database::class); - $dummyBackend->expects($this->once()) - ->method('implementsActions') - ->willReturn(true); - $dummyBackend->expects($this->once()) - ->method('countUsers') - ->willReturn($userCount); $this->userManager->expects($this->once()) - ->method('getBackends') - ->willReturn([$dummyBackend]); + ->method('countUsersTotal') + ->willReturn($userCount); if ($expectedResult) { $dummyGroup = $this->createMock(IGroup::class); |