aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/WizardTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/WizardTest.php')
-rw-r--r--apps/user_ldap/tests/WizardTest.php87
1 files changed, 31 insertions, 56 deletions
diff --git a/apps/user_ldap/tests/WizardTest.php b/apps/user_ldap/tests/WizardTest.php
index 378d549bc27..3ae9a409e88 100644
--- a/apps/user_ldap/tests/WizardTest.php
+++ b/apps/user_ldap/tests/WizardTest.php
@@ -1,32 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Victor Dubiniuk <dubiniuk@owncloud.com>
- * @author Viktor Szépe <viktor@szepe.net>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\Access;
@@ -57,36 +36,32 @@ 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)
- ->setConstructorArgs([$lw, null, null])
+ ->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, usually invalid
- ->willReturn(true);
+ //dummy value
+ ->willReturn(ldap_connect('ldap://example.com'));
$ldap->expects($this->exactly(3))
->method('setOption')
@@ -97,8 +72,8 @@ class WizardTest extends TestCase {
->willReturn(true);
}
- public function testCumulativeSearchOnAttributeLimited() {
- list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
+ public function testCumulativeSearchOnAttributeLimited(): void {
+ [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
$configuration->expects($this->any())
->method('__get')
@@ -157,8 +132,8 @@ class WizardTest extends TestCase {
unset($uidnumber);
}
- public function testCumulativeSearchOnAttributeUnlimited() {
- list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
+ public function testCumulativeSearchOnAttributeUnlimited(): void {
+ [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
$configuration->expects($this->any())
->method('__get')
@@ -174,7 +149,7 @@ class WizardTest extends TestCase {
$ldap->expects($this->any())
->method('isResource')
->willReturnCallback(function ($r) {
- if ($r === true) {
+ if ($r instanceof \LDAP\Connection) {
return true;
}
if ($r % 24 === 0) {
@@ -233,8 +208,8 @@ class WizardTest extends TestCase {
unset($uidnumber);
}
- public function testDetectEmailAttributeAlreadySet() {
- list($wizard, $configuration, $ldap, $access)
+ public function testDetectEmailAttributeAlreadySet(): void {
+ [$wizard, $configuration, $ldap, $access]
= $this->getWizardAndMocks();
$configuration->expects($this->any())
@@ -255,8 +230,8 @@ class WizardTest extends TestCase {
$wizard->detectEmailAttribute();
}
- public function testDetectEmailAttributeOverrideSet() {
- list($wizard, $configuration, $ldap, $access)
+ public function testDetectEmailAttributeOverrideSet(): void {
+ [$wizard, $configuration, $ldap, $access]
= $this->getWizardAndMocks();
$configuration->expects($this->any())
@@ -294,8 +269,8 @@ class WizardTest extends TestCase {
$result['changes']['ldap_email_attr']);
}
- public function testDetectEmailAttributeFind() {
- list($wizard, $configuration, $ldap, $access)
+ public function testDetectEmailAttributeFind(): void {
+ [$wizard, $configuration, $ldap, $access]
= $this->getWizardAndMocks();
$configuration->expects($this->any())
@@ -333,8 +308,8 @@ class WizardTest extends TestCase {
$result['changes']['ldap_email_attr']);
}
- public function testDetectEmailAttributeFindNothing() {
- list($wizard, $configuration, $ldap, $access)
+ public function testDetectEmailAttributeFindNothing(): void {
+ [$wizard, $configuration, $ldap, $access]
= $this->getWizardAndMocks();
$configuration->expects($this->any())
@@ -368,13 +343,13 @@ class WizardTest extends TestCase {
});
$result = $wizard->detectEmailAttribute();
- $this->assertSame(false, $result->hasChanges());
+ $this->assertFalse($result->hasChanges());
}
- public function testCumulativeSearchOnAttributeSkipReadDN() {
+ public function testCumulativeSearchOnAttributeSkipReadDN(): void {
// tests that there is no infinite loop, when skipping already processed
// DNs (they can be returned multiple times for multiple filters )
- list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
+ [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
$configuration->expects($this->any())
->method('__get')
@@ -445,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);
}
}