aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Support')
-rw-r--r--tests/lib/Support/CrashReport/RegistryTest.php31
-rw-r--r--tests/lib/Support/Subscription/DummySubscription.php18
-rw-r--r--tests/lib/Support/Subscription/RegistryTest.php50
3 files changed, 30 insertions, 69 deletions
diff --git a/tests/lib/Support/CrashReport/RegistryTest.php b/tests/lib/Support/CrashReport/RegistryTest.php
index b65c21b759e..adf7579b202 100644
--- a/tests/lib/Support/CrashReport/RegistryTest.php
+++ b/tests/lib/Support/CrashReport/RegistryTest.php
@@ -12,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();
}
/**
@@ -45,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');
@@ -60,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 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 869c1498c41..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();
@@ -73,7 +59,7 @@ class RegistryTest extends TestCase {
public function testDoubleRegistration(): void {
- $this->expectException(\OCP\Support\Subscription\Exception\AlreadyRegisteredException::class);
+ $this->expectException(AlreadyRegisteredException::class);
/* @var ISubscription $subscription1 */
$subscription1 = $this->createMock(ISubscription::class);
@@ -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,9 +168,7 @@ class RegistryTest extends TestCase {
];
}
- /**
- * @dataProvider dataForUserLimitCheck
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataForUserLimitCheck')]
public function testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount($userLimit, $userCount, $disabledUsers, $expectedResult): void {
$this->config->expects($this->once())
->method('getSystemValueBool')
@@ -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);