aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2025-05-28 09:50:46 +0200
committerJoas Schilling <coding@schilljs.com>2025-05-28 10:10:45 +0200
commit6c7f8ea55ba256fae2a380aa1649b16c7aeca638 (patch)
treeb6b06416ee993564d96f1f0f5a8d5d857fdc1e87
parent56f3d1989e6d2c28a437cc33850d95fb768d3996 (diff)
downloadnextcloud-server-tests/noid/ldap.tar.gz
nextcloud-server-tests/noid/ldap.zip
test: Migrate User LDAP to phpunit 10tests/noid/ldap
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/user_ldap/tests/AccessTest.php111
-rw-r--r--apps/user_ldap/tests/ConfigurationTest.php14
-rw-r--r--apps/user_ldap/tests/ConnectionTest.php13
-rw-r--r--apps/user_ldap/tests/GroupLDAPPluginTest.php40
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php85
-rw-r--r--apps/user_ldap/tests/HelperTest.php10
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php2
-rw-r--r--apps/user_ldap/tests/Jobs/CleanUpTest.php9
-rw-r--r--apps/user_ldap/tests/Jobs/SyncTest.php101
-rw-r--r--apps/user_ldap/tests/LDAPGroupPluginDummy.php2
-rw-r--r--apps/user_ldap/tests/LDAPProviderTest.php306
-rw-r--r--apps/user_ldap/tests/LDAPTest.php12
-rw-r--r--apps/user_ldap/tests/LDAPUserPluginDummy.php10
-rw-r--r--apps/user_ldap/tests/Mapping/AbstractMappingTestCase.php (renamed from apps/user_ldap/tests/Mapping/AbstractMappingTest.php)33
-rw-r--r--apps/user_ldap/tests/Mapping/GroupMappingTest.php3
-rw-r--r--apps/user_ldap/tests/Mapping/UserMappingTest.php3
-rw-r--r--apps/user_ldap/tests/Migration/AbstractUUIDFixTestCase.php (renamed from apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php)41
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixGroupTest.php7
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixInsertTest.php48
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixUserTest.php4
-rw-r--r--apps/user_ldap/tests/Service/BirthdateParserServiceTest.php5
-rw-r--r--apps/user_ldap/tests/Service/UpdateGroupsServiceTest.php31
-rw-r--r--apps/user_ldap/tests/Settings/AdminTest.php8
-rw-r--r--apps/user_ldap/tests/Settings/SectionTest.php12
-rw-r--r--apps/user_ldap/tests/User/DeletedUsersIndexTest.php21
-rw-r--r--apps/user_ldap/tests/User/ManagerTest.php60
-rw-r--r--apps/user_ldap/tests/User/OfflineUserTest.php19
-rw-r--r--apps/user_ldap/tests/User/UserTest.php66
-rw-r--r--apps/user_ldap/tests/UserLDAPPluginTest.php64
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php79
-rw-r--r--apps/user_ldap/tests/User_ProxyTest.php28
-rw-r--r--apps/user_ldap/tests/WizardTest.php21
32 files changed, 606 insertions, 662 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index dba6e5480d5..86ce2aff854 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -41,36 +43,25 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class AccessTest extends TestCase {
- /** @var UserMapping|MockObject */
- protected $userMapper;
- /** @var IManager|MockObject */
- protected $shareManager;
- /** @var GroupMapping|MockObject */
- protected $groupMapper;
- /** @var Connection|MockObject */
- private $connection;
- /** @var LDAP|MockObject */
- private $ldap;
- /** @var Manager|MockObject */
- private $userManager;
- /** @var Helper|MockObject */
- private $helper;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IUserManager|MockObject */
- private $ncUserManager;
-
+ protected UserMapping&MockObject $userMapper;
+ protected IManager&MockObject $shareManager;
+ protected GroupMapping&MockObject $groupMapper;
+ private Connection&MockObject $connection;
+ private LDAP&MockObject $ldap;
+ private Manager&MockObject $userManager;
+ private Helper&MockObject $helper;
+ private IConfig&MockObject $config;
+ private IUserManager&MockObject $ncUserManager;
private LoggerInterface&MockObject $logger;
-
private IAppConfig&MockObject $appConfig;
-
- /** @var IEventDispatcher|MockObject */
- private $dispatcher;
+ private IEventDispatcher&MockObject $dispatcher;
private Access $access;
protected function setUp(): void {
- $this->connection = $this->createMock(Connection::class);
$this->ldap = $this->createMock(LDAP::class);
+ $this->connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->ldap])
+ ->getMock();
$this->userManager = $this->createMock(Manager::class);
$this->helper = $this->createMock(Helper::class);
$this->config = $this->createMock(IConfig::class);
@@ -126,19 +117,19 @@ class AccessTest extends TestCase {
public function testEscapeFilterPartValidChars(): void {
$input = 'okay';
- $this->assertTrue($input === $this->access->escapeFilterPart($input));
+ $this->assertSame($input, $this->access->escapeFilterPart($input));
}
public function testEscapeFilterPartEscapeWildcard(): void {
$input = '*';
$expected = '\\2a';
- $this->assertTrue($expected === $this->access->escapeFilterPart($input));
+ $this->assertSame($expected, $this->access->escapeFilterPart($input));
}
public function testEscapeFilterPartEscapeWildcard2(): void {
$input = 'foo*bar';
$expected = 'foo\\2abar';
- $this->assertTrue($expected === $this->access->escapeFilterPart($input));
+ $this->assertSame($expected, $this->access->escapeFilterPart($input));
}
/**
@@ -151,7 +142,7 @@ class AccessTest extends TestCase {
$this->assertSame($sidExpected, $this->access->convertSID2Str($sidBinary));
}
- public function convertSID2StrSuccessData() {
+ public static function convertSID2StrSuccessData(): array {
return [
[
[
@@ -209,55 +200,53 @@ class AccessTest extends TestCase {
$this->assertSame($expected, $this->access->getDomainDNFromDN($inputDN));
}
- public function dnInputDataProvider() {
- return [[
+ public static function dnInputDataProvider(): array {
+ return [
[
- 'input' => 'foo=bar,bar=foo,dc=foobar',
- 'interResult' => [
+ 'foo=bar,bar=foo,dc=foobar',
+ [
'count' => 3,
0 => 'foo=bar',
1 => 'bar=foo',
2 => 'dc=foobar'
],
- 'expectedResult' => true
+ true
],
[
- 'input' => 'foobarbarfoodcfoobar',
- 'interResult' => false,
- 'expectedResult' => false
+ 'foobarbarfoodcfoobar',
+ false,
+ false
]
- ]];
+ ];
}
/**
* @dataProvider dnInputDataProvider
- * @param array $case
*/
- public function testStringResemblesDN($case): void {
+ public function testStringResemblesDN(string $input, array|bool $interResult, bool $expectedResult): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig|MockObject $config */
+ /** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
$lw->expects($this->exactly(1))
->method('explodeDN')
- ->willReturnCallback(function ($dn) use ($case) {
- if ($dn === $case['input']) {
- return $case['interResult'];
+ ->willReturnCallback(function ($dn) use ($input, $interResult) {
+ if ($dn === $input) {
+ return $interResult;
}
return null;
});
- $this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
+ $this->assertSame($expectedResult, $access->stringResemblesDN($input));
}
/**
* @dataProvider dnInputDataProvider
- * @param $case
*/
- public function testStringResemblesDNLDAPmod($case): void {
+ public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig|MockObject $config */
+ /** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$lw = new LDAP();
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
@@ -266,7 +255,7 @@ class AccessTest extends TestCase {
$this->markTestSkipped('LDAP Module not available');
}
- $this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
+ $this->assertSame($expectedResult, $access->stringResemblesDN($input));
}
public function testCacheUserHome(): void {
@@ -290,7 +279,7 @@ class AccessTest extends TestCase {
->method('getAttributes')
->willReturn(['displayname' => ['bar', 'count' => 1]]);
- /** @var UserMapping|MockObject $mapperMock */
+ /** @var UserMapping&MockObject $mapperMock */
$mapperMock = $this->createMock(UserMapping::class);
$mapperMock->expects($this->any())
->method('getNameByDN')
@@ -335,7 +324,7 @@ class AccessTest extends TestCase {
}
public function testBatchApplyUserAttributesSkipped(): void {
- /** @var UserMapping|MockObject $mapperMock */
+ /** @var UserMapping&MockObject $mapperMock */
$mapperMock = $this->createMock(UserMapping::class);
$mapperMock->expects($this->any())
->method('getNameByDN')
@@ -376,7 +365,7 @@ class AccessTest extends TestCase {
}
public function testBatchApplyUserAttributesDontSkip(): void {
- /** @var UserMapping|MockObject $mapperMock */
+ /** @var UserMapping&MockObject $mapperMock */
$mapperMock = $this->createMock(UserMapping::class);
$mapperMock->expects($this->any())
->method('getNameByDN')
@@ -416,7 +405,7 @@ class AccessTest extends TestCase {
$this->access->batchApplyUserAttributes($data);
}
- public function dNAttributeProvider() {
+ public static function dNAttributeProvider(): array {
// corresponds to Access::resemblesDN()
return [
'dn' => ['dn'],
@@ -428,11 +417,10 @@ class AccessTest extends TestCase {
/**
* @dataProvider dNAttributeProvider
- * @param $attribute
*/
- public function testSanitizeDN($attribute): void {
+ public function testSanitizeDN(string $attribute): void {
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
- /** @var IConfig|MockObject $config */
+ /** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
@@ -628,7 +616,7 @@ class AccessTest extends TestCase {
$this->userMapper->expects($this->exactly($fakeLdapEntries['count']))
->method('getNameByDN')
->willReturnCallback(function ($fdn) {
- $parts = ldap_explode_dn($fdn, false);
+ $parts = ldap_explode_dn($fdn, 0);
return $parts[0];
});
@@ -676,7 +664,7 @@ class AccessTest extends TestCase {
$this->assertSame('Another Good Team', $groups[1]['cn'][0]);
}
- public function intUsernameProvider() {
+ public static function intUsernameProvider(): array {
return [
['alice', 'alice'],
['b/ob', 'bob'],
@@ -694,7 +682,7 @@ class AccessTest extends TestCase {
];
}
- public function groupIDCandidateProvider() {
+ public static function groupIDCandidateProvider(): array {
return [
['alice', 'alice'],
['b/ob', 'b/ob'],
@@ -713,11 +701,8 @@ class AccessTest extends TestCase {
/**
* @dataProvider intUsernameProvider
- *
- * @param $name
- * @param $expected
*/
- public function testSanitizeUsername($name, $expected): void {
+ public function testSanitizeUsername(string $name, ?string $expected): void {
if ($expected === null) {
$this->expectException(\InvalidArgumentException::class);
}
@@ -752,7 +737,7 @@ class AccessTest extends TestCase {
->with('detta')
->willReturnOnConsecutiveCalls($offlineUserMock, $regularUserMock);
- /** @var UserMapping|MockObject $mapperMock */
+ /** @var UserMapping&MockObject $mapperMock */
$mapperMock = $this->createMock(UserMapping::class);
$mapperMock->expects($this->any())
->method('getNameByDN')
diff --git a/apps/user_ldap/tests/ConfigurationTest.php b/apps/user_ldap/tests/ConfigurationTest.php
index cced8334bf5..dd6bd020f7b 100644
--- a/apps/user_ldap/tests/ConfigurationTest.php
+++ b/apps/user_ldap/tests/ConfigurationTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,15 +11,14 @@ namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\Configuration;
class ConfigurationTest extends \Test\TestCase {
- /** @var Configuration */
- protected $configuration;
+ protected Configuration $configuration;
protected function setUp(): void {
parent::setUp();
$this->configuration = new Configuration('t01', false);
}
- public function configurationDataProvider() {
+ public static function configurationDataProvider(): array {
$inputWithDN = [
'cn=someUsers,dc=example,dc=org',
' ',
@@ -89,12 +89,12 @@ class ConfigurationTest extends \Test\TestCase {
/**
* @dataProvider configurationDataProvider
*/
- public function testSetValue($key, $input, $expected): void {
+ public function testSetValue(string $key, string|array $input, string|array $expected): void {
$this->configuration->setConfiguration([$key => $input]);
$this->assertSame($this->configuration->$key, $expected);
}
- public function avatarRuleValueProvider() {
+ public static function avatarRuleValueProvider(): array {
return [
['none', []],
['data:selfie', ['selfie']],
@@ -108,7 +108,7 @@ class ConfigurationTest extends \Test\TestCase {
/**
* @dataProvider avatarRuleValueProvider
*/
- public function testGetAvatarAttributes($setting, $expected): void {
+ public function testGetAvatarAttributes(string $setting, array $expected): void {
$this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]);
$this->assertSame($expected, $this->configuration->getAvatarAttributes());
}
@@ -116,7 +116,7 @@ class ConfigurationTest extends \Test\TestCase {
/**
* @dataProvider avatarRuleValueProvider
*/
- public function testResolveRule($setting, $expected): void {
+ public function testResolveRule(string $setting, array $expected): void {
$this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]);
// so far the only thing that can get resolved :)
$this->assertSame($expected, $this->configuration->resolveRule('avatar'));
diff --git a/apps/user_ldap/tests/ConnectionTest.php b/apps/user_ldap/tests/ConnectionTest.php
index 9cb19891b3d..601611fcc2f 100644
--- a/apps/user_ldap/tests/ConnectionTest.php
+++ b/apps/user_ldap/tests/ConnectionTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,6 +11,7 @@ namespace OCA\User_LDAP\Tests;
use OC\ServerNotAvailableException;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\ILDAPWrapper;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class Test_Connection
@@ -19,19 +21,16 @@ use OCA\User_LDAP\ILDAPWrapper;
* @package OCA\User_LDAP\Tests
*/
class ConnectionTest extends \Test\TestCase {
- /** @var ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject */
- protected $ldap;
-
- /** @var Connection */
- protected $connection;
+ protected ILDAPWrapper&MockObject $ldap;
+ protected Connection $connection;
protected function setUp(): void {
parent::setUp();
$this->ldap = $this->createMock(ILDAPWrapper::class);
// we use a mock here to replace the cache mechanism, due to missing DI in LDAP backend.
- $this->connection = $this->getMockBuilder('OCA\User_LDAP\Connection')
- ->setMethods(['getFromCache', 'writeToCache'])
+ $this->connection = $this->getMockBuilder(Connection::class)
+ ->onlyMethods(['getFromCache', 'writeToCache'])
->setConstructorArgs([$this->ldap, '', null])
->getMock();
diff --git a/apps/user_ldap/tests/GroupLDAPPluginTest.php b/apps/user_ldap/tests/GroupLDAPPluginTest.php
index f67de32c2e9..9f4cff64d6b 100644
--- a/apps/user_ldap/tests/GroupLDAPPluginTest.php
+++ b/apps/user_ldap/tests/GroupLDAPPluginTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -9,27 +11,23 @@ use OCA\User_LDAP\GroupPluginManager;
use OCP\GroupInterface;
class GroupLDAPPluginTest extends \Test\TestCase {
-
- /**
- * @return GroupPluginManager
- */
- private function getGroupPluginManager() {
+ private function getGroupPluginManager(): GroupPluginManager {
return new GroupPluginManager();
}
public function testImplementsActions(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(GroupInterface::CREATE_GROUP);
- $plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions'])
+ $plugin2 = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions'])
->getMock();
$plugin2->expects($this->any())
@@ -47,8 +45,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testCreateGroup(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'createGroup'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'createGroup'])
->getMock();
$plugin->expects($this->any())
@@ -77,8 +75,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testDeleteGroup(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'deleteGroup'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'deleteGroup'])
->getMock();
$plugin->expects($this->any())
@@ -107,8 +105,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testAddToGroup(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'addToGroup'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'addToGroup'])
->getMock();
$plugin->expects($this->any())
@@ -138,8 +136,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testRemoveFromGroup(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'removeFromGroup'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'removeFromGroup'])
->getMock();
$plugin->expects($this->any())
@@ -169,8 +167,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testCountUsersInGroup(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'countUsersInGroup'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'countUsersInGroup'])
->getMock();
$plugin->expects($this->any())
@@ -200,8 +198,8 @@ class GroupLDAPPluginTest extends \Test\TestCase {
public function testgetGroupDetails(): void {
$pluginManager = $this->getGroupPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
- ->setMethods(['respondToActions', 'getGroupDetails'])
+ $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'getGroupDetails'])
->getMock();
$plugin->expects($this->any())
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index ad97d5024b1..d2634548f4f 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -34,10 +35,10 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class Group_LDAPTest extends TestCase {
- private MockObject|Access $access;
- private MockObject|GroupPluginManager $pluginManager;
- private MockObject|IConfig $config;
- private MockObject|IUserManager $ncUserManager;
+ private Access&MockObject $access;
+ private GroupPluginManager&MockObject $pluginManager;
+ private IConfig&MockObject $config;
+ private IUserManager&MockObject $ncUserManager;
private GroupLDAP $groupBackend;
public function setUp(): void {
@@ -96,30 +97,19 @@ class Group_LDAPTest extends TestCase {
* @return MockObject|Access
*/
private function getAccessMock() {
- static $conMethods;
- static $accMethods;
-
- if (is_null($conMethods) || is_null($accMethods)) {
- $conMethods = get_class_methods(Connection::class);
- $accMethods = get_class_methods(Access::class);
- }
$lw = $this->createMock(ILDAPWrapper::class);
-
$connector = $this->getMockBuilder(Connection::class)
- ->setMethods($conMethods)
->setConstructorArgs([$lw, '', null])
->getMock();
$this->access = $this->createMock(Access::class);
-
$this->access->connection = $connector;
-
$this->access->userManager = $this->createMock(Manager::class);
return $this->access;
}
- private function enableGroups() {
+ private function enableGroups(): void {
$this->access->connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($name) {
@@ -179,7 +169,7 @@ class Group_LDAPTest extends TestCase {
public function testCountUsersWithPlugin(): void {
/** @var GroupPluginManager|MockObject $pluginManager */
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'countUsersInGroup'])
+ ->onlyMethods(['implementsActions', 'countUsersInGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -470,7 +460,7 @@ class Group_LDAPTest extends TestCase {
$this->groupBackend->inGroup($uid, $gid);
}
- public function groupWithMembersProvider() {
+ public static function groupWithMembersProvider(): array {
return [
[
'someGroup',
@@ -574,7 +564,7 @@ class Group_LDAPTest extends TestCase {
$memberUids = [];
$userRecords = [];
foreach ($memberDNs as $dn) {
- $memberUids[] = ldap_explode_dn($dn, false)[0];
+ $memberUids[] = ldap_explode_dn($dn, 0)[0];
$userRecords[] = ['dn' => [$dn]];
}
@@ -876,8 +866,8 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
/**
@@ -903,8 +893,8 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
public function testGetUserGroupsUnrecognizedOfflineUser(): void {
@@ -946,11 +936,11 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
- public function nestedGroupsProvider(): array {
+ public static function nestedGroupsProvider(): array {
return [
[true],
[false],
@@ -1076,7 +1066,7 @@ class Group_LDAPTest extends TestCase {
public function testCreateGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'createGroup'])
+ ->onlyMethods(['implementsActions', 'createGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1090,7 +1080,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->createGroup('gid'), true);
+ $this->assertTrue($this->groupBackend->createGroup('gid'));
}
@@ -1098,7 +1088,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'createGroup'])
+ ->onlyMethods(['implementsActions', 'createGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1112,7 +1102,7 @@ class Group_LDAPTest extends TestCase {
public function testDeleteGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'deleteGroup'])
+ ->onlyMethods(['implementsActions', 'deleteGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1126,7 +1116,7 @@ class Group_LDAPTest extends TestCase {
->willReturn(true);
$mapper = $this->getMockBuilder(GroupMapping::class)
- ->setMethods(['unmap'])
+ ->onlyMethods(['unmap'])
->disableOriginalConstructor()
->getMock();
@@ -1143,7 +1133,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'deleteGroup'])
+ ->onlyMethods(['implementsActions', 'deleteGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1157,7 +1147,7 @@ class Group_LDAPTest extends TestCase {
public function testAddToGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'addToGroup'])
+ ->onlyMethods(['implementsActions', 'addToGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1171,7 +1161,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->addToGroup('uid', 'gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->addToGroup('uid', 'gid'));
}
@@ -1179,7 +1169,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'addToGroup'])
+ ->onlyMethods(['implementsActions', 'addToGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1193,7 +1183,7 @@ class Group_LDAPTest extends TestCase {
public function testRemoveFromGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'removeFromGroup'])
+ ->onlyMethods(['implementsActions', 'removeFromGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1207,7 +1197,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->removeFromGroup('uid', 'gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->removeFromGroup('uid', 'gid'));
}
@@ -1215,7 +1205,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'removeFromGroup'])
+ ->onlyMethods(['implementsActions', 'removeFromGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1230,7 +1220,7 @@ class Group_LDAPTest extends TestCase {
public function testGetGroupDetailsWithPlugin(): void {
/** @var GroupPluginManager|MockObject $pluginManager */
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'getGroupDetails'])
+ ->onlyMethods(['implementsActions', 'getGroupDetails'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1244,14 +1234,14 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->getGroupDetails('gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->getGroupDetails('gid'));
}
public function testGetGroupDetailsFailing(): void {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'getGroupDetails'])
+ ->onlyMethods(['implementsActions', 'getGroupDetails'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1263,7 +1253,7 @@ class Group_LDAPTest extends TestCase {
$this->groupBackend->getGroupDetails('gid');
}
- public function groupMemberProvider() {
+ public static function groupMemberProvider(): array {
$base = 'dc=species,dc=earth';
$birdsDn = [
@@ -1332,10 +1322,9 @@ class Group_LDAPTest extends TestCase {
}
/**
- * @param string[] $expectedMembers
* @dataProvider groupMemberProvider
*/
- public function testGroupMembers(array $expectedResult, ?array $groupsInfo = null): void {
+ public function testGroupMembers(array $expectedResult, array $groupsInfo): void {
$this->access->expects($this->any())
->method('readAttribute')
->willReturnCallback(function ($group) use ($groupsInfo) {
@@ -1360,11 +1349,13 @@ class Group_LDAPTest extends TestCase {
foreach ($expectedResult as $groupDN => $expectedMembers) {
$resultingMembers = $this->invokePrivate($this->groupBackend, '_groupMembers', [$groupDN]);
- $this->assertEqualsCanonicalizing($expectedMembers, $resultingMembers);
+ sort($expectedMembers);
+ sort($resultingMembers);
+ $this->assertEquals($expectedMembers, $resultingMembers);
}
}
- public function displayNameProvider() {
+ public static function displayNameProvider(): array {
return [
['Graphic Novelists', ['Graphic Novelists']],
['', false],
@@ -1374,7 +1365,7 @@ class Group_LDAPTest extends TestCase {
/**
* @dataProvider displayNameProvider
*/
- public function testGetDisplayName(string $expected, $ldapResult): void {
+ public function testGetDisplayName(string $expected, bool|array $ldapResult): void {
$gid = 'graphic_novelists';
$this->access->expects($this->atLeastOnce())
diff --git a/apps/user_ldap/tests/HelperTest.php b/apps/user_ldap/tests/HelperTest.php
index eee5c162b53..470b67c5531 100644
--- a/apps/user_ldap/tests/HelperTest.php
+++ b/apps/user_ldap/tests/HelperTest.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
@@ -9,17 +11,15 @@ use OCA\User_LDAP\Helper;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @group DB
*/
class HelperTest extends \Test\TestCase {
+ private IConfig&MockObject $config;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
-
- /** @var Helper */
- private $helper;
+ private Helper $helper;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
index e45238fa978..ae1709edd22 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
@@ -3,7 +3,7 @@
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\user_ldap\tests\Integration\Lib;
+namespace OCA\User_LDAP\Tests\Integration\Lib;
use OCA\User_LDAP\Group_LDAP;
use OCA\User_LDAP\GroupPluginManager;
diff --git a/apps/user_ldap/tests/Jobs/CleanUpTest.php b/apps/user_ldap/tests/Jobs/CleanUpTest.php
index 582b6fba5d7..cefc9cc86b5 100644
--- a/apps/user_ldap/tests/Jobs/CleanUpTest.php
+++ b/apps/user_ldap/tests/Jobs/CleanUpTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -18,13 +19,11 @@ use OCP\IDBConnection;
use Test\TestCase;
class CleanUpTest extends TestCase {
- /** @var CleanUp */
- protected $bgJob;
-
- /** @var array */
- protected $mocks;
+ protected CleanUp $bgJob;
+ protected array $mocks;
public function setUp(): void {
+ parent::setUp();
$this->createMocks();
$this->bgJob = new CleanUp($this->mocks['timeFactory'], $this->mocks['userBackend'], $this->mocks['deletedUsersIndex']);
$this->bgJob->setArguments($this->mocks);
diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index 8277e7d48a9..20489ea0901 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -26,32 +27,23 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
+/**
+ * @group DB
+ */
class SyncTest extends TestCase {
- /** @var array */
- protected $arguments;
- /** @var Helper|MockObject */
- protected $helper;
- /** @var LDAP|MockObject */
- protected $ldapWrapper;
- /** @var Manager|MockObject */
- protected $userManager;
- /** @var UserMapping|MockObject */
- protected $mapper;
+ protected Helper&MockObject $helper;
+ protected LDAP&MockObject $ldapWrapper;
+ protected Manager&MockObject $userManager;
+ protected UserMapping&MockObject $mapper;
+ protected IConfig&MockObject $config;
+ protected IAvatarManager&MockObject $avatarManager;
+ protected IDBConnection&MockObject $dbc;
+ protected IUserManager&MockObject $ncUserManager;
+ protected IManager&MockObject $notificationManager;
+ protected ConnectionFactory&MockObject $connectionFactory;
+ protected AccessFactory&MockObject $accessFactory;
+ protected array $arguments = [];
protected Sync $sync;
- /** @var IConfig|MockObject */
- protected $config;
- /** @var IAvatarManager|MockObject */
- protected $avatarManager;
- /** @var IDBConnection|MockObject */
- protected $dbc;
- /** @var IUserManager|MockObject */
- protected $ncUserManager;
- /** @var IManager|MockObject */
- protected $notificationManager;
- /** @var ConnectionFactory|MockObject */
- protected $connectionFactory;
- /** @var AccessFactory|MockObject */
- protected $accessFactory;
protected function setUp(): void {
parent::setUp();
@@ -65,7 +57,11 @@ class SyncTest extends TestCase {
$this->dbc = $this->createMock(IDBConnection::class);
$this->ncUserManager = $this->createMock(IUserManager::class);
$this->notificationManager = $this->createMock(IManager::class);
- $this->connectionFactory = $this->createMock(ConnectionFactory::class);
+ $this->connectionFactory = $this->getMockBuilder(ConnectionFactory::class)
+ ->setConstructorArgs([
+ $this->ldapWrapper,
+ ])
+ ->getMock();
$this->accessFactory = $this->createMock(AccessFactory::class);
$this->sync = new Sync(
@@ -86,7 +82,7 @@ class SyncTest extends TestCase {
$this->sync->overwritePropertiesForTest($this->ldapWrapper);
}
- public function intervalDataProvider(): array {
+ public static function intervalDataProvider(): array {
return [
[
0, 1000, 750
@@ -139,7 +135,7 @@ class SyncTest extends TestCase {
$this->sync->updateInterval();
}
- public function moreResultsProvider() {
+ public static function moreResultsProvider(): array {
return [
[ 3, 3, true ],
[ 3, 5, true ],
@@ -153,7 +149,11 @@ class SyncTest extends TestCase {
* @dataProvider moreResultsProvider
*/
public function testMoreResults($pagingSize, $results, $expected): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([
+ $this->ldapWrapper,
+ ])
+ ->getMock();
$this->connectionFactory->expects($this->any())
->method('get')
->willReturn($connection);
@@ -166,7 +166,7 @@ class SyncTest extends TestCase {
return null;
});
- /** @var Access|MockObject $access */
+ /** @var Access&MockObject $access */
$access = $this->createMock(Access::class);
$this->accessFactory->expects($this->any())
->method('get')
@@ -191,7 +191,7 @@ class SyncTest extends TestCase {
$this->assertSame($expected, $hasMoreResults);
}
- public function cycleDataProvider() {
+ public static function cycleDataProvider(): array {
$lastCycle = ['prefix' => 's01', 'offset' => 1000];
$lastCycle2 = ['prefix' => '', 'offset' => 1000];
return [
@@ -207,19 +207,23 @@ class SyncTest extends TestCase {
/**
* @dataProvider cycleDataProvider
*/
- public function testDetermineNextCycle($cycleData, $prefixes, $expectedCycle): void {
+ public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?array $expectedCycle): void {
$this->helper->expects($this->any())
->method('getServerConfigurationPrefixes')
->with(true)
->willReturn($prefixes);
if (is_array($expectedCycle)) {
+ $calls = [
+ ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
+ ['user_ldap', 'background_sync_offset', $expectedCycle['offset']],
+ ];
$this->config->expects($this->exactly(2))
->method('setAppValue')
- ->withConsecutive(
- ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
- ['user_ldap', 'background_sync_offset', $expectedCycle['offset']]
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
} else {
$this->config->expects($this->never())
->method('setAppValue');
@@ -248,7 +252,7 @@ class SyncTest extends TestCase {
$this->assertFalse($this->sync->qualifiesToRun($cycleData));
}
- public function runDataProvider(): array {
+ public static function runDataProvider(): array {
return [
#0 - one LDAP server, reset
[[
@@ -283,7 +287,7 @@ class SyncTest extends TestCase {
/**
* @dataProvider runDataProvider
*/
- public function testRun($runData): void {
+ public function testRun(array $runData): void {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(function ($app, $key, $default) use ($runData) {
@@ -310,13 +314,18 @@ class SyncTest extends TestCase {
return $default;
});
+
+ $calls = [
+ ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']],
+ ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']],
+ ['user_ldap', 'background_sync_interval', '43200'],
+ ];
$this->config->expects($this->exactly(3))
->method('setAppValue')
- ->withConsecutive(
- ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']],
- ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']],
- ['user_ldap', 'background_sync_interval', $this->anything()]
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->config->expects($this->any())
->method('getAppKeys')
->with('user_ldap')
@@ -327,7 +336,11 @@ class SyncTest extends TestCase {
->with(true)
->willReturn($runData['prefixes']);
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([
+ $this->ldapWrapper,
+ ])
+ ->getMock();
$this->connectionFactory->expects($this->any())
->method('get')
->willReturn($connection);
@@ -340,7 +353,7 @@ class SyncTest extends TestCase {
return null;
});
- /** @var Access|MockObject $access */
+ /** @var Access&MockObject $access */
$access = $this->createMock(Access::class);
$this->accessFactory->expects($this->any())
->method('get')
diff --git a/apps/user_ldap/tests/LDAPGroupPluginDummy.php b/apps/user_ldap/tests/LDAPGroupPluginDummy.php
index 0d47fbbd290..5ea1a491f14 100644
--- a/apps/user_ldap/tests/LDAPGroupPluginDummy.php
+++ b/apps/user_ldap/tests/LDAPGroupPluginDummy.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php
index 9b0830ae513..a4da4a91948 100644
--- a/apps/user_ldap/tests/LDAPProviderTest.php
+++ b/apps/user_ldap/tests/LDAPProviderTest.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
@@ -12,6 +14,7 @@ use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Group_LDAP;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\IGroupLDAP;
+use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\IUserLDAP;
use OCA\User_LDAP\LDAPProviderFactory;
use OCA\User_LDAP\User_LDAP;
@@ -31,13 +34,9 @@ use Psr\Log\LoggerInterface;
* @package OCA\User_LDAP\Tests
*/
class LDAPProviderTest extends \Test\TestCase {
- protected function setUp(): void {
- parent::setUp();
- }
-
private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) {
$server = $this->getMockBuilder('OC\Server')
- ->setMethods(['getUserManager', 'getBackends', 'getGroupManager'])
+ ->onlyMethods(['getUserManager', 'getGroupManager'])
->setConstructorArgs(['', new Config(\OC::$configDir)])
->getMock();
$server->expects($this->any())
@@ -46,16 +45,13 @@ class LDAPProviderTest extends \Test\TestCase {
$server->expects($this->any())
->method('getGroupManager')
->willReturn($this->getGroupManagerMock($groupBackend));
- $server->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
return $server;
}
private function getUserManagerMock(IUserLDAP $userBackend) {
$userManager = $this->getMockBuilder(Manager::class)
- ->setMethods(['getBackends'])
+ ->onlyMethods(['getBackends'])
->setConstructorArgs([
$this->createMock(IConfig::class),
$this->createMock(ICacheFactory::class),
@@ -71,7 +67,7 @@ class LDAPProviderTest extends \Test\TestCase {
private function getGroupManagerMock(IGroupLDAP $groupBackend) {
$groupManager = $this->getMockBuilder('OC\Group\Manager')
- ->setMethods(['getBackends'])
+ ->onlyMethods(['getBackends'])
->disableOriginalConstructor()
->getMock();
$groupManager->expects($this->any())
@@ -98,8 +94,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -110,20 +106,25 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider->getUserDN('nonexisting_user');
}
+
public function testGetUserDN(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'username2dn'])
+ $userAccess = $this->getMockBuilder(Access::class)
+ ->onlyMethods(['username2dn'])
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userAccess->expects($this->once())
+ ->method('username2dn')
+ ->willReturn('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org');
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->once())
->method('userExists')
->willReturn(true);
- $userBackend->expects($this->once())
- ->method('username2dn')
- ->willReturn('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org');
$userBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($userAccess);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -137,12 +138,9 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
- ->getMock();
-
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists'])
+ $userBackend = $this->createMock(User_LDAP::class);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists'])
->disableOriginalConstructor()
->getMock();
@@ -155,25 +153,23 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetGroupDN(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'username2dn'])
- ->disableOriginalConstructor()
- ->getMock();
+ $userBackend = $this->createMock(User_LDAP::class);
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists', 'getLDAPAccess', 'groupname2dn'])
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
+ $groupAccess = $this->createMock(Access::class);
+ $groupAccess->expects($this->once())
+ ->method('groupname2dn')
+ ->willReturn('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org');
$groupBackend->expects($this->once())
->method('groupExists')
->willReturn(true);
- $groupBackend->expects($this->once())
- ->method('groupname2dn')
- ->willReturn('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org');
$groupBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($groupAccess);
$server = $this->getServerMock($userBackend, $groupBackend);
@@ -183,8 +179,8 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetUserName(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['dn2UserName'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['dn2UserName'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())
@@ -199,10 +195,7 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testDNasBaseParameter(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods([])
- ->disableOriginalConstructor()
- ->getMock();
+ $userBackend = $this->createMock(User_LDAP::class);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -215,10 +208,7 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testSanitizeDN(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods([])
- ->disableOriginalConstructor()
- ->getMock();
+ $userBackend = $this->createMock(User_LDAP::class);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -235,10 +225,7 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
- ->disableOriginalConstructor()
- ->getMock();
+ $userBackend = $this->createMock(User_LDAP::class);
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -248,8 +235,8 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetLDAPConnection(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getNewLDAPConnection'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getNewLDAPConnection'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())
@@ -271,12 +258,9 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
- ->getMock();
-
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists'])
+ $userBackend = $this->createMock(User_LDAP::class);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists'])
->disableOriginalConstructor()
->getMock();
@@ -289,12 +273,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetGroupLDAPConnection(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
- ->getMock();
-
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists','getNewLDAPConnection'])
+ $userBackend = $this->createMock(User_LDAP::class);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists','getNewLDAPConnection'])
->disableOriginalConstructor()
->getMock();
@@ -318,8 +299,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -337,7 +318,9 @@ class LDAPProviderTest extends \Test\TestCase {
];
$dn = 'uid=malik,' . $bases[1];
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($key) use ($bases) {
@@ -359,8 +342,8 @@ class LDAPProviderTest extends \Test\TestCase {
->method('username2dn')
->willReturn($dn);
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->atLeastOnce())
@@ -381,8 +364,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -399,7 +382,9 @@ class LDAPProviderTest extends \Test\TestCase {
'ou=groups,ou=barfoo,dc=example,dc=org',
];
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($key) use ($bases) {
@@ -415,8 +400,8 @@ class LDAPProviderTest extends \Test\TestCase {
->method('getConnection')
->willReturn($connection);
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())
@@ -437,8 +422,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -450,19 +435,25 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testClearCache(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'clearCache'])
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
+ $connection->expects($this->once())
+ ->method('clearCache')
+ ->willReturn(true);
+ $access = $this->createMock(Access::class);
+ $access->method('getConnection')
+ ->willReturn($connection);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->once())
->method('userExists')
->willReturn(true);
- $userBackend->expects($this->once())
- ->method('clearCache')
- ->willReturn(true);
$userBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($access);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -476,11 +467,11 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
->disableOriginalConstructor()
->getMock();
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists'])
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists'])
->disableOriginalConstructor()
->getMock();
$groupBackend->expects($this->any())->method('groupExists')->willReturn(false);
@@ -492,22 +483,26 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testClearGroupCache(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
+ $userBackend = $this->createMock(User_LDAP::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
->getMock();
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists', 'getLDAPAccess', 'getConnection', 'clearCache'])
+ $connection->expects($this->once())
+ ->method('clearCache')
+ ->willReturn(true);
+ $access = $this->createMock(Access::class);
+ $access->method('getConnection')
+ ->willReturn($connection);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$groupBackend->expects($this->once())
->method('groupExists')
->willReturn(true);
- $groupBackend->expects($this->once())
- ->method('clearCache')
- ->willReturn(true);
$groupBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($access);
$server = $this->getServerMock($userBackend, $groupBackend);
@@ -517,8 +512,8 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testDnExists(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['dn2UserName'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['dn2UserName'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())
@@ -532,11 +527,7 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testFlagRecord(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods([])
- ->disableOriginalConstructor()
- ->getMock();
-
+ $userBackend = $this->createMock(User_LDAP::class);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server);
@@ -545,11 +536,7 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testUnflagRecord(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods([])
- ->disableOriginalConstructor()
- ->getMock();
-
+ $userBackend = $this->createMock(User_LDAP::class);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server);
@@ -562,8 +549,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -575,19 +562,25 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetLDAPDisplayNameField(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration'])
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
+ $connection->expects($this->once())
+ ->method('getConfiguration')
+ ->willReturn(['ldap_display_name' => 'displayName']);
+ $access = $this->createMock(Access::class);
+ $access->method('getConnection')
+ ->willReturn($connection);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->once())
->method('userExists')
->willReturn(true);
- $userBackend->expects($this->once())
- ->method('getConfiguration')
- ->willReturn(['ldap_display_name' => 'displayName']);
$userBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($access);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -600,8 +593,8 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists'])
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false);
@@ -613,19 +606,25 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetLDAPEmailField(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'getConfiguration'])
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
+ $connection->expects($this->once())
+ ->method('getConfiguration')
+ ->willReturn(['ldap_email_attr' => 'mail']);
+ $access = $this->createMock(Access::class);
+ $access->method('getConnection')
+ ->willReturn($connection);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->onlyMethods(['userExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
$userBackend->expects($this->once())
->method('userExists')
->willReturn(true);
- $userBackend->expects($this->once())
- ->method('getConfiguration')
- ->willReturn(['ldap_email_attr' => 'mail']);
$userBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($access);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
@@ -638,16 +637,15 @@ class LDAPProviderTest extends \Test\TestCase {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP');
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
- ->getMock();
-
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists'])
+ $userBackend = $this->createMock(User_LDAP::class);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists'])
->disableOriginalConstructor()
->getMock();
- $groupBackend->expects($this->any())->method('groupExists')->willReturn(false);
+ $groupBackend->expects($this->any())
+ ->method('groupExists')
+ ->willReturn(false);
$server = $this->getServerMock($userBackend, $groupBackend);
@@ -656,12 +654,19 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testgetLDAPGroupMemberAssoc(): void {
- $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
- ->disableOriginalConstructor()
- ->getMock();
+ $userBackend = $this->createMock(User_LDAP::class);
- $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
- ->setMethods(['groupExists', 'getLDAPAccess', 'getConnection', 'getConfiguration'])
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
+ $connection->expects($this->once())
+ ->method('getConfiguration')
+ ->willReturn(['ldap_group_member_assoc_attribute' => 'assoc_type']);
+ $access = $this->createMock(Access::class);
+ $access->method('getConnection')
+ ->willReturn($connection);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->onlyMethods(['groupExists', 'getLDAPAccess'])
->disableOriginalConstructor()
->getMock();
@@ -669,11 +674,8 @@ class LDAPProviderTest extends \Test\TestCase {
->method('groupExists')
->willReturn(true);
$groupBackend->expects($this->any())
- ->method('getConfiguration')
- ->willReturn(['ldap_group_member_assoc_attribute' => 'assoc_type']);
- $groupBackend->expects($this->any())
- ->method($this->anything())
- ->willReturnSelf();
+ ->method('getLDAPAccess')
+ ->willReturn($access);
$server = $this->getServerMock($userBackend, $groupBackend);
@@ -698,7 +700,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetMultiValueUserAttributeCacheHit(): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects(self::once())
->method('getFromCache')
->with('admin-mailAlias')
@@ -723,7 +727,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetMultiValueUserAttributeLdapError(): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects(self::once())
->method('getFromCache')
->with('admin-mailAlias')
@@ -760,7 +766,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetMultiValueUserAttribute(): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects(self::once())
->method('getFromCache')
->with('admin-mailAlias')
@@ -797,7 +805,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetUserAttributeLdapError(): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects(self::once())
->method('getFromCache')
->with('admin-mailAlias')
@@ -834,7 +844,9 @@ class LDAPProviderTest extends \Test\TestCase {
}
public function testGetUserAttribute(): void {
- $connection = $this->createMock(Connection::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$connection->expects(self::once())
->method('getFromCache')
->with('admin-mailAlias')
diff --git a/apps/user_ldap/tests/LDAPTest.php b/apps/user_ldap/tests/LDAPTest.php
index a29751555cb..936a1a27d3d 100644
--- a/apps/user_ldap/tests/LDAPTest.php
+++ b/apps/user_ldap/tests/LDAPTest.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
@@ -6,20 +8,20 @@
namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\LDAP;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class LDAPTest extends TestCase {
- /** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
- private $ldap;
+ private LDAP&MockObject $ldap;
protected function setUp(): void {
parent::setUp();
$this->ldap = $this->getMockBuilder(LDAP::class)
- ->setMethods(['invokeLDAPMethod'])
+ ->onlyMethods(['invokeLDAPMethod'])
->getMock();
}
- public function errorProvider() {
+ public static function errorProvider(): array {
return [
[
'ldap_search(): Partial search results returned: Sizelimit exceeded at /srv/http/nextcloud/master/apps/user_ldap/lib/LDAP.php#292',
@@ -32,8 +34,6 @@ class LDAPTest extends TestCase {
}
/**
- * @param string $errorMessage
- * @param bool $passThrough
* @dataProvider errorProvider
*/
public function testSearchWithErrorHandler(string $errorMessage, bool $passThrough): void {
diff --git a/apps/user_ldap/tests/LDAPUserPluginDummy.php b/apps/user_ldap/tests/LDAPUserPluginDummy.php
index f6edf3df63b..8d4870406ae 100644
--- a/apps/user_ldap/tests/LDAPUserPluginDummy.php
+++ b/apps/user_ldap/tests/LDAPUserPluginDummy.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -39,4 +41,12 @@ class LDAPUserPluginDummy implements ILDAPUserPlugin {
public function countUsers() {
return null;
}
+
+ public function canDeleteUser() {
+ return true;
+ }
+
+ public function deleteUser($uid) {
+ return null;
+ }
}
diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTestCase.php
index f1e9b1b67bc..8efee4e2085 100644
--- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/AbstractMappingTestCase.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,7 +12,7 @@ use OCA\User_LDAP\Mapping\AbstractMapping;
use OCP\IDBConnection;
use OCP\Server;
-abstract class AbstractMappingTest extends \Test\TestCase {
+abstract class AbstractMappingTestCase extends \Test\TestCase {
abstract public function getMapper(IDBConnection $dbMock);
/**
@@ -29,8 +30,8 @@ abstract class AbstractMappingTest extends \Test\TestCase {
* returns an array of test entries with dn, name and uuid as keys
* @return array
*/
- protected function getTestData() {
- $data = [
+ protected static function getTestData(): array {
+ return [
[
'dn' => 'uid=foobar,dc=example,dc=org',
'name' => 'Foobar',
@@ -47,8 +48,6 @@ abstract class AbstractMappingTest extends \Test\TestCase {
'uuid' => '3333-CCCC-1234-CDEF',
]
];
-
- return $data;
}
/**
@@ -56,7 +55,7 @@ abstract class AbstractMappingTest extends \Test\TestCase {
* @param AbstractMapping $mapper
* @param array $data
*/
- protected function mapEntries($mapper, $data) {
+ protected function mapEntries(AbstractMapping $mapper, array $data): void {
foreach ($data as $entry) {
$done = $mapper->map($entry['dn'], $entry['name'], $entry['uuid']);
$this->assertTrue($done);
@@ -70,7 +69,7 @@ abstract class AbstractMappingTest extends \Test\TestCase {
* @return array 0 = \OCA\User_LDAP\Mapping\AbstractMapping, 1 = array of
* users or groups
*/
- private function initTest() {
+ private function initTest(): array {
$dbc = Server::get(IDBConnection::class);
$mapper = $this->getMapper($dbc);
$data = $this->getTestData();
@@ -157,13 +156,13 @@ abstract class AbstractMappingTest extends \Test\TestCase {
[$mapper,] = $this->initTest();
$names = $mapper->getNamesBySearch('oo', '%', '%');
- $this->assertTrue(is_array($names));
+ $this->assertIsArray($names);
$this->assertSame(2, count($names));
- $this->assertTrue(in_array('Foobar', $names));
- $this->assertTrue(in_array('Barfoo', $names));
+ $this->assertContains('Foobar', $names);
+ $this->assertContains('Barfoo', $names);
$names = $mapper->getNamesBySearch('nada');
- $this->assertTrue(is_array($names));
- $this->assertSame(0, count($names));
+ $this->assertIsArray($names);
+ $this->assertCount(0, $names);
}
/**
@@ -250,20 +249,20 @@ abstract class AbstractMappingTest extends \Test\TestCase {
// get all entries without specifying offset or limit
$results = $mapper->getList();
- $this->assertSame(3, count($results));
+ $this->assertCount(3, $results);
// get all-1 entries by specifying offset, and an high limit
// specifying only offset without limit will not work by underlying lib
$results = $mapper->getList(1, 999);
- $this->assertSame(count($data) - 1, count($results));
+ $this->assertCount(count($data) - 1, $results);
// get first 2 entries by limit, but not offset
$results = $mapper->getList(0, 2);
- $this->assertSame(2, count($results));
+ $this->assertCount(2, $results);
// get 2nd entry by specifying both offset and limit
$results = $mapper->getList(1, 1);
- $this->assertSame(1, count($results));
+ $this->assertCount(1, $results);
}
public function testGetListOfIdsByDn(): void {
@@ -282,6 +281,6 @@ abstract class AbstractMappingTest extends \Test\TestCase {
}
$result = $mapper->getListOfIdsByDn($listOfDNs);
- $this->assertSame(66640 / 20, count($result));
+ $this->assertCount(66640 / 20, $result);
}
}
diff --git a/apps/user_ldap/tests/Mapping/GroupMappingTest.php b/apps/user_ldap/tests/Mapping/GroupMappingTest.php
index efa42e47863..5729058d10e 100644
--- a/apps/user_ldap/tests/Mapping/GroupMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/GroupMappingTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,7 +18,7 @@ use OCP\IDBConnection;
*
* @package OCA\User_LDAP\Tests\Mapping
*/
-class GroupMappingTest extends AbstractMappingTest {
+class GroupMappingTest extends AbstractMappingTestCase {
public function getMapper(IDBConnection $dbMock) {
return new GroupMapping($dbMock);
}
diff --git a/apps/user_ldap/tests/Mapping/UserMappingTest.php b/apps/user_ldap/tests/Mapping/UserMappingTest.php
index 07980ba470c..4346fe1d23f 100644
--- a/apps/user_ldap/tests/Mapping/UserMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/UserMappingTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -18,7 +19,7 @@ use OCP\Support\Subscription\IAssertion;
*
* @package OCA\User_LDAP\Tests\Mapping
*/
-class UserMappingTest extends AbstractMappingTest {
+class UserMappingTest extends AbstractMappingTestCase {
public function getMapper(IDBConnection $dbMock) {
return new UserMapping($dbMock, $this->createMock(IAssertion::class));
}
diff --git a/apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php b/apps/user_ldap/tests/Migration/AbstractUUIDFixTestCase.php
index f8abcaeb482..7a85b885bc1 100644
--- a/apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php
+++ b/apps/user_ldap/tests/Migration/AbstractUUIDFixTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -13,17 +15,18 @@ use OCA\User_LDAP\Migration\UUIDFix;
use OCA\User_LDAP\Proxy;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
-abstract class AbstractUUIDFixTest extends TestCase {
- protected Helper $helper;
- protected IConfig $config;
- protected LDAP $ldap;
+abstract class AbstractUUIDFixTestCase extends TestCase {
+ protected Helper&MockObject $helper;
+ protected IConfig&MockObject $config;
+ protected LDAP&MockObject $ldap;
protected AbstractMapping $mapper;
protected UUIDFix $job;
protected Proxy $proxy;
- protected Access $access;
- protected ITimeFactory $time;
+ protected Access&MockObject $access;
+ protected ITimeFactory&MockObject $time;
protected bool $isUser = true;
protected function setUp(): void {
@@ -141,19 +144,23 @@ abstract class AbstractUUIDFixTest extends TestCase {
$this->access->expects($this->exactly(3))
->method('getUUID')
- ->withConsecutive(
- [$args['records'][0]['dn'], $this->isUser],
- [$args['records'][1]['dn'], $this->isUser],
- [$args['records'][2]['dn'], $this->isUser]
- )
- ->willReturnOnConsecutiveCalls($correctUUIDs[0], $correctUUIDs[1], $correctUUIDs[2]);
-
+ ->willReturnMap([
+ [$args['records'][0]['dn'], $this->isUser, null, $correctUUIDs[0]],
+ [$args['records'][1]['dn'], $this->isUser, null, $correctUUIDs[1]],
+ [$args['records'][2]['dn'], $this->isUser, null, $correctUUIDs[2]],
+ ]);
+
+ $calls = [
+ [$correctUUIDs[0], $args['records'][0]['dn']],
+ [$correctUUIDs[2], $args['records'][2]['dn']],
+ ];
$this->mapper->expects($this->exactly(2))
->method('setUUIDbyDN')
- ->withConsecutive(
- [$correctUUIDs[0], $args['records'][0]['dn']],
- [$correctUUIDs[2], $args['records'][2]['dn']]
- );
+ ->willReturnCallback(function ($i, $j) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ return true;
+ });
$this->job->run($args);
}
diff --git a/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php b/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php
index ab8fe03d6d2..89d880f4acb 100644
--- a/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php
+++ b/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php
@@ -1,14 +1,15 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Group_LDAP\Tests\Migration;
+namespace OCA\User_LDAP\Tests\Migration;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Migration\UUIDFixGroup;
-use OCA\User_LDAP\Tests\Migration\AbstractUUIDFixTest;
/**
* Class UUIDFixGroupTest
@@ -16,7 +17,7 @@ use OCA\User_LDAP\Tests\Migration\AbstractUUIDFixTest;
* @package OCA\Group_LDAP\Tests\Migration
* @group DB
*/
-class UUIDFixGroupTest extends AbstractUUIDFixTest {
+class UUIDFixGroupTest extends AbstractUUIDFixTestCase {
protected function setUp(): void {
$this->isUser = false;
parent::setUp();
diff --git a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
index f31da43c584..0fc601c7d2e 100644
--- a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
+++ b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,23 +13,15 @@ use OCA\User_LDAP\Migration\UUIDFixInsert;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\Migration\IOutput;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UUIDFixInsertTest extends TestCase {
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $userMapper;
-
- /** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $groupMapper;
-
- /** @var IJobList|\PHPUnit\Framework\MockObject\MockObject */
- protected $jobList;
-
- /** @var UUIDFixInsert */
- protected $job;
+ protected IConfig&MockObject $config;
+ protected UserMapping&MockObject $userMapper;
+ protected GroupMapping&MockObject $groupMapper;
+ protected IJobList&MockObject $jobList;
+ protected UUIDFixInsert $job;
protected function setUp(): void {
parent::setUp();
@@ -48,13 +42,12 @@ class UUIDFixInsertTest extends TestCase {
$this->assertSame('Insert UUIDFix background job for user and group in batches', $this->job->getName());
}
- public function recordProvider() {
+ public static function recordProvider(): array {
$record = [
'dn' => 'cn=somerecord,dc=somewhere',
'name' => 'Something',
'uuid' => 'AB12-3456-CDEF7-8GH9'
];
- array_fill(0, 50, $record);
$userBatches = [
0 => array_fill(0, 50, $record),
@@ -71,13 +64,12 @@ class UUIDFixInsertTest extends TestCase {
];
}
- public function recordProviderTooLongAndNone() {
+ public static function recordProviderTooLongAndNone(): array {
$record = [
'dn' => 'cn=somerecord,dc=somewhere',
'name' => 'Something',
'uuid' => 'AB12-3456-CDEF7-8GH9'
];
- array_fill(0, 50, $record);
$userBatches = [
0 => array_fill(0, 50, $record),
@@ -97,7 +89,7 @@ class UUIDFixInsertTest extends TestCase {
/**
* @dataProvider recordProvider
*/
- public function testRun($userBatches, $groupBatches): void {
+ public function testRun(array $userBatches, array $groupBatches): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('user_ldap', 'installed_version', '1.2.1')
@@ -105,8 +97,11 @@ class UUIDFixInsertTest extends TestCase {
$this->userMapper->expects($this->exactly(3))
->method('getList')
- ->withConsecutive([0, 50], [50, 50], [100, 50])
- ->willReturnOnConsecutiveCalls($userBatches[0], $userBatches[1], $userBatches[2]);
+ ->willReturnMap([
+ [0, 50, false, $userBatches[0]],
+ [50, 50, false, $userBatches[1]],
+ [100, 50, false, $userBatches[2]],
+ ]);
$this->groupMapper->expects($this->exactly(1))
->method('getList')
@@ -124,7 +119,7 @@ class UUIDFixInsertTest extends TestCase {
/**
* @dataProvider recordProviderTooLongAndNone
*/
- public function testRunWithManyAndNone($userBatches, $groupBatches): void {
+ public function testRunWithManyAndNone(array $userBatches, array $groupBatches): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('user_ldap', 'installed_version', '1.2.1')
@@ -132,8 +127,13 @@ class UUIDFixInsertTest extends TestCase {
$this->userMapper->expects($this->exactly(5))
->method('getList')
- ->withConsecutive([0, 50], [0, 40], [0, 32], [32, 32], [64, 32])
- ->willReturnOnConsecutiveCalls($userBatches[0], $userBatches[1], $userBatches[2], $userBatches[3], $userBatches[4]);
+ ->willReturnMap([
+ [0, 50, false, $userBatches[0]],
+ [0, 40, false, $userBatches[1]],
+ [0, 32, false, $userBatches[2]],
+ [32, 32, false, $userBatches[3]],
+ [64, 32, false, $userBatches[4]],
+ ]);
$this->groupMapper->expects($this->once())
->method('getList')
diff --git a/apps/user_ldap/tests/Migration/UUIDFixUserTest.php b/apps/user_ldap/tests/Migration/UUIDFixUserTest.php
index dfa1898450f..a582fd677fa 100644
--- a/apps/user_ldap/tests/Migration/UUIDFixUserTest.php
+++ b/apps/user_ldap/tests/Migration/UUIDFixUserTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,7 +17,7 @@ use OCA\User_LDAP\User_Proxy;
* @package OCA\User_LDAP\Tests\Migration
* @group DB
*/
-class UUIDFixUserTest extends AbstractUUIDFixTest {
+class UUIDFixUserTest extends AbstractUUIDFixTestCase {
protected function setUp(): void {
$this->isUser = true;
parent::setUp();
diff --git a/apps/user_ldap/tests/Service/BirthdateParserServiceTest.php b/apps/user_ldap/tests/Service/BirthdateParserServiceTest.php
index 79450d6913e..85d6a6ba5f7 100644
--- a/apps/user_ldap/tests/Service/BirthdateParserServiceTest.php
+++ b/apps/user_ldap/tests/Service/BirthdateParserServiceTest.php
@@ -1,11 +1,12 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\user_ldap\tests\Service;
+namespace OCA\User_LDAP\Tests\Service;
use DateTimeImmutable;
use OCA\User_LDAP\Service\BirthdateParserService;
@@ -20,7 +21,7 @@ class BirthdateParserServiceTest extends TestCase {
$this->service = new BirthdateParserService();
}
- public function parseBirthdateDataProvider(): array {
+ public static function parseBirthdateDataProvider(): array {
return [
['2024-01-01', new DateTimeImmutable('2024-01-01'), false],
['20240101', new DateTimeImmutable('2024-01-01'), false],
diff --git a/apps/user_ldap/tests/Service/UpdateGroupsServiceTest.php b/apps/user_ldap/tests/Service/UpdateGroupsServiceTest.php
index 84aefb484bb..601aee86602 100644
--- a/apps/user_ldap/tests/Service/UpdateGroupsServiceTest.php
+++ b/apps/user_ldap/tests/Service/UpdateGroupsServiceTest.php
@@ -6,17 +6,15 @@ declare(strict_types=1);
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\user_ldap\tests\Service;
+namespace OCA\User_LDAP\Tests\Service;
use OCA\User_LDAP\Db\GroupMembership;
use OCA\User_LDAP\Db\GroupMembershipMapper;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Service\UpdateGroupsService;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
-use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
@@ -26,23 +24,12 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class UpdateGroupsServiceTest extends TestCase {
- /** @var Group_Proxy|MockObject */
- protected $groupBackend;
- /** @var IEventDispatcher|MockObject */
- protected $dispatcher;
- /** @var IGroupManager|MockObject */
- protected $groupManager;
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var GroupMembershipMapper|MockObject */
- protected $groupMembershipMapper;
- /** @var IConfig|MockObject */
- protected $config;
- /** @var ITimeFactory|MockObject */
- protected $timeFactory;
-
+ protected Group_Proxy&MockObject $groupBackend;
+ protected IEventDispatcher&MockObject $dispatcher;
+ protected IGroupManager&MockObject $groupManager;
+ protected IUserManager&MockObject $userManager;
+ protected LoggerInterface&MockObject $logger;
+ protected GroupMembershipMapper&MockObject $groupMembershipMapper;
protected UpdateGroupsService $updateGroupsService;
public function setUp(): void {
@@ -52,8 +39,6 @@ class UpdateGroupsServiceTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->groupMembershipMapper = $this->createMock(GroupMembershipMapper::class);
- $this->config = $this->createMock(IConfig::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->updateGroupsService = new UpdateGroupsService(
$this->groupBackend,
@@ -62,8 +47,6 @@ class UpdateGroupsServiceTest extends TestCase {
$this->userManager,
$this->logger,
$this->groupMembershipMapper,
- $this->config,
- $this->timeFactory
);
}
diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php
index 05b9697e4c8..b17e96c1a68 100644
--- a/apps/user_ldap/tests/Settings/AdminTest.php
+++ b/apps/user_ldap/tests/Settings/AdminTest.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
@@ -20,13 +22,12 @@ use Test\TestCase;
*/
class AdminTest extends TestCase {
private IL10N&MockObject $l10n;
-
private ITemplateManager $templateManager;
private Admin $admin;
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->templateManager = Server::get(ITemplateManager::class);
$this->admin = new Admin(
@@ -35,9 +36,6 @@ class AdminTest extends TestCase {
);
}
- /**
- * @UseDB
- */
public function testGetForm(): void {
$prefixes = ['s01'];
$hosts = ['s01' => ''];
diff --git a/apps/user_ldap/tests/Settings/SectionTest.php b/apps/user_ldap/tests/Settings/SectionTest.php
index 722581713d1..3f9ae1e56d4 100644
--- a/apps/user_ldap/tests/Settings/SectionTest.php
+++ b/apps/user_ldap/tests/Settings/SectionTest.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
@@ -8,15 +10,13 @@ namespace OCA\User_LDAP\Tests\Settings;
use OCA\User_LDAP\Settings\Section;
use OCP\IL10N;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SectionTest extends TestCase {
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $url;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l;
- /** @var Section */
- private $section;
+ private IURLGenerator&MockObject $url;
+ private IL10N&MockObject $l;
+ private Section $section;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
index 64e443a064f..b245e52fe6e 100644
--- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
+++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,6 +13,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Server;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class DeletedUsersIndexTest
@@ -20,19 +23,11 @@ use OCP\Share\IManager;
* @package OCA\User_LDAP\Tests\User
*/
class DeletedUsersIndexTest extends \Test\TestCase {
- /** @var DeletedUsersIndex */
- protected $dui;
-
- /** @var IConfig */
- protected $config;
-
- /** @var IDBConnection */
- protected $db;
-
- /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $mapping;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected DeletedUsersIndex $dui;
+ protected IConfig $config;
+ protected IDBConnection $db;
+ protected UserMapping&MockObject $mapping;
+ protected IManager&MockObject $shareManager;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php
index 4f504ff5f7a..3f8b3aa174f 100644
--- a/apps/user_ldap/tests/User/ManagerTest.php
+++ b/apps/user_ldap/tests/User/ManagerTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,6 +20,7 @@ use OCP\Image;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -29,40 +31,18 @@ use Psr\Log\LoggerInterface;
* @package OCA\User_LDAP\Tests\User
*/
class ManagerTest extends \Test\TestCase {
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject */
- protected $access;
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
-
- /** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $avatarManager;
-
- /** @var Image|\PHPUnit\Framework\MockObject\MockObject */
- protected $image;
-
- /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
- protected $dbc;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $ncUserManager;
-
- /** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
-
- /** @var ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject */
- protected $ldapWrapper;
-
- /** @var Connection */
- protected $connection;
-
- /** @var Manager */
- protected $manager;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected Access&MockObject $access;
+ protected IConfig&MockObject $config;
+ protected LoggerInterface&MockObject $logger;
+ protected IAvatarManager&MockObject $avatarManager;
+ protected Image&MockObject $image;
+ protected IDBConnection&MockObject $dbc;
+ protected IUserManager&MockObject $ncUserManager;
+ protected INotificationManager&MockObject $notificationManager;
+ protected ILDAPWrapper&MockObject $ldapWrapper;
+ protected Connection $connection;
+ protected IManager&MockObject $shareManager;
+ protected Manager $manager;
protected function setUp(): void {
parent::setUp();
@@ -97,7 +77,7 @@ class ManagerTest extends \Test\TestCase {
$this->manager->setLdapAccess($this->access);
}
- public function dnProvider() {
+ public static function dnProvider(): array {
return [
['cn=foo,dc=foobar,dc=bar'],
['uid=foo,o=foobar,c=bar'],
@@ -197,7 +177,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertNull($user);
}
- public function attributeRequestProvider() {
+ public static function attributeRequestProvider(): array {
return [
[false],
[true],
@@ -217,10 +197,10 @@ class ManagerTest extends \Test\TestCase {
$attributes = $this->manager->getAttributes($minimal);
- $this->assertTrue(in_array('dn', $attributes));
- $this->assertTrue(in_array(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes));
- $this->assertTrue(!in_array($this->access->getConnection()->ldapEmailAttribute, $attributes)); #cases check
- $this->assertFalse(in_array('', $attributes));
+ $this->assertContains('dn', $attributes);
+ $this->assertContains(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes);
+ $this->assertNotContains($this->access->getConnection()->ldapEmailAttribute, $attributes); #cases check
+ $this->assertNotContains('', $attributes);
$this->assertSame(!$minimal, in_array('jpegphoto', $attributes));
$this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes));
$valueCounts = array_count_values($attributes);
diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php
index e53bfca7f47..5ef89303111 100644
--- a/apps/user_ldap/tests/User/OfflineUserTest.php
+++ b/apps/user_ldap/tests/User/OfflineUserTest.php
@@ -13,20 +13,15 @@ use OCA\User_LDAP\User\OfflineUser;
use OCP\IConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class OfflineUserTest extends TestCase {
-
- /** @var OfflineUser */
- protected $offlineUser;
- /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $mapping;
- /** @var string */
- protected $uid;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected UserMapping&MockObject $mapping;
+ protected string $uid;
+ protected IConfig&MockObject $config;
+ protected IManager&MockObject $shareManager;
+ protected OfflineUser $offlineUser;
public function setUp(): void {
$this->uid = 'deborah';
@@ -42,7 +37,7 @@ class OfflineUserTest extends TestCase {
);
}
- public function shareOwnerProvider(): array {
+ public static function shareOwnerProvider(): array {
return [
[[], false],
[[IShare::TYPE_USER], true],
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index badbca7f476..d9075af1569 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,6 +10,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
+use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User\User;
use OCP\IAvatar;
use OCP\IAvatarManager;
@@ -19,6 +21,7 @@ use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -29,33 +32,24 @@ use Psr\Log\LoggerInterface;
* @package OCA\User_LDAP\Tests\User
*/
class UserTest extends \Test\TestCase {
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject */
- protected $access;
- /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
- protected $connection;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
- /** @var Image|\PHPUnit\Framework\MockObject\MockObject */
- protected $image;
- /** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $avatarManager;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
- /** @var string */
- protected $uid = 'alice';
- /** @var string */
- protected $dn = 'uid=alice,dc=foo,dc=bar';
- /** @var User */
- protected $user;
+ protected Access&MockObject $access;
+ protected Connection&MockObject $connection;
+ protected IConfig&MockObject $config;
+ protected INotificationManager&MockObject $notificationManager;
+ protected IUserManager&MockObject $userManager;
+ protected Image&MockObject $image;
+ protected IAvatarManager&MockObject $avatarManager;
+ protected LoggerInterface&MockObject $logger;
+ protected string $uid = 'alice';
+ protected string $dn = 'uid=alice,dc=foo,dc=bar';
+ protected User $user;
protected function setUp(): void {
parent::setUp();
- $this->connection = $this->createMock(Connection::class);
+ $this->connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$this->access = $this->createMock(Access::class);
$this->access->connection = $this->connection;
@@ -100,9 +94,7 @@ class UserTest extends \Test\TestCase {
$this->equalTo('email'))
->willReturn(['alice@foo.bar']);
- $coreUser = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $coreUser = $this->createMock(IUser::class);
$coreUser->expects($this->once())
->method('setSystemEMailAddress')
->with('alice@foo.bar');
@@ -506,7 +498,7 @@ class UserTest extends \Test\TestCase {
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image));
+ ->with($this->image);
$this->avatarManager->expects($this->once())
->method('getAvatar')
@@ -617,7 +609,7 @@ class UserTest extends \Test\TestCase {
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image));
+ ->with($this->image);
$this->avatarManager->expects($this->once())
->method('getAvatar')
@@ -723,7 +715,7 @@ class UserTest extends \Test\TestCase {
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image))
+ ->with($this->image)
->willThrowException(new \Exception());
$this->avatarManager->expects($this->once())
@@ -780,7 +772,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateAvatar();
}
- public function extStorageHomeDataProvider() {
+ public static function extStorageHomeDataProvider(): array {
return [
[ 'myFolder', null ],
[ '', null, false ],
@@ -865,7 +857,7 @@ class UserTest extends \Test\TestCase {
$this->assertFalse($this->user->getAvatarImage());
}
- public function imageDataProvider() {
+ public static function imageDataProvider(): array {
return [
[ false, false ],
[ 'corruptData', false ],
@@ -884,7 +876,7 @@ class UserTest extends \Test\TestCase {
'updateExtStorageHome',
];
- /** @var User|\PHPUnit\Framework\MockObject\MockObject $userMock */
+ /** @var User&MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->setConstructorArgs([
$this->uid,
@@ -897,7 +889,7 @@ class UserTest extends \Test\TestCase {
$this->userManager,
$this->notificationManager
])
- ->setMethods($requiredMethods)
+ ->onlyMethods($requiredMethods)
->getMock();
$this->connection->setConfiguration([
@@ -937,7 +929,7 @@ class UserTest extends \Test\TestCase {
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
}
- public function emptyHomeFolderAttributeValueProvider() {
+ public static function emptyHomeFolderAttributeValueProvider(): array {
return [
'empty' => [''],
'prefixOnly' => ['attr:'],
@@ -947,7 +939,7 @@ class UserTest extends \Test\TestCase {
/**
* @dataProvider emptyHomeFolderAttributeValueProvider
*/
- public function testGetHomePathNotConfigured($attributeValue): void {
+ public function testGetHomePathNotConfigured(string $attributeValue): void {
$this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
@@ -1011,7 +1003,7 @@ class UserTest extends \Test\TestCase {
$this->user->getHomePath();
}
- public function displayNameProvider() {
+ public static function displayNameProvider(): array {
return [
['Roland Deschain', '', 'Roland Deschain', false],
['Roland Deschain', '', 'Roland Deschain', true],
@@ -1023,7 +1015,7 @@ class UserTest extends \Test\TestCase {
/**
* @dataProvider displayNameProvider
*/
- public function testComposeAndStoreDisplayName($part1, $part2, $expected, $expectTriggerChange): void {
+ public function testComposeAndStoreDisplayName(string $part1, string $part2, string $expected, bool $expectTriggerChange): void {
$this->config->expects($this->once())
->method('setUserValue');
$oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
diff --git a/apps/user_ldap/tests/UserLDAPPluginTest.php b/apps/user_ldap/tests/UserLDAPPluginTest.php
index 5f11f817771..8a065374e61 100644
--- a/apps/user_ldap/tests/UserLDAPPluginTest.php
+++ b/apps/user_ldap/tests/UserLDAPPluginTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -9,27 +11,23 @@ use OC\User\Backend;
use OCA\User_LDAP\UserPluginManager;
class UserLDAPPluginTest extends \Test\TestCase {
-
- /**
- * @return UserPluginManager
- */
- private function getUserPluginManager() {
+ private function getUserPluginManager(): UserPluginManager {
return new UserPluginManager();
}
public function testImplementsActions(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions'])
->getMock();
$plugin->expects($this->any())
->method('respondToActions')
->willReturn(Backend::CREATE_USER);
- $plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions'])
+ $plugin2 = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions'])
->getMock();
$plugin2->expects($this->any())
@@ -47,8 +45,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testCreateUser(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'createUser'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'createUser'])
->getMock();
$plugin->expects($this->any())
@@ -66,7 +64,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->createUser('user', 'password');
}
-
+
public function testCreateUserNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements createUser in this LDAP Backend.');
@@ -78,8 +76,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testSetPassword(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'setPassword'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'setPassword'])
->getMock();
$plugin->expects($this->any())
@@ -97,7 +95,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->setPassword('user', 'password');
}
-
+
public function testSetPasswordNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements setPassword in this LDAP Backend.');
@@ -109,8 +107,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testGetHome(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'getHome'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'getHome'])
->getMock();
$plugin->expects($this->any())
@@ -127,7 +125,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->getHome('uid');
}
-
+
public function testGetHomeNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements getHome in this LDAP Backend.');
@@ -139,8 +137,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testGetDisplayName(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'getDisplayName'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'getDisplayName'])
->getMock();
$plugin->expects($this->any())
@@ -157,7 +155,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->getDisplayName('uid');
}
-
+
public function testGetDisplayNameNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements getDisplayName in this LDAP Backend.');
@@ -169,8 +167,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testSetDisplayName(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'setDisplayName'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'setDisplayName'])
->getMock();
$plugin->expects($this->any())
@@ -188,7 +186,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->setDisplayName('user', 'password');
}
-
+
public function testSetDisplayNameNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements setDisplayName in this LDAP Backend.');
@@ -200,8 +198,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testCanChangeAvatar(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'canChangeAvatar'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'canChangeAvatar'])
->getMock();
$plugin->expects($this->any())
@@ -218,7 +216,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->canChangeAvatar('uid');
}
-
+
public function testCanChangeAvatarNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements canChangeAvatar in this LDAP Backend.');
@@ -230,8 +228,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testCountUsers(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'countUsers'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'countUsers'])
->getMock();
$plugin->expects($this->any())
@@ -245,7 +243,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->countUsers();
}
-
+
public function testCountUsersNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements countUsers in this LDAP Backend.');
@@ -257,8 +255,8 @@ class UserLDAPPluginTest extends \Test\TestCase {
public function testDeleteUser(): void {
$pluginManager = $this->getUserPluginManager();
- $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPUserPluginDummy')
- ->setMethods(['respondToActions', 'canDeleteUser','deleteUser'])
+ $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
+ ->onlyMethods(['respondToActions', 'canDeleteUser','deleteUser'])
->getMock();
$plugin->expects($this->any())
@@ -281,7 +279,7 @@ class UserLDAPPluginTest extends \Test\TestCase {
$pluginManager->deleteUser('uid');
}
-
+
public function testDeleteUserNotRegistered(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements deleteUser in this LDAP Backend.');
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index ede7123bd36..5be01d5e414 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,6 +11,7 @@ namespace OCA\User_LDAP\Tests;
use OC\User\Backend;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
+use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\Mapping\AbstractMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
@@ -38,24 +40,15 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class User_LDAPTest extends TestCase {
- /** @var User_LDAP */
- protected $backend;
- /** @var Access|MockObject */
- protected $access;
- /** @var OfflineUser|MockObject */
- protected $offlineUser;
- /** @var INotificationManager|MockObject */
- protected $notificationManager;
- /** @var UserPluginManager|MockObject */
- protected $pluginManager;
- /** @var Connection|MockObject */
- protected $connection;
- /** @var Manager|MockObject */
- protected $userManager;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var DeletedUsersIndex|MockObject */
- protected $deletedUsersIndex;
+ protected Access&MockObject $access;
+ protected OfflineUser&MockObject $offlineUser;
+ protected INotificationManager&MockObject $notificationManager;
+ protected UserPluginManager&MockObject $pluginManager;
+ protected Connection&MockObject $connection;
+ protected Manager&MockObject $userManager;
+ protected LoggerInterface&MockObject $logger;
+ protected DeletedUsersIndex&MockObject $deletedUsersIndex;
+ protected User_LDAP $backend;
protected function setUp(): void {
parent::setUp();
@@ -63,7 +56,9 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->clearBackends();
Server::get(IGroupManager::class)->clearBackends();
- $this->connection = $this->createMock(Connection::class);
+ $this->connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$this->userManager = $this->createMock(Manager::class);
$this->access = $this->createMock(Access::class);
@@ -86,7 +81,7 @@ class User_LDAPTest extends TestCase {
);
}
- private function prepareMockForUserExists() {
+ private function prepareMockForUserExists(): void {
$this->access->expects($this->any())
->method('username2dn')
->willReturnCallback(function ($uid) {
@@ -114,10 +109,8 @@ class User_LDAPTest extends TestCase {
/**
* Prepares the Access mock for checkPassword tests
- * @param bool $noDisplayName
- * @return void
*/
- private function prepareAccessForCheckPassword($noDisplayName = false) {
+ private function prepareAccessForCheckPassword(bool $noDisplayName = false): void {
$this->connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($name) {
@@ -347,7 +340,7 @@ class User_LDAPTest extends TestCase {
->method('invalidate')
->with('uid');
- $this->assertEquals(true, $this->backend->deleteUser('uid'));
+ $this->assertTrue($this->backend->deleteUser('uid'));
}
/**
@@ -404,7 +397,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers();
- $this->assertEquals(3, count($result));
+ $this->assertCount(3, $result);
}
public function testGetUsersLimitOffset(): void {
@@ -412,7 +405,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 1, 2);
- $this->assertEquals(1, count($result));
+ $this->assertCount(1, $result);
}
public function testGetUsersLimitOffset2(): void {
@@ -420,7 +413,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 2, 1);
- $this->assertEquals(2, count($result));
+ $this->assertCount(2, $result);
}
public function testGetUsersSearchWithResult(): void {
@@ -428,7 +421,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('yo');
- $this->assertEquals(2, count($result));
+ $this->assertCount(2, $result);
}
public function testGetUsersSearchEmptyResult(): void {
@@ -436,7 +429,7 @@ class User_LDAPTest extends TestCase {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('nix');
- $this->assertEquals(0, count($result));
+ $this->assertCount(0, $result);
}
private function getUsers($search = '', $limit = null, $offset = null) {
@@ -453,7 +446,7 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers();
- $this->assertEquals(3, count($result));
+ $this->assertCount(3, $result);
}
public function testGetUsersViaAPILimitOffset(): void {
@@ -462,7 +455,7 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('', 1, 2);
- $this->assertEquals(1, count($result));
+ $this->assertCount(1, $result);
}
public function testGetUsersViaAPILimitOffset2(): void {
@@ -471,7 +464,7 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('', 2, 1);
- $this->assertEquals(2, count($result));
+ $this->assertCount(2, $result);
}
public function testGetUsersViaAPISearchWithResult(): void {
@@ -480,7 +473,7 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('yo');
- $this->assertEquals(2, count($result));
+ $this->assertCount(2, $result);
}
public function testGetUsersViaAPISearchEmptyResult(): void {
@@ -489,15 +482,13 @@ class User_LDAPTest extends TestCase {
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('nix');
- $this->assertEquals(0, count($result));
+ $this->assertCount(0, $result);
}
public function testUserExists(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
- $user = $this->createMock(User::class);
-
$this->userManager->expects($this->never())
->method('get');
$this->userManager->expects($this->once())
@@ -1182,8 +1173,6 @@ class User_LDAPTest extends TestCase {
/**
* Prepares the Access mock for setPassword tests
- *
- * @param bool $enablePasswordChange
*/
private function prepareAccessForSetPassword($enablePasswordChange = true) {
$this->connection->expects($this->any())
@@ -1328,7 +1317,7 @@ class User_LDAPTest extends TestCase {
$this->assertEquals($this->backend->setPassword('uid', 'password'), 'result');
}
- public function avatarDataProvider() {
+ public static function avatarDataProvider(): array {
return [
[ 'validImageData', false ],
[ 'corruptImageData', true ],
@@ -1336,8 +1325,10 @@ class User_LDAPTest extends TestCase {
];
}
- /** @dataProvider avatarDataProvider */
- public function testCanChangeAvatar($imageData, $expected): void {
+ /**
+ * @dataProvider avatarDataProvider
+ */
+ public function testCanChangeAvatar(string|bool $imageData, bool $expected): void {
$isValidImage = str_starts_with((string)$imageData, 'valid');
$user = $this->createMock(User::class);
@@ -1451,9 +1442,9 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($this->backend->createUser('uid', 'password'));
}
- public function actionProvider() {
+ public static function actionProvider(): array {
return [
- [ 'ldapUserAvatarRule', 'default', Backend::PROVIDE_AVATAR, true] ,
+ [ 'ldapUserAvatarRule', 'default', Backend::PROVIDE_AVATAR, true],
[ 'ldapUserAvatarRule', 'data:selfiePhoto', Backend::PROVIDE_AVATAR, true],
[ 'ldapUserAvatarRule', 'none', Backend::PROVIDE_AVATAR, false],
[ 'turnOnPasswordChange', 0, Backend::SET_PASSWORD, false],
@@ -1464,7 +1455,7 @@ class User_LDAPTest extends TestCase {
/**
* @dataProvider actionProvider
*/
- public function testImplementsAction($configurable, $value, $actionCode, $expected): void {
+ public function testImplementsAction(string $configurable, string|int $value, int $actionCode, bool $expected): void {
$this->pluginManager->expects($this->once())
->method('getImplementedActions')
->willReturn(0);
diff --git a/apps/user_ldap/tests/User_ProxyTest.php b/apps/user_ldap/tests/User_ProxyTest.php
index 4544276a714..38f94af33a7 100644
--- a/apps/user_ldap/tests/User_ProxyTest.php
+++ b/apps/user_ldap/tests/User_ProxyTest.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
@@ -17,22 +19,14 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class User_ProxyTest extends TestCase {
- /** @var Helper|MockObject */
- protected $helper;
- /** @var ILDAPWrapper|MockObject */
- private $ldapWrapper;
- /** @var AccessFactory|MockObject */
- private $accessFactory;
- /** @var INotificationManager|MockObject */
- private $notificationManager;
- /** @var User_Proxy|MockObject */
- private $proxy;
- /** @var UserPluginManager|MockObject */
- private $userPluginManager;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var DeletedUsersIndex|MockObject */
- protected $deletedUsersIndex;
+ protected Helper&MockObject $helper;
+ private ILDAPWrapper&MockObject $ldapWrapper;
+ private AccessFactory&MockObject $accessFactory;
+ private INotificationManager&MockObject $notificationManager;
+ private User_Proxy&MockObject $proxy;
+ private UserPluginManager&MockObject $userPluginManager;
+ protected LoggerInterface&MockObject $logger;
+ protected DeletedUsersIndex&MockObject $deletedUsersIndex;
protected function setUp(): void {
parent::setUp();
@@ -54,7 +48,7 @@ class User_ProxyTest extends TestCase {
$this->logger,
$this->deletedUsersIndex,
])
- ->setMethods(['handleRequest'])
+ ->onlyMethods(['handleRequest'])
->getMock();
}
diff --git a/apps/user_ldap/tests/WizardTest.php b/apps/user_ldap/tests/WizardTest.php
index 31fd28e2fa1..3ae9a409e88 100644
--- a/apps/user_ldap/tests/WizardTest.php
+++ b/apps/user_ldap/tests/WizardTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -35,32 +36,28 @@ class WizardTest extends TestCase {
}
}
- private function getWizardAndMocks() {
+ private function getWizardAndMocks(): array {
static $confMethods;
- static $connMethods;
- static $accMethods;
if (is_null($confMethods)) {
$confMethods = get_class_methods('\OCA\User_LDAP\Configuration');
- $connMethods = get_class_methods('\OCA\User_LDAP\Connection');
- $accMethods = get_class_methods('\OCA\User_LDAP\Access');
}
- /** @var ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject $lw */
+ /** @var ILDAPWrapper&MockObject $lw */
$lw = $this->createMock(ILDAPWrapper::class);
- /** @var Configuration|\PHPUnit\Framework\MockObject\MockObject $conf */
+ /** @var Configuration&MockObject $conf */
$conf = $this->getMockBuilder(Configuration::class)
- ->setMethods($confMethods)
+ ->onlyMethods($confMethods)
->setConstructorArgs(['', true])
->getMock();
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject $access */
+ /** @var Access&MockObject $access */
$access = $this->createMock(Access::class);
return [new Wizard($conf, $lw, $access), $conf, $lw, $access];
}
- private function prepareLdapWrapperForConnections(MockObject &$ldap) {
+ private function prepareLdapWrapperForConnections(MockObject $ldap) {
$ldap->expects($this->once())
->method('connect')
//dummy value
@@ -346,7 +343,7 @@ class WizardTest extends TestCase {
});
$result = $wizard->detectEmailAttribute();
- $this->assertSame(false, $result->hasChanges());
+ $this->assertFalse($result->hasChanges());
}
public function testCumulativeSearchOnAttributeSkipReadDN(): void {
@@ -423,7 +420,7 @@ class WizardTest extends TestCase {
// The following expectations are the real test
$filters = ['f1', 'f2', '*'];
$resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
- $this->assertSame(6, count($resultArray));
+ $this->assertCount(6, $resultArray);
unset($mark);
}
}