aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r--apps/provisioning_api/tests/CapabilitiesTest.php23
-rw-r--r--apps/provisioning_api/tests/Controller/AppConfigControllerTest.php91
-rw-r--r--apps/provisioning_api/tests/Controller/AppsControllerTest.php26
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php62
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php180
-rw-r--r--apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php49
6 files changed, 160 insertions, 271 deletions
diff --git a/apps/provisioning_api/tests/CapabilitiesTest.php b/apps/provisioning_api/tests/CapabilitiesTest.php
index e3c14f37ed7..86d2bb8c4fa 100644
--- a/apps/provisioning_api/tests/CapabilitiesTest.php
+++ b/apps/provisioning_api/tests/CapabilitiesTest.php
@@ -1,9 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Provisioning_API\Tests\unit;
+namespace OCA\Provisioning_API\Tests;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Provisioning_API\Capabilities;
@@ -21,11 +23,8 @@ use Test\TestCase;
*/
class CapabilitiesTest extends TestCase {
- /** @var Capabilities */
- protected $capabilities;
-
- /** @var IAppManager|MockObject */
- protected $appManager;
+ protected IAppManager&MockObject $appManager;
+ protected Capabilities $capabilities;
public function setUp(): void {
parent::setUp();
@@ -38,7 +37,7 @@ class CapabilitiesTest extends TestCase {
->willReturn('1.12');
}
- public function getCapabilitiesProvider() {
+ public static function getCapabilitiesProvider(): array {
return [
[true, false, false, true, false],
[true, true, false, true, false],
@@ -49,16 +48,14 @@ class CapabilitiesTest extends TestCase {
];
}
- /**
- * @dataProvider getCapabilitiesProvider
- */
- public function testGetCapabilities($federationAppEnabled, $federatedFileSharingAppEnabled, $lookupServerEnabled, $expectedFederatedScopeEnabled, $expectedPublishedScopeEnabled): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('getCapabilitiesProvider')]
+ public function testGetCapabilities(bool $federationAppEnabled, bool $federatedFileSharingAppEnabled, bool $lookupServerEnabled, bool $expectedFederatedScopeEnabled, bool $expectedPublishedScopeEnabled): void {
$this->appManager->expects($this->any())
->method('isEnabledForUser')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['federation', null, $federationAppEnabled],
['federatedfilesharing', null, $federatedFileSharingAppEnabled],
- ]));
+ ]);
$federatedShareProvider = $this->createMock(FederatedShareProvider::class);
$this->overwriteService(FederatedShareProvider::class, $federatedShareProvider);
diff --git a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
index 41739b6283f..1b09838cbc3 100644
--- a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -30,7 +32,6 @@ use function json_encode;
* @package OCA\Provisioning_API\Tests
*/
class AppConfigControllerTest extends TestCase {
-
private IAppConfig&MockObject $appConfig;
private IUserSession&MockObject $userSession;
private IL10N&MockObject $l10n;
@@ -51,7 +52,7 @@ class AppConfigControllerTest extends TestCase {
/**
* @param string[] $methods
- * @return AppConfigController|\PHPUnit\Framework\MockObject\MockObject
+ * @return AppConfigController|MockObject
*/
protected function getInstance(array $methods = []) {
$request = $this->createMock(IRequest::class);
@@ -79,7 +80,7 @@ class AppConfigControllerTest extends TestCase {
$this->settingManager,
$this->appManager,
])
- ->setMethods($methods)
+ ->onlyMethods($methods)
->getMock();
}
}
@@ -95,21 +96,15 @@ class AppConfigControllerTest extends TestCase {
$this->assertEquals(['data' => ['apps']], $result->getData());
}
- public function dataGetKeys() {
+ public static function dataGetKeys(): array {
return [
['app1 ', null, new \InvalidArgumentException('error'), Http::STATUS_FORBIDDEN],
['app2', ['keys'], null, Http::STATUS_OK],
];
}
- /**
- * @dataProvider dataGetKeys
- * @param string $app
- * @param array|null $keys
- * @param \Exception|null $throws
- * @param int $status
- */
- public function testGetKeys($app, $keys, $throws, $status): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetKeys')]
+ public function testGetKeys(string $app, ?array $keys, ?\Throwable $throws, int $status): void {
$api = $this->getInstance(['verifyAppId']);
if ($throws instanceof \Exception) {
$api->expects($this->once())
@@ -140,23 +135,15 @@ class AppConfigControllerTest extends TestCase {
}
}
- public function dataGetValue() {
+ public static function dataGetValue(): array {
return [
['app1', 'key', 'default', null, new \InvalidArgumentException('error'), Http::STATUS_FORBIDDEN],
['app2', 'key', 'default', 'return', null, Http::STATUS_OK],
];
}
- /**
- * @dataProvider dataGetValue
- * @param string $app
- * @param string|null $key
- * @param string|null $default
- * @param string|null $return
- * @param \Exception|null $throws
- * @param int $status
- */
- public function testGetValue($app, $key, $default, $return, $throws, $status): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetValue')]
+ public function testGetValue(string $app, string $key, string $default, ?string $return, ?\Throwable $throws, int $status): void {
$api = $this->getInstance(['verifyAppId']);
if ($throws instanceof \Exception) {
$api->expects($this->once())
@@ -184,7 +171,7 @@ class AppConfigControllerTest extends TestCase {
}
}
- public function dataSetValue() {
+ public static function dataSetValue(): array {
return [
['app1', 'key', 'default', new \InvalidArgumentException('error1'), null, Http::STATUS_FORBIDDEN],
['app2', 'key', 'default', null, new \InvalidArgumentException('error2'), Http::STATUS_FORBIDDEN],
@@ -199,16 +186,8 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataSetValue
- * @param string $app
- * @param string|null $key
- * @param string|null $value
- * @param \Exception|null $appThrows
- * @param \Exception|null $keyThrows
- * @param int|\Throwable $status
- */
- public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status, int|\Throwable $type = IAppConfig::VALUE_MIXED): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
+ public function testSetValue(string $app, string $key, string $value, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status, int|\Throwable $type = IAppConfig::VALUE_MIXED): void {
$adminUser = $this->createMock(IUser::class);
$adminUser->expects($this->once())
->method('getUid')
@@ -297,7 +276,7 @@ class AppConfigControllerTest extends TestCase {
}
}
- public function dataDeleteValue() {
+ public static function dataDeleteValue(): array {
return [
['app1', 'key', new \InvalidArgumentException('error1'), null, Http::STATUS_FORBIDDEN],
['app2', 'key', null, new \InvalidArgumentException('error2'), Http::STATUS_FORBIDDEN],
@@ -305,15 +284,8 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataDeleteValue
- * @param string $app
- * @param string|null $key
- * @param \Exception|null $appThrows
- * @param \Exception|null $keyThrows
- * @param int $status
- */
- public function testDeleteValue($app, $key, $appThrows, $keyThrows, $status): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteValue')]
+ public function testDeleteValue(string $app, string $key, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status): void {
$api = $this->getInstance(['verifyAppId', 'verifyConfigKey']);
if ($appThrows instanceof \Exception) {
$api->expects($this->once())
@@ -367,7 +339,7 @@ class AppConfigControllerTest extends TestCase {
$this->addToAssertionCount(1);
}
- public function dataVerifyAppIdThrows() {
+ public static function dataVerifyAppIdThrows(): array {
return [
['activity..'],
['activity/'],
@@ -376,18 +348,15 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyAppIdThrows
- * @param string $app
- */
- public function testVerifyAppIdThrows($app): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyAppIdThrows')]
+ public function testVerifyAppIdThrows(string $app): void {
$this->expectException(\InvalidArgumentException::class);
$api = $this->getInstance();
$this->invokePrivate($api, 'verifyAppId', [$app]);
}
- public function dataVerifyConfigKey() {
+ public static function dataVerifyConfigKey(): array {
return [
['activity', 'abc', ''],
['dav', 'public_route', ''],
@@ -396,19 +365,14 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyConfigKey
- * @param string $app
- * @param string $key
- * @param string $value
- */
- public function testVerifyConfigKey($app, $key, $value): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyConfigKey')]
+ public function testVerifyConfigKey(string $app, string $key, string $value): void {
$api = $this->getInstance();
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key, $value]);
$this->addToAssertionCount(1);
}
- public function dataVerifyConfigKeyThrows() {
+ public static function dataVerifyConfigKeyThrows(): array {
return [
['activity', 'installed_version', ''],
['calendar', 'enabled', ''],
@@ -422,13 +386,8 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyConfigKeyThrows
- * @param string $app
- * @param string $key
- * @param string $value
- */
- public function testVerifyConfigKeyThrows($app, $key, $value): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyConfigKeyThrows')]
+ public function testVerifyConfigKeyThrows(string $app, string $key, string $value): void {
$this->expectException(\InvalidArgumentException::class);
$api = $this->getInstance();
diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
index bbcabfddd8b..f95daeae7d3 100644
--- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
@@ -7,14 +7,17 @@
*/
namespace OCA\Provisioning_API\Tests\Controller;
+use OC\Installer;
use OCA\Provisioning_API\Controller\AppsController;
use OCA\Provisioning_API\Tests\TestCase;
use OCP\App\IAppManager;
use OCP\AppFramework\OCS\OCSException;
+use OCP\IAppConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class AppsTest
@@ -24,12 +27,11 @@ use OCP\Server;
* @package OCA\Provisioning_API\Tests
*/
class AppsControllerTest extends TestCase {
- /** @var IAppManager */
- private $appManager;
- /** @var AppsController */
- private $api;
- /** @var IUserSession */
- private $userSession;
+ private IAppManager $appManager;
+ private IAppConfig&MockObject $appConfig;
+ private Installer&MockObject $installer;
+ private AppsController $api;
+ private IUserSession $userSession;
protected function setUp(): void {
parent::setUp();
@@ -37,15 +39,17 @@ class AppsControllerTest extends TestCase {
$this->appManager = Server::get(IAppManager::class);
$this->groupManager = Server::get(IGroupManager::class);
$this->userSession = Server::get(IUserSession::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->installer = $this->createMock(Installer::class);
- $request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(IRequest::class);
$this->api = new AppsController(
'provisioning_api',
$request,
- $this->appManager
+ $this->appManager,
+ $this->installer,
+ $this->appConfig,
);
}
@@ -96,7 +100,7 @@ class AppsControllerTest extends TestCase {
$this->assertEquals(count($disabled), count($data['apps']));
}
-
+
public function testGetAppsInvalidFilter(): void {
$this->expectException(OCSException::class);
$this->expectExceptionCode(101);
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index 29b098429e8..85e5d733b1f 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -22,30 +22,20 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\UserInterface;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class GroupsControllerTest extends \Test\TestCase {
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- protected $request;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
- protected $groupManager;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $userSession;
- /** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $accountManager;
- /** @var ISubAdmin|\PHPUnit\Framework\MockObject\MockObject */
- protected $subAdminManager;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $l10nFactory;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
-
- /** @var GroupsController|\PHPUnit\Framework\MockObject\MockObject */
- protected $api;
+ protected IRequest&MockObject $request;
+ protected IUserManager&MockObject $userManager;
+ protected IConfig&MockObject $config;
+ protected Manager&MockObject $groupManager;
+ protected IUserSession&MockObject $userSession;
+ protected IAccountManager&MockObject $accountManager;
+ protected ISubAdmin&MockObject $subAdminManager;
+ protected IFactory&MockObject $l10nFactory;
+ protected LoggerInterface&MockObject $logger;
+ protected GroupsController&MockObject $api;
private IRootFolder $rootFolder;
@@ -82,16 +72,12 @@ class GroupsControllerTest extends \Test\TestCase {
$this->rootFolder,
$this->logger
])
- ->setMethods(['fillStorageInfo'])
+ ->onlyMethods(['fillStorageInfo'])
->getMock();
}
- /**
- * @param string $gid
- * @return IGroup|\PHPUnit\Framework\MockObject\MockObject
- */
- private function createGroup($gid) {
- $group = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
+ private function createGroup(string $gid): IGroup&MockObject {
+ $group = $this->createMock(IGroup::class);
$group
->method('getGID')
->willReturn($gid);
@@ -116,7 +102,7 @@ class GroupsControllerTest extends \Test\TestCase {
/**
* @param string $uid
- * @return IUser|\PHPUnit\Framework\MockObject\MockObject
+ * @return IUser&MockObject
*/
private function createUser($uid) {
$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
@@ -165,7 +151,7 @@ class GroupsControllerTest extends \Test\TestCase {
});
}
- public function dataGetGroups() {
+ public static function dataGetGroups(): array {
return [
[null, 0, 0],
['foo', 0, 0],
@@ -175,14 +161,8 @@ class GroupsControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetGroups
- *
- * @param string|null $search
- * @param int|null $limit
- * @param int|null $offset
- */
- public function testGetGroups($search, $limit, $offset): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
+ public function testGetGroups(?string $search, int $limit, int $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
$search = $search === null ? '' : $search;
@@ -198,12 +178,12 @@ class GroupsControllerTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetGroups
*
* @param string|null $search
* @param int|null $limit
* @param int|null $offset
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
public function testGetGroupsDetails($search, $limit, $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
@@ -509,7 +489,7 @@ class GroupsControllerTest extends \Test\TestCase {
->method('getUserGroups')
->willReturn([$group]);
- /** @var \PHPUnit\Framework\MockObject\MockObject */
+ /** @var MockObject */
$this->subAdminManager->expects($this->any())
->method('isSubAdminOfGroup')
->willReturn(false);
@@ -554,7 +534,7 @@ class GroupsControllerTest extends \Test\TestCase {
->method('getUserGroups')
->willReturn([$group]);
- /** @var \PHPUnit\Framework\MockObject\MockObject */
+ /** @var MockObject */
$this->subAdminManager->expects($this->any())
->method('isSubAdminOfGroup')
->willReturn(false);
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 7d4f99356b3..cf35a4fb324 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -20,6 +20,7 @@ use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;
+use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\EventDispatcher\IEventDispatcher;
@@ -46,41 +47,25 @@ use RuntimeException;
use Test\TestCase;
class UsersControllerTest extends TestCase {
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var IConfig|MockObject */
- protected $config;
- /** @var Manager|MockObject */
- protected $groupManager;
- /** @var IUserSession|MockObject */
- protected $userSession;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var UsersController|MockObject */
- protected $api;
- /** @var IAccountManager|MockObject */
- protected $accountManager;
- /** @var ISubAdmin|MockObject */
- protected $subAdminManager;
- /** @var IURLGenerator|MockObject */
- protected $urlGenerator;
- /** @var IRequest|MockObject */
- protected $request;
- /** @var IFactory|MockObject */
- private $l10nFactory;
- /** @var NewUserMailHelper|MockObject */
- private $newUserMailHelper;
- /** @var ISecureRandom|MockObject */
- private $secureRandom;
- /** @var RemoteWipe|MockObject */
- private $remoteWipe;
- /** @var KnownUserService|MockObject */
- private $knownUserService;
- /** @var IEventDispatcher|MockObject */
- private $eventDispatcher;
+ protected IUserManager&MockObject $userManager;
+ protected IConfig&MockObject $config;
+ protected Manager&MockObject $groupManager;
+ protected IUserSession&MockObject $userSession;
+ protected LoggerInterface&MockObject $logger;
+ protected UsersController&MockObject $api;
+ protected IAccountManager&MockObject $accountManager;
+ protected ISubAdmin&MockObject $subAdminManager;
+ protected IURLGenerator&MockObject $urlGenerator;
+ protected IRequest&MockObject $request;
+ private IFactory&MockObject $l10nFactory;
+ private NewUserMailHelper&MockObject $newUserMailHelper;
+ private ISecureRandom&MockObject $secureRandom;
+ private RemoteWipe&MockObject $remoteWipe;
+ private KnownUserService&MockObject $knownUserService;
+ private IEventDispatcher&MockObject $eventDispatcher;
private IRootFolder $rootFolder;
- /** @var IPhoneNumberUtil */
- private $phoneNumberUtil;
+ private IPhoneNumberUtil $phoneNumberUtil;
+ private IAppManager $appManager;
protected function setUp(): void {
parent::setUp();
@@ -101,6 +86,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService = $this->createMock(KnownUserService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->phoneNumberUtil = new PhoneNumberUtil();
+ $this->appManager = $this->createMock(IAppManager::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$l10n = $this->createMock(IL10N::class);
@@ -127,6 +113,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['fillStorageInfo'])
->getMock();
@@ -212,8 +199,7 @@ class UsersControllerTest extends TestCase {
->willReturn($subAdminManager);
$this->groupManager
->expects($this->any())
- ->method('displayNamesInGroup')
- ->will($this->onConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]));
+ ->method('displayNamesInGroup')->willReturnOnConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]);
$expected = [
'users' => [
@@ -449,10 +435,6 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(2))
->method('groupExists')
- ->withConsecutive(
- ['ExistingGroup'],
- ['NonExistingGroup']
- )
->willReturnMap([
['ExistingGroup', true],
['NonExistingGroup', false]
@@ -522,6 +504,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['editUser'])
->getMock();
@@ -798,18 +781,20 @@ class UsersControllerTest extends TestCase {
->method('get')
->with('ExistingGroup')
->willReturn($group);
+
+ $calls = [
+ ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']],
+ ];
$this->logger
->expects($this->exactly(2))
->method('info')
- ->withConsecutive(
- ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
- $this->assertTrue(key_exists(
- 'id',
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData()
- ));
+ $this->assertArrayHasKey('id', $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
}
@@ -828,7 +813,7 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser')
- ->will($this->throwException($exception));
+ ->willThrowException($exception);
$this->logger
->expects($this->once())
->method('error')
@@ -966,11 +951,10 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(2))
->method('groupExists')
- ->withConsecutive(
- ['ExistingGroup1'],
- ['ExistingGroup2']
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['ExistingGroup1', true],
+ ['ExistingGroup2', true]
+ ]);
$user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
@@ -996,24 +980,23 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(4))
->method('get')
- ->withConsecutive(
- ['ExistingGroup1'],
- ['ExistingGroup2'],
- ['ExistingGroup1'],
- ['ExistingGroup2']
- )
->willReturnMap([
['ExistingGroup1', $existingGroup1],
['ExistingGroup2', $existingGroup2]
]);
+
+ $calls = [
+ ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']],
+ ];
$this->logger
->expects($this->exactly(3))
->method('info')
- ->withConsecutive(
- ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
->disableOriginalConstructor()->getMock();
$this->groupManager
@@ -1023,16 +1006,12 @@ class UsersControllerTest extends TestCase {
$subAdminManager
->expects($this->exactly(2))
->method('isSubAdminOfGroup')
- ->withConsecutive(
- [$loggedInUser, $existingGroup1],
- [$loggedInUser, $existingGroup2]
- )
- ->willReturn(true);
+ ->willReturnMap([
+ [$loggedInUser, $existingGroup1, true],
+ [$loggedInUser, $existingGroup2, true],
+ ]);
- $this->assertTrue(key_exists(
- 'id',
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()
- ));
+ $this->assertArrayHasKey('id', $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
}
@@ -1541,7 +1520,7 @@ class UsersControllerTest extends TestCase {
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
- public function dataSearchByPhoneNumbers(): array {
+ public static function dataSearchByPhoneNumbers(): array {
return [
'Invalid country' => ['Not a country code', ['12345' => ['NaN']], 400, null, null, []],
'No number to search' => ['DE', ['12345' => ['NaN']], 200, null, null, []],
@@ -1554,13 +1533,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataSearchByPhoneNumbers
- * @param string $location
- * @param array $search
- * @param int $status
- * @param array $expected
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchByPhoneNumbers')]
public function testSearchByPhoneNumbers(string $location, array $search, int $status, ?array $searchUsers, ?array $userMatches, array $expected): void {
$knownTo = 'knownTo';
$user = $this->createMock(IUser::class);
@@ -1870,7 +1843,7 @@ class UsersControllerTest extends TestCase {
$this->api->editUser('UserToEdit', 'email', 'demo.org');
}
- public function selfEditChangePropertyProvider() {
+ public static function selfEditChangePropertyProvider(): array {
return [
[IAccountManager::PROPERTY_TWITTER, '@oldtwitter', '@newtwitter'],
[IAccountManager::PROPERTY_FEDIVERSE, '@oldFediverse@floss.social', '@newFediverse@floss.social'],
@@ -1886,9 +1859,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider selfEditChangePropertyProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('selfEditChangePropertyProvider')]
public function testEditUserRegularUserSelfEditChangeProperty($propertyName, $oldValue, $newValue): void {
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
@@ -1964,9 +1935,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider selfEditChangePropertyProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('selfEditChangePropertyProvider')]
public function testEditUserRegularUserSelfEditChangePropertyScope($propertyName, $oldScope, $newScope): void {
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
@@ -2294,16 +2263,14 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
}
- public function dataEditUserSelfEditChangeLanguageButForced() {
+ public static function dataEditUserSelfEditChangeLanguageButForced(): array {
return [
['de'],
[true],
];
}
- /**
- * @dataProvider dataEditUserSelfEditChangeLanguageButForced
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserSelfEditChangeLanguageButForced($forced): void {
$this->expectException(OCSException::class);
@@ -2397,9 +2364,7 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
}
- /**
- * @dataProvider dataEditUserSelfEditChangeLanguageButForced
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserAdminEditChangeLanguageInvalidLanguage(): void {
$this->expectException(OCSException::class);
@@ -3825,6 +3790,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -3916,6 +3882,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -3942,11 +3909,10 @@ class UsersControllerTest extends TestCase {
$api->expects($this->exactly(2))
->method('getUserData')
- ->withConsecutive(
- ['uid', false],
- ['currentuser', true],
- )
- ->willReturn($expected);
+ ->willReturnMap([
+ ['uid', false, $expected],
+ ['currentuser', true, $expected],
+ ]);
$this->assertSame($expected, $api->getUser('uid')->getData());
@@ -4263,7 +4229,7 @@ class UsersControllerTest extends TestCase {
}
- public function dataGetEditableFields() {
+ public static function dataGetEditableFields(): array {
return [
[false, true, ISetDisplayNameBackend::class, [
IAccountManager::PROPERTY_EMAIL,
@@ -4386,13 +4352,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetEditableFields
- *
- * @param bool $allowedToChangeDisplayName
- * @param string $userBackend
- * @param array $expected
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetEditableFields')]
public function testGetEditableFields(bool $allowedToChangeDisplayName, bool $allowedToChangeEmail, string $userBackend, array $expected): void {
$this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => match ($key) {
'allow_user_to_change_display_name' => $allowedToChangeDisplayName,
@@ -4427,7 +4387,7 @@ class UsersControllerTest extends TestCase {
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
- ->will($this->returnValueMap($mockedProperties));
+ ->willReturnMap($mockedProperties);
$this->accountManager->expects($this->any())->method('getAccount')
->with($targetUser)
diff --git a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
index d097febb04f..c027e518a3d 100644
--- a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
+++ b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -24,34 +25,27 @@ class ProvisioningApiMiddlewareTest extends TestCase {
$this->reflector = $this->createMock(IControllerMethodReflector::class);
}
- public function dataAnnotation() {
+ public static function dataAnnotation(): array {
return [
[false, false, false, false, false],
- [false, false, true, false, false],
- [false, true, true, false, false],
- [ true, false, false, false, true],
- [ true, false, true, false, false],
- [ true, true, false, false, false],
- [ true, true, true, false, false],
+ [false, false, true, false, false],
+ [false, true, true, false, false],
+ [true, false, false, false, true],
+ [true, false, true, false, false],
+ [true, true, false, false, false],
+ [true, true, true, false, false],
[false, false, false, true, false],
- [false, false, true, true, false],
- [false, true, true, true, false],
- [ true, false, false, true, false],
- [ true, false, true, true, false],
- [ true, true, false, true, false],
- [ true, true, true, true, false],
+ [false, false, true, true, false],
+ [false, true, true, true, false],
+ [true, false, false, true, false],
+ [true, false, true, true, false],
+ [true, true, false, true, false],
+ [true, true, true, true, false],
];
}
- /**
- * @dataProvider dataAnnotation
- *
- * @param bool $subadminRequired
- * @param bool $isAdmin
- * @param bool $isSubAdmin
- * @param bool $shouldThrowException
- */
- public function testBeforeController($subadminRequired, $isAdmin, $isSubAdmin, $hasSettingAuthorizationAnnotation, $shouldThrowException): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAnnotation')]
+ public function testBeforeController(bool $subadminRequired, bool $isAdmin, bool $isSubAdmin, bool $hasSettingAuthorizationAnnotation, bool $shouldThrowException): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,
$isAdmin,
@@ -80,20 +74,15 @@ class ProvisioningApiMiddlewareTest extends TestCase {
}
}
- public function dataAfterException() {
+ public static function dataAfterException(): array {
return [
[new NotSubAdminException(), false],
[new \Exception('test', 42), true],
];
}
- /**
- * @dataProvider dataAfterException
- *
- * @param \Exception $e
- * @param bool $forwared
- */
- public function testAfterException(\Exception $exception, $forwared): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterException')]
+ public function testAfterException(\Exception $exception, bool $forwared): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,
false,