aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Support/Subscription
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Support/Subscription')
-rw-r--r--tests/lib/Support/Subscription/DummySubscription.php18
-rw-r--r--tests/lib/Support/Subscription/RegistryTest.php72
2 files changed, 31 insertions, 59 deletions
diff --git a/tests/lib/Support/Subscription/DummySubscription.php b/tests/lib/Support/Subscription/DummySubscription.php
index ca1644c91f5..4513bf278f6 100644
--- a/tests/lib/Support/Subscription/DummySubscription.php
+++ b/tests/lib/Support/Subscription/DummySubscription.php
@@ -9,24 +9,20 @@ declare(strict_types=1);
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 de7f7600496..e6e83d6038b 100644
--- a/tests/lib/Support/Subscription/RegistryTest.php
+++ b/tests/lib/Support/Subscription/RegistryTest.php
@@ -8,42 +8,28 @@
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();
@@ -66,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);
@@ -83,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())
@@ -99,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')
@@ -109,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())
@@ -121,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())
@@ -132,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));
@@ -142,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())
@@ -163,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')
@@ -172,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],
@@ -182,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')
@@ -198,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);