aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/Migration
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/Migration')
-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
4 files changed, 55 insertions, 45 deletions
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();