aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/Core/Command/Apps/AppsDisableTest.php2
-rw-r--r--tests/Core/Command/Apps/AppsEnableTest.php2
-rw-r--r--tests/Core/Command/Config/ImportTest.php12
-rw-r--r--tests/Core/Command/Config/ListConfigsTest.php2
-rw-r--r--tests/Core/Command/Config/System/DeleteConfigTest.php4
-rw-r--r--tests/Core/Command/Config/System/GetConfigTest.php2
-rw-r--r--tests/Core/Command/Config/System/SetConfigTest.php6
-rw-r--r--tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php20
-rw-r--r--tests/Core/Command/Encryption/DecryptAllTest.php39
-rw-r--r--tests/Core/Command/Encryption/DisableTest.php2
-rw-r--r--tests/Core/Command/Encryption/EncryptAllTest.php2
-rw-r--r--tests/Core/Command/Encryption/SetDefaultModuleTest.php14
-rw-r--r--tests/Core/Command/Group/InfoTest.php2
-rw-r--r--tests/Core/Command/Group/ListCommandTest.php2
-rw-r--r--tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php55
-rw-r--r--tests/Core/Command/Maintenance/ModeTest.php2
-rw-r--r--tests/Core/Command/Preview/RepairTest.php15
-rw-r--r--tests/Core/Command/SystemTag/AddTest.php2
-rw-r--r--tests/Core/Command/SystemTag/DeleteTest.php2
-rw-r--r--tests/Core/Command/SystemTag/EditTest.php2
-rw-r--r--tests/Core/Command/SystemTag/ListCommandTest.php2
-rw-r--r--tests/Core/Command/User/AddTest.php2
-rw-r--r--tests/Core/Command/User/DeleteTest.php2
-rw-r--r--tests/Core/Command/User/LastSeenTest.php2
-rw-r--r--tests/Core/Command/User/SettingTest.php8
-rw-r--r--tests/Core/Controller/AutoCompleteControllerTest.php2
-rw-r--r--tests/Core/Controller/ClientFlowLoginControllerTest.php30
-rw-r--r--tests/Core/Controller/LoginControllerTest.php100
-rw-r--r--tests/Core/Controller/LostControllerTest.php34
-rw-r--r--tests/Core/Controller/TwoFactorChallengeControllerTest.php14
-rw-r--r--tests/Core/Controller/WipeControllerTest.php2
-rw-r--r--tests/Core/Middleware/TwoFactorMiddlewareTest.php26
-rw-r--r--tests/Core/Service/LoginFlowV2ServiceUnitTest.php27
-rw-r--r--tests/lib/Collaboration/Collaborators/LookupPluginTest.php59
-rw-r--r--tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php153
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php27
-rw-r--r--tests/lib/DirectEditing/ManagerTest.php25
-rw-r--r--tests/lib/Encryption/DecryptAllTest.php70
-rw-r--r--tests/lib/Encryption/Keys/StorageTest.php38
-rw-r--r--tests/lib/Files/Mount/ObjectHomeMountProviderTest.php14
-rw-r--r--tests/lib/Files/Storage/Wrapper/AvailabilityTest.php12
-rw-r--r--tests/lib/Files/Type/DetectionTest.php36
-rw-r--r--tests/lib/Files/ViewTest.php122
-rw-r--r--tests/lib/Http/Client/ClientTest.php86
-rw-r--r--tests/lib/IntegrityCheck/CheckerTest.php211
-rw-r--r--tests/lib/Share20/ManagerTest.php451
46 files changed, 864 insertions, 880 deletions
diff --git a/tests/Core/Command/Apps/AppsDisableTest.php b/tests/Core/Command/Apps/AppsDisableTest.php
index 8d23ecd1c61..ce43222e44e 100644
--- a/tests/Core/Command/Apps/AppsDisableTest.php
+++ b/tests/Core/Command/Apps/AppsDisableTest.php
@@ -50,7 +50,7 @@ class AppsDisableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}
- public function dataCommandInput(): array {
+ public static function dataCommandInput(): array {
return [
[['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
[['comments'], 0, 'comments ([\d\.]*) disabled'],
diff --git a/tests/Core/Command/Apps/AppsEnableTest.php b/tests/Core/Command/Apps/AppsEnableTest.php
index 5e7a4215286..59b5dad6406 100644
--- a/tests/Core/Command/Apps/AppsEnableTest.php
+++ b/tests/Core/Command/Apps/AppsEnableTest.php
@@ -57,7 +57,7 @@ class AppsEnableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}
- public function dataCommandInput(): array {
+ public static function dataCommandInput(): array {
return [
[['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'],
[['comments'], null, 0, 'comments ([\d\.]*) enabled'],
diff --git a/tests/Core/Command/Config/ImportTest.php b/tests/Core/Command/Config/ImportTest.php
index 0077f84f82b..3cce8cb0243 100644
--- a/tests/Core/Command/Config/ImportTest.php
+++ b/tests/Core/Command/Config/ImportTest.php
@@ -38,7 +38,7 @@ class ImportTest extends TestCase {
$this->command = new Import($config);
}
- public function validateAppsArrayData() {
+ public static function validateAppsArrayData(): array {
return [
[0],
[1],
@@ -58,7 +58,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function validateAppsArrayThrowsData() {
+ public static function validateAppsArrayThrowsData(): array {
return [
[false],
[true],
@@ -81,7 +81,7 @@ class ImportTest extends TestCase {
}
}
- public function checkTypeRecursivelyData() {
+ public static function checkTypeRecursivelyData(): array {
return [
[0],
[1],
@@ -107,7 +107,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function checkTypeRecursivelyThrowsData() {
+ public static function checkTypeRecursivelyThrowsData(): array {
return [
[new \Exception()],
[[new \Exception()]],
@@ -130,7 +130,7 @@ class ImportTest extends TestCase {
}
}
- public function validateArrayData() {
+ public static function validateArrayData(): array {
return [
[['system' => []]],
[['apps' => []]],
@@ -148,7 +148,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function validateArrayThrowsData() {
+ public static function validateArrayThrowsData(): array {
return [
[[], 'At least one key of the following is expected:'],
[[0 => []], 'Found invalid entries in root'],
diff --git a/tests/Core/Command/Config/ListConfigsTest.php b/tests/Core/Command/Config/ListConfigsTest.php
index 0cee870d45c..12a6e6f1cf8 100644
--- a/tests/Core/Command/Config/ListConfigsTest.php
+++ b/tests/Core/Command/Config/ListConfigsTest.php
@@ -46,7 +46,7 @@ class ListConfigsTest extends TestCase {
$this->command = new ListConfigs($systemConfig, $appConfig);
}
- public function listData() {
+ public static function listData(): array {
return [
[
'all',
diff --git a/tests/Core/Command/Config/System/DeleteConfigTest.php b/tests/Core/Command/Config/System/DeleteConfigTest.php
index 872079ef4c2..31e238573d0 100644
--- a/tests/Core/Command/Config/System/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/System/DeleteConfigTest.php
@@ -38,7 +38,7 @@ class DeleteConfigTest extends TestCase {
$this->command = new DeleteConfig($systemConfig);
}
- public function deleteData() {
+ public static function deleteData(): array {
return [
[
'name1',
@@ -105,7 +105,7 @@ class DeleteConfigTest extends TestCase {
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
- public function deleteArrayData() {
+ public static function deleteArrayData(): array {
return [
[
['name', 'sub'],
diff --git a/tests/Core/Command/Config/System/GetConfigTest.php b/tests/Core/Command/Config/System/GetConfigTest.php
index f05d0e384ee..daaee5605b7 100644
--- a/tests/Core/Command/Config/System/GetConfigTest.php
+++ b/tests/Core/Command/Config/System/GetConfigTest.php
@@ -39,7 +39,7 @@ class GetConfigTest extends TestCase {
}
- public function getData() {
+ public static function getData(): array {
return [
// String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],
diff --git a/tests/Core/Command/Config/System/SetConfigTest.php b/tests/Core/Command/Config/System/SetConfigTest.php
index 6ab624b7918..cfe93a15eaf 100644
--- a/tests/Core/Command/Config/System/SetConfigTest.php
+++ b/tests/Core/Command/Config/System/SetConfigTest.php
@@ -76,7 +76,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function setUpdateOnlyProvider() {
+ public static function setUpdateOnlyProvider(): array {
return [
[['name'], null],
[['a', 'b', 'c'], null],
@@ -113,7 +113,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function castValueProvider() {
+ public static function castValueProvider(): array {
return [
[null, 'string', ['value' => '', 'readable-value' => 'empty string']],
@@ -141,7 +141,7 @@ class SetConfigTest extends TestCase {
);
}
- public function castValueInvalidProvider() {
+ public static function castValueInvalidProvider(): array {
return [
['123', 'foobar'],
diff --git a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
index b124a27f9ab..8232db70504 100644
--- a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
+++ b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
@@ -89,7 +89,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
- )->setMethods(['moveAllKeys'])->getMock();
+ )->onlyMethods(['moveAllKeys'])->getMock();
$this->util->expects($this->once())->method('getKeyStorageRoot')
->willReturn('');
@@ -122,7 +122,7 @@ class ChangeKeyStorageRootTest extends TestCase {
);
}
- public function dataTestExecute() {
+ public static function dataTestExecute(): array {
return [
[null, true, true],
[null, true, false],
@@ -143,7 +143,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
- )->setMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
+ )->onlyMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
$changeKeyStorageRoot->expects($this->once())->method('prepareNewRoot')->with('newRoot');
$changeKeyStorageRoot->expects($this->once())->method('moveSystemKeys')->with('oldRoot', 'newRoot');
@@ -179,7 +179,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
}
- public function dataTestPrepareNewRootException() {
+ public static function dataTestPrepareNewRootException(): array {
return [
[true, false],
[true, null],
@@ -204,7 +204,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
- )->setMethods(['targetExists'])->getMock();
+ )->onlyMethods(['targetExists'])->getMock();
$this->view->expects($this->once())->method('is_dir')
->with('oldRoot/files_encryption')->willReturn($dirExists);
@@ -221,7 +221,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveSystemKeys', ['oldRoot', 'newRoot']);
}
- public function dataTestMoveSystemKeys() {
+ public static function dataTestMoveSystemKeys(): array {
return [
[true, false, true],
[false, true, false],
@@ -241,7 +241,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
- )->setMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
+ )->onlyMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
$this->userManager->expects($this->once())->method('getBackends')
->willReturn([$this->userInterface]);
@@ -271,7 +271,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
- )->setMethods(['targetExists', 'prepareParentFolder'])->getMock();
+ )->onlyMethods(['targetExists', 'prepareParentFolder'])->getMock();
$this->userManager->expects($this->once())->method('userExists')
->willReturn($userExists);
@@ -293,7 +293,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveUserEncryptionFolder', ['user1', 'oldRoot', 'newRoot']);
}
- public function dataTestMoveUserEncryptionFolder() {
+ public static function dataTestMoveUserEncryptionFolder(): array {
return [
[true, true, false, true],
[true, false, true, false],
@@ -334,7 +334,7 @@ class ChangeKeyStorageRootTest extends TestCase {
);
}
- public function dataTestPrepareParentFolder() {
+ public static function dataTestPrepareParentFolder(): array {
return [
['/user/folder/sub_folder/keystorage', true],
['/user/folder/sub_folder/keystorage', false]
diff --git a/tests/Core/Command/Encryption/DecryptAllTest.php b/tests/Core/Command/Encryption/DecryptAllTest.php
index 6ed4cbbea99..45b331efb59 100644
--- a/tests/Core/Command/Encryption/DecryptAllTest.php
+++ b/tests/Core/Command/Encryption/DecryptAllTest.php
@@ -73,12 +73,16 @@ class DecryptAllTest extends TestCase {
public function testMaintenanceAndTrashbin(): void {
// on construct we enable single-user-mode and disable the trash bin
// on destruct we disable single-user-mode again and enable the trash bin
+ $calls = [
+ ['maintenance', true],
+ ['maintenance', false],
+ ];
$this->config->expects($this->exactly(2))
->method('setSystemValue')
- ->withConsecutive(
- ['maintenance', true],
- ['maintenance', false],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->appManager->expects($this->once())
->method('disableApp')
->with('files_trashbin');
@@ -127,12 +131,16 @@ class DecryptAllTest extends TestCase {
->willReturn('user1');
if ($encryptionEnabled) {
+ $calls = [
+ ['core', 'encryption_enabled', 'no'],
+ ['core', 'encryption_enabled', 'yes'],
+ ];
$this->config->expects($this->exactly(2))
->method('setAppValue')
- ->withConsecutive(
- ['core', 'encryption_enabled', 'no'],
- ['core', 'encryption_enabled', 'yes'],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->questionHelper->expects($this->once())
->method('ask')
->willReturn($continue);
@@ -152,7 +160,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function dataTestExecute() {
+ public static function dataTestExecute(): array {
return [
[true, true],
[true, false],
@@ -174,13 +182,16 @@ class DecryptAllTest extends TestCase {
);
// make sure that we enable encryption again after a exception was thrown
+ $calls = [
+ ['core', 'encryption_enabled', 'no'],
+ ['core', 'encryption_enabled', 'yes'],
+ ];
$this->config->expects($this->exactly(2))
->method('setAppValue')
- ->withConsecutive(
- ['core', 'encryption_enabled', 'no'],
- ['core', 'encryption_enabled', 'yes'],
- );
-
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->encryptionManager->expects($this->once())
->method('isEnabled')
->willReturn(true);
diff --git a/tests/Core/Command/Encryption/DisableTest.php b/tests/Core/Command/Encryption/DisableTest.php
index 913d03a8850..4cbc92a5f8a 100644
--- a/tests/Core/Command/Encryption/DisableTest.php
+++ b/tests/Core/Command/Encryption/DisableTest.php
@@ -38,7 +38,7 @@ class DisableTest extends TestCase {
}
- public function dataDisable() {
+ public static function dataDisable(): array {
return [
['yes', true, 'Encryption disabled'],
['no', false, 'Encryption is already disabled'],
diff --git a/tests/Core/Command/Encryption/EncryptAllTest.php b/tests/Core/Command/Encryption/EncryptAllTest.php
index 6e72e87b973..1c59a3705af 100644
--- a/tests/Core/Command/Encryption/EncryptAllTest.php
+++ b/tests/Core/Command/Encryption/EncryptAllTest.php
@@ -99,7 +99,7 @@ class EncryptAllTest extends TestCase {
$this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function dataTestExecute() {
+ public static function dataTestExecute(): array {
return [
['y', true], ['Y', true], ['n', false], ['N', false], ['', false]
];
diff --git a/tests/Core/Command/Encryption/SetDefaultModuleTest.php b/tests/Core/Command/Encryption/SetDefaultModuleTest.php
index 0a2c2a81c28..52f14dd4537 100644
--- a/tests/Core/Command/Encryption/SetDefaultModuleTest.php
+++ b/tests/Core/Command/Encryption/SetDefaultModuleTest.php
@@ -43,7 +43,7 @@ class SetDefaultModuleTest extends TestCase {
}
- public function dataSetDefaultModule() {
+ public static function dataSetDefaultModule(): array {
return [
['ID0', 'ID0', null, null, 'already'],
['ID0', 'ID1', 'ID1', true, 'info'],
@@ -113,12 +113,16 @@ class SetDefaultModuleTest extends TestCase {
->with('maintenance', false)
->willReturn(true);
+ $calls = [
+ 'Maintenance mode must be disabled when setting default module,',
+ 'in order to load the relevant encryption modules correctly.',
+ ];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
- ->withConsecutive(
- [$this->stringContains('Maintenance mode must be disabled when setting default module,')],
- [$this->stringContains('in order to load the relevant encryption modules correctly.')],
- );
+ ->willReturnCallback(function ($message) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
diff --git a/tests/Core/Command/Group/InfoTest.php b/tests/Core/Command/Group/InfoTest.php
index 869b6741866..ffd716f502d 100644
--- a/tests/Core/Command/Group/InfoTest.php
+++ b/tests/Core/Command/Group/InfoTest.php
@@ -32,7 +32,7 @@ class InfoTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(Info::class)
->setConstructorArgs([$this->groupManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/Group/ListCommandTest.php b/tests/Core/Command/Group/ListCommandTest.php
index 93d472af388..72cf44aa113 100644
--- a/tests/Core/Command/Group/ListCommandTest.php
+++ b/tests/Core/Command/Group/ListCommandTest.php
@@ -33,7 +33,7 @@ class ListCommandTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->groupManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
index d8c82de19ac..2f232837fe2 100644
--- a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
+++ b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
@@ -33,15 +33,10 @@ class UpdateDBTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->detector = $this->getMockBuilder(Detection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->loader = $this->getMockBuilder(Loader::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->detector = $this->createMock(Detection::class);
+ $this->loader = $this->createMock(Loader::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
$this->command = new UpdateDB($this->detector, $this->loader);
}
@@ -64,12 +59,16 @@ class UpdateDBTest extends TestCase {
$this->loader->expects($this->never())
->method('updateFilecache');
+ $calls = [
+ 'Added 0 new mimetypes',
+ 'Updated 0 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
- ->withConsecutive(
- ['Added 0 new mimetypes'],
- ['Updated 0 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
@@ -103,14 +102,18 @@ class UpdateDBTest extends TestCase {
->with('new', 2)
->willReturn(3);
+ $calls = [
+ 'Added mimetype "testing/newmimetype" to database',
+ 'Updated 3 filecache rows for mimetype "testing/newmimetype"',
+ 'Added 1 new mimetypes',
+ 'Updated 3 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(4))
->method('writeln')
- ->withConsecutive(
- ['Added mimetype "testing/newmimetype" to database'],
- ['Updated 3 filecache rows for mimetype "testing/newmimetype"'],
- ['Added 1 new mimetypes'],
- ['Updated 3 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
@@ -153,13 +156,17 @@ class UpdateDBTest extends TestCase {
->with('ext', 1)
->willReturn(3);
+ $calls = [
+ 'Updated 3 filecache rows for mimetype "testing/existingmimetype"',
+ 'Added 0 new mimetypes',
+ 'Updated 3 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(3))
->method('writeln')
- ->withConsecutive(
- ['Updated 3 filecache rows for mimetype "testing/existingmimetype"'],
- ['Added 0 new mimetypes'],
- ['Updated 3 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
diff --git a/tests/Core/Command/Maintenance/ModeTest.php b/tests/Core/Command/Maintenance/ModeTest.php
index a4c33474745..85efbffdc0b 100644
--- a/tests/Core/Command/Maintenance/ModeTest.php
+++ b/tests/Core/Command/Maintenance/ModeTest.php
@@ -67,7 +67,7 @@ class ModeTest extends TestCase {
*
* @return array
*/
- public function getExecuteTestData(): array {
+ public static function getExecuteTestData(): array {
return [
'off -> on' => [
'on', // command option
diff --git a/tests/Core/Command/Preview/RepairTest.php b/tests/Core/Command/Preview/RepairTest.php
index e54f4dde3ad..d522816e531 100644
--- a/tests/Core/Command/Preview/RepairTest.php
+++ b/tests/Core/Command/Preview/RepairTest.php
@@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -54,8 +55,7 @@ class RepairTest extends TestCase {
$this->iniGetWrapper,
$this->createMock(ILockingProvider::class)
);
- $this->input = $this->getMockBuilder(InputInterface::class)
- ->getMock();
+ $this->input = $this->createMock(InputInterface::class);
$this->input->expects($this->any())
->method('getOption')
->willReturnCallback(function ($parameter) {
@@ -64,13 +64,10 @@ class RepairTest extends TestCase {
}
return null;
});
- $this->output = $this->getMockBuilder(OutputInterface::class)
- ->setMethods(['section', 'writeln', 'write', 'setVerbosity', 'getVerbosity', 'isQuiet', 'isVerbose', 'isVeryVerbose', 'isDebug', 'setDecorated', 'isDecorated', 'setFormatter', 'getFormatter'])
+ $this->output = $this->getMockBuilder(ConsoleOutput::class)
+ ->onlyMethods(['section', 'writeln', 'getFormatter'])
->getMock();
$self = $this;
- $this->output->expects($this->any())
- ->method('section')
- ->willReturn($this->output);
/* We need format method to return a string */
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
@@ -87,7 +84,7 @@ class RepairTest extends TestCase {
});
}
- public function emptyTestDataProvider() {
+ public static function dataEmptyTest(): array {
/** directoryNames, expectedOutput */
return [
[
@@ -114,7 +111,7 @@ class RepairTest extends TestCase {
}
/**
- * @dataProvider emptyTestDataProvider
+ * @dataProvider dataEmptyTest
*/
public function testEmptyExecute($directoryNames, $expectedOutput): void {
$previewFolder = $this->getMockBuilder(Folder::class)
diff --git a/tests/Core/Command/SystemTag/AddTest.php b/tests/Core/Command/SystemTag/AddTest.php
index 7ae832e4079..b697cd1d2f0 100644
--- a/tests/Core/Command/SystemTag/AddTest.php
+++ b/tests/Core/Command/SystemTag/AddTest.php
@@ -33,7 +33,7 @@ class AddTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Add::class)
->setConstructorArgs([$this->systemTagManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/SystemTag/DeleteTest.php b/tests/Core/Command/SystemTag/DeleteTest.php
index 78d073db6d6..3c7a6e24c21 100644
--- a/tests/Core/Command/SystemTag/DeleteTest.php
+++ b/tests/Core/Command/SystemTag/DeleteTest.php
@@ -32,7 +32,7 @@ class DeleteTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Delete::class)
->setConstructorArgs([$this->systemTagManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php
index 0d2f6ba4fbc..637172222eb 100644
--- a/tests/Core/Command/SystemTag/EditTest.php
+++ b/tests/Core/Command/SystemTag/EditTest.php
@@ -33,7 +33,7 @@ class EditTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Edit::class)
->setConstructorArgs([$this->systemTagManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/SystemTag/ListCommandTest.php b/tests/Core/Command/SystemTag/ListCommandTest.php
index 9f4c4072ffc..a2c52a03244 100644
--- a/tests/Core/Command/SystemTag/ListCommandTest.php
+++ b/tests/Core/Command/SystemTag/ListCommandTest.php
@@ -32,7 +32,7 @@ class ListCommandTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->systemTagManager])
- ->setMethods(['writeArrayInOutputFormat'])
+ ->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);
diff --git a/tests/Core/Command/User/AddTest.php b/tests/Core/Command/User/AddTest.php
index 7a956c173c1..91535ea6670 100644
--- a/tests/Core/Command/User/AddTest.php
+++ b/tests/Core/Command/User/AddTest.php
@@ -126,7 +126,7 @@ class AddTest extends TestCase {
/**
* @return array
*/
- public function addEmailDataProvider(): array {
+ public static function addEmailDataProvider(): array {
return [
'Valid E-Mail' => [
'info@example.com',
diff --git a/tests/Core/Command/User/DeleteTest.php b/tests/Core/Command/User/DeleteTest.php
index 42244412d9f..010b8580819 100644
--- a/tests/Core/Command/User/DeleteTest.php
+++ b/tests/Core/Command/User/DeleteTest.php
@@ -39,7 +39,7 @@ class DeleteTest extends TestCase {
}
- public function validUserLastSeen() {
+ public static function validUserLastSeen(): array {
return [
[true, 'The specified user was deleted'],
[false, 'The specified user could not be deleted'],
diff --git a/tests/Core/Command/User/LastSeenTest.php b/tests/Core/Command/User/LastSeenTest.php
index 014c981112e..b64b0e73ced 100644
--- a/tests/Core/Command/User/LastSeenTest.php
+++ b/tests/Core/Command/User/LastSeenTest.php
@@ -38,7 +38,7 @@ class LastSeenTest extends TestCase {
$this->command = new LastSeen($userManager);
}
- public function validUserLastSeen() {
+ public static function validUserLastSeen(): array {
return [
[0, 'never logged in'],
[time(), 'last login'],
diff --git a/tests/Core/Command/User/SettingTest.php b/tests/Core/Command/User/SettingTest.php
index 62b75191d36..e9e150b78de 100644
--- a/tests/Core/Command/User/SettingTest.php
+++ b/tests/Core/Command/User/SettingTest.php
@@ -62,7 +62,7 @@ class SettingTest extends TestCase {
}
}
- public function dataCheckInput() {
+ public static function dataCheckInput(): array {
return [
[
[['uid', 'username']],
@@ -235,7 +235,7 @@ class SettingTest extends TestCase {
$this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
- public function dataExecuteDelete() {
+ public static function dataExecuteDelete(): array {
return [
['config', false, null, 0],
['config', true, null, 0],
@@ -299,7 +299,7 @@ class SettingTest extends TestCase {
$this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
- public function dataExecuteSet() {
+ public static function dataExecuteSet(): array {
return [
['config', false, null, 0],
['config', true, null, 0],
@@ -367,7 +367,7 @@ class SettingTest extends TestCase {
$this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
- public function dataExecuteGet() {
+ public static function dataExecuteGet(): array {
return [
['config', null, 'config', 0],
[null, 'config', 'config', 0],
diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php
index 23bd03be7af..23fd0ac8399 100644
--- a/tests/Core/Controller/AutoCompleteControllerTest.php
+++ b/tests/Core/Controller/AutoCompleteControllerTest.php
@@ -42,7 +42,7 @@ class AutoCompleteControllerTest extends TestCase {
);
}
- public function searchDataProvider() {
+ public static function searchDataProvider(): array {
return [
[ #0 – regular search
// searchResults
diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php
index 591a3027e96..b10055ef542 100644
--- a/tests/Core/Controller/ClientFlowLoginControllerTest.php
+++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php
@@ -118,10 +118,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOcsHeader(): void {
$this->request
->method('getHeader')
- ->withConsecutive(
- ['USER_AGENT'],
- ['OCS-APIREQUEST']
- )
->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'true'],
@@ -181,10 +177,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOauth(): void {
$this->request
->method('getHeader')
- ->withConsecutive(
- ['USER_AGENT'],
- ['OCS-APIREQUEST']
- )
->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'false'],
@@ -404,20 +396,20 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl): void {
$this->session
->method('get')
- ->withConsecutive(
- ['client.flow.state.token'],
- ['oauth.state']
- )
->willReturnMap([
['client.flow.state.token', 'MyStateToken'],
['oauth.state', 'MyOauthState'],
]);
+ $calls = [
+ 'client.flow.state.token',
+ 'oauth.state',
+ ];
$this->session
->method('remove')
- ->withConsecutive(
- ['client.flow.state.token'],
- ['oauth.state']
- );
+ ->willReturnCallback(function ($key) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $key);
+ });
$this->session
->expects($this->once())
->method('getId')
@@ -439,10 +431,6 @@ class ClientFlowLoginControllerTest extends TestCase {
->willReturn('MyPassword');
$this->random
->method('generate')
- ->withConsecutive(
- [72],
- [128]
- )
->willReturnMap([
[72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'],
[128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyAccessCode'],
@@ -561,7 +549,7 @@ class ClientFlowLoginControllerTest extends TestCase {
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
- public function dataGeneratePasswordWithHttpsProxy() {
+ public static function dataGeneratePasswordWithHttpsProxy(): array {
return [
[
[
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php
index a6438a35af0..d049203c302 100644
--- a/tests/Core/Controller/LoginControllerTest.php
+++ b/tests/Core/Controller/LoginControllerTest.php
@@ -255,9 +255,9 @@ class LoginControllerTest extends TestCase {
],
]
);
- $this->initialState->expects($this->exactly(13))
- ->method('provideInitialState')
- ->withConsecutive([
+
+ $calls = [
+ [
'loginMessages',
[
'MessageArray1',
@@ -265,17 +265,26 @@ class LoginControllerTest extends TestCase {
'This community release of Nextcloud is unsupported and push notifications are limited.',
],
],
+ [
+ 'loginErrors',
[
- 'loginErrors',
- [
- 'ErrorArray1',
- 'ErrorArray2',
- ],
+ 'ErrorArray1',
+ 'ErrorArray2',
],
- [
- 'loginUsername',
- '',
- ]);
+ ],
+ [
+ 'loginUsername',
+ '',
+ ]
+ ];
+ $this->initialState->expects($this->exactly(13))
+ ->method('provideInitialState')
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ if (!empty($expected)) {
+ $this->assertEquals($expected, func_get_args());
+ }
+ });
$expectedResponse = new TemplateResponse(
'core',
@@ -294,15 +303,25 @@ class LoginControllerTest extends TestCase {
->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
- $this->initialState->expects($this->exactly(14))
- ->method('provideInitialState')
- ->withConsecutive([], [], [], [
+ $calls = [
+ [], [], [],
+ [
'loginAutocomplete',
false
- ], [
+ ],
+ [
'loginRedirectUrl',
'login/flow'
- ]);
+ ],
+ ];
+ $this->initialState->expects($this->exactly(14))
+ ->method('provideInitialState')
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ if (!empty($expected)) {
+ $this->assertEquals($expected, func_get_args());
+ }
+ });
$expectedResponse = new TemplateResponse(
'core',
@@ -319,7 +338,7 @@ class LoginControllerTest extends TestCase {
/**
* @return array
*/
- public function passwordResetDataProvider(): array {
+ public static function passwordResetDataProvider(): array {
return [
[
true,
@@ -363,15 +382,26 @@ class LoginControllerTest extends TestCase {
->method('get')
->with('LdapUser')
->willReturn($user);
- $this->initialState->expects($this->exactly(13))
- ->method('provideInitialState')
- ->withConsecutive([], [], [
+ $calls = [
+ [], [],
+ [
'loginUsername',
'LdapUser'
- ], [], [], [], [
+ ],
+ [], [], [],
+ [
'loginCanResetPassword',
$expectedResult
- ]);
+ ],
+ ];
+ $this->initialState->expects($this->exactly(13))
+ ->method('provideInitialState')
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ if (!empty($expected)) {
+ $this->assertEquals($expected, func_get_args());
+ }
+ });
$expectedResponse = new TemplateResponse(
'core',
@@ -411,18 +441,30 @@ class LoginControllerTest extends TestCase {
->method('get')
->with('0')
->willReturn($user);
- $this->initialState->expects($this->exactly(13))
- ->method('provideInitialState')
- ->withConsecutive([], [], [], [
+ $calls = [
+ [], [], [],
+ [
'loginAutocomplete',
true
- ], [], [
+ ],
+ [],
+ [
'loginResetPasswordLink',
false
- ], [
+ ],
+ [
'loginCanResetPassword',
false
- ]);
+ ],
+ ];
+ $this->initialState->expects($this->exactly(13))
+ ->method('provideInitialState')
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ if (!empty($expected)) {
+ $this->assertEquals($expected, func_get_args());
+ }
+ });
$expectedResponse = new TemplateResponse(
'core',
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php
index 2a99c9f9d16..ffe3eb3920d 100644
--- a/tests/Core/Controller/LostControllerTest.php
+++ b/tests/Core/Controller/LostControllerTest.php
@@ -172,13 +172,18 @@ class LostControllerTest extends TestCase {
->method('linkToRouteAbsolute')
->with('core.lost.setPassword', ['userId' => 'ValidTokenUser', 'token' => 'MySecretToken'])
->willReturn('https://example.tld/index.php/lostpassword/set/sometoken/someuser');
+
+ $calls = [
+ ['resetPasswordUser', 'ValidTokenUser'],
+ ['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser'],
+ ];
$this->initialState
->expects($this->exactly(2))
->method('provideInitialState')
- ->withConsecutive(
- ['resetPasswordUser', 'ValidTokenUser'],
- ['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser']
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$response = $this->lostController->resetform('MySecretToken', 'ValidTokenUser');
$expectedResponse = new TemplateResponse('core',
@@ -448,12 +453,19 @@ class LostControllerTest extends TestCase {
$this->userManager->method('get')
->with('ValidTokenUser')
->willReturn($this->existingUser);
- $beforePasswordResetEvent = new BeforePasswordResetEvent($this->existingUser, 'NewPassword');
- $passwordResetEvent = new PasswordResetEvent($this->existingUser, 'NewPassword');
+
+ $calls = [
+ [new BeforePasswordResetEvent($this->existingUser, 'NewPassword')],
+ [new PasswordResetEvent($this->existingUser, 'NewPassword')],
+ ];
$this->eventDispatcher
->expects($this->exactly(2))
->method('dispatchTyped')
- ->withConsecutive([$beforePasswordResetEvent], [$passwordResetEvent]);
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
+
$this->config->expects($this->once())
->method('deleteUserValue')
->with('ValidTokenUser', 'core', 'lostpassword');
@@ -666,15 +678,15 @@ class LostControllerTest extends TestCase {
/**
* @return array
*/
- public function dataTwoUserswithSameEmailOneDisabled(): array {
+ public static function dataTwoUsersWithSameEmailOneDisabled(): array {
return [
- ['user1' => true, 'user2' => false],
- ['user1' => false, 'user2' => true]
+ ['userEnabled1' => true, 'userEnabled2' => false],
+ ['userEnabled1' => false, 'userEnabled2' => true]
];
}
/**
- * @dataProvider dataTwoUserswithSameEmailOneDisabled
+ * @dataProvider dataTwoUsersWithSameEmailOneDisabled
* @param bool $userEnabled1
* @param bool $userEnabled2
*/
diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
index 7498abb9a9e..97900191199 100644
--- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php
+++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
@@ -68,7 +68,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->urlGenerator,
$this->logger,
])
- ->setMethods(['getLogoutUrl'])
+ ->onlyMethods(['getLogoutUrl'])
->getMock();
$this->controller->expects($this->any())
->method('getLogoutUrl')
@@ -302,12 +302,16 @@ class TwoFactorChallengeControllerTest extends TestCase {
->method('verifyChallenge')
->with('myprovider', $user, 'token')
->will($this->throwException($exception));
+ $calls = [
+ ['two_factor_auth_error_message', '2FA failed'],
+ ['two_factor_auth_error', true],
+ ];
$this->session->expects($this->exactly(2))
->method('set')
- ->withConsecutive(
- ['two_factor_auth_error_message', '2FA failed'],
- ['two_factor_auth_error', true]
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.TwoFactorChallenge.showChallenge', [
diff --git a/tests/Core/Controller/WipeControllerTest.php b/tests/Core/Controller/WipeControllerTest.php
index 2cd315db5bf..fa5f98988e7 100644
--- a/tests/Core/Controller/WipeControllerTest.php
+++ b/tests/Core/Controller/WipeControllerTest.php
@@ -33,7 +33,7 @@ class WipeControllerTest extends TestCase {
$this->remoteWipe);
}
- public function dataTest() {
+ public static function dataTest(): array {
return [
// valid token, could perform operation, valid result
[ true, true, true],
diff --git a/tests/Core/Middleware/TwoFactorMiddlewareTest.php b/tests/Core/Middleware/TwoFactorMiddlewareTest.php
index 6b8bf1c76e0..2d778a740dc 100644
--- a/tests/Core/Middleware/TwoFactorMiddlewareTest.php
+++ b/tests/Core/Middleware/TwoFactorMiddlewareTest.php
@@ -234,23 +234,29 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($twoFactorChallengeController, 'index');
}
- public function dataRequires2FASetupDone() {
- $provider = $this->createMock(IProvider::class);
- $provider->method('getId')
- ->willReturn('2FAftw');
-
+ public static function dataRequires2FASetupDone(): array {
return [
- [[], false, false],
- [[], true, true],
- [[$provider], false, true],
- [[$provider], true, true],
+ [false, false, false],
+ [false, true, true],
+ [true, false, true],
+ [true, true, true],
];
}
/**
* @dataProvider dataRequires2FASetupDone
*/
- public function testRequires2FASetupDone(array $providers, bool $missingProviders, bool $expectEception): void {
+ public function testRequires2FASetupDone(bool $hasProvider, bool $missingProviders, bool $expectEception): void {
+ if ($hasProvider) {
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getId')
+ ->willReturn('2FAftw');
+ $providers = [$provider];
+ } else {
+ $providers = [];
+ }
+
+
$user = $this->createMock(IUser::class);
$this->reflector
diff --git a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php
index 8118106c722..149990f4df1 100644
--- a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php
+++ b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php
@@ -67,26 +67,13 @@ class LoginFlowV2ServiceUnitTest extends TestCase {
* Code was moved to separate function to keep setUp function small and clear.
*/
private function setupSubjectUnderTest(): void {
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->crypto = $this->getMockBuilder(ICrypto::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->mapper = $this->getMockBuilder(LoginFlowV2Mapper::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->logger = $this->getMockBuilder(LoggerInterface::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->tokenProvider = $this->getMockBuilder(IProvider::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->secureRandom = $this->getMockBuilder(ISecureRandom::class)
- ->disableOriginalConstructor()->getMock();
-
- $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)
- ->disableOriginalConstructor()->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->crypto = $this->createMock(ICrypto::class);
+ $this->mapper = $this->createMock(LoginFlowV2Mapper::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->tokenProvider = $this->createMock(IProvider::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->subjectUnderTest = new LoginFlowV2Service(
$this->mapper,
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
index 7ff01831e18..d74dfca3be9 100644
--- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
@@ -76,13 +76,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['gs.enabled', false],
- ['has_internet_connection', true],
- )->willReturnOnConsecutiveCalls(
- true,
- true,
- );
+ ->willReturnMap([
+ ['gs.enabled', false, true],
+ ['has_internet_connection', true, true],
+ ]);
$this->config->expects($this->once())
->method('getSystemValueString')
@@ -105,13 +102,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['gs.enabled', false],
- ['has_internet_connection', true],
- )->willReturnOnConsecutiveCalls(
- false,
- false,
- );
+ ->willReturnMap([
+ ['gs.enabled', false, false],
+ ['has_internet_connection', true, false],
+ ]);
$this->clientService->expects($this->never())
->method('newClient');
@@ -141,13 +135,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['gs.enabled', false],
- ['has_internet_connection', true],
- )->willReturnOnConsecutiveCalls(
- true,
- true,
- );
+ ->willReturnMap([
+ ['gs.enabled', false, true],
+ ['has_internet_connection', true, true],
+ ]);
$this->config->expects($this->once())
->method('getSystemValueString')
@@ -206,13 +197,10 @@ class LookupPluginTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['gs.enabled', false],
- ['has_internet_connection', true],
- )->willReturnOnConsecutiveCalls(
- $GSEnabled,
- true,
- );
+ ->willReturnMap([
+ ['gs.enabled', false, $GSEnabled],
+ ['has_internet_connection', true, true],
+ ]);
$this->config->expects($this->once())
->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com')
@@ -239,13 +227,10 @@ class LookupPluginTest extends TestCase {
$searchResult->expects($this->never())->method('addResultSet');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['gs.enabled', false],
- ['has_internet_connection', true],
- )->willReturnOnConsecutiveCalls(
- $GSEnabled,
- true,
- );
+ ->willReturnMap([
+ ['gs.enabled', false, $GSEnabled],
+ ['has_internet_connection', true, true],
+ ]);
}
$moreResults = $this->plugin->search(
$searchParams['search'],
@@ -276,7 +261,7 @@ class LookupPluginTest extends TestCase {
$this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult));
}
- public function dataSearchEnableDisableLookupServer() {
+ public static function dataSearchEnableDisableLookupServer(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',
@@ -449,7 +434,7 @@ class LookupPluginTest extends TestCase {
];
}
- public function searchDataProvider() {
+ public static function searchDataProvider(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
index a3151d0b040..9097ee779d2 100644
--- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
@@ -255,29 +255,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->contactsManager->expects($this->once())
->method('search')
@@ -330,29 +328,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturn($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->contactsManager->expects($this->once())
->method('search')
@@ -463,29 +459,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -542,16 +536,17 @@ class ContactsStoreTest extends TestCase {
$user1 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ ];
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->once())
->method('get')
@@ -617,29 +612,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
+ $calls = [
+ [[$currentUser], ['group1', 'group2', 'group3']],
+ [[$user1], ['group1']],
+ [[$user2], ['group2', 'group3']],
+ [[$user3], ['group8', 'group9']],
+ ];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->withConsecutive(
- [$this->equalTo($currentUser)],
- [$this->equalTo($user1)],
- [$this->equalTo($user2)],
- [$this->equalTo($user3)]
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2', 'group3'],
- ['group1'],
- ['group2', 'group3'],
- ['group8', 'group9']
- );
+ ->willReturnCallback(function () use (&$calls): array {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected[0], func_get_args());
+ return $expected[1];
+ });
$this->userManager->expects($this->exactly(3))
->method('get')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- ['user3']
- )
- ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
+ ->willReturnMap([
+ ['user1', $user1],
+ ['user2', $user2],
+ ['user3', $user3],
+ ]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
index c87bb3d5147..dd6c634c740 100644
--- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -65,11 +65,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(25, 0);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 25],
+ ['sharing.minSearchStringLength', 0, 0],
+ ]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -102,11 +101,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(3, 0);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
+ ['sharing.minSearchStringLength', 0, 0],
+ ]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -138,11 +136,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->withConsecutive(
- ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
- ['sharing.minSearchStringLength', 0]
- )
- ->willReturnOnConsecutiveCalls(3, 4);
+ ->willReturnMap([
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
+ ['sharing.minSearchStringLength', 0, 4],
+ ]);
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user)
diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php
index d26817438cf..e09a87e448e 100644
--- a/tests/lib/DirectEditing/ManagerTest.php
+++ b/tests/lib/DirectEditing/ManagerTest.php
@@ -173,8 +173,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
@@ -198,8 +200,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
@@ -226,11 +230,12 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
- $folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/File.txt')
@@ -277,8 +282,10 @@ class ManagerTest extends TestCase {
]);
$this->userFolder
->method('nodeExists')
- ->withConsecutive(['/File.txt'], ['/'])
- ->willReturnOnConsecutiveCalls(false, true);
+ ->willReturnMap([
+ ['/File.txt', false],
+ ['/', true],
+ ]);
$this->userFolder
->method('get')
->with('/')
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php
index 6a8453bcaf8..7385ff03785 100644
--- a/tests/lib/Encryption/DecryptAllTest.php
+++ b/tests/lib/Encryption/DecryptAllTest.php
@@ -82,7 +82,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($this->instance, 'output', [$this->outputInterface]);
}
- public function dataDecryptAll() {
+ public static function dataDecryptAll(): array {
return [
[true, 'user1', true],
[false, 'user1', true],
@@ -113,7 +113,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
- ->setMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
+ ->onlyMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
->getMock();
$instance->expects($this->once())
@@ -145,7 +145,7 @@ class DecryptAllTest extends TestCase {
);
}
- public function dataTrueFalse() {
+ public static function dataTrueFalse(): array {
return [
[true],
[false],
@@ -198,7 +198,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
- ->setMethods(['decryptUsersFiles'])
+ ->onlyMethods(['decryptUsersFiles'])
->getMock();
$this->invokePrivate($instance, 'input', [$this->inputInterface]);
@@ -211,12 +211,16 @@ class DecryptAllTest extends TestCase {
$this->userInterface->expects($this->any())
->method('getUsers')
->willReturn(['user1', 'user2']);
+ $calls = [
+ 'user1',
+ 'user2',
+ ];
$instance->expects($this->exactly(2))
->method('decryptUsersFiles')
- ->withConsecutive(
- ['user1'],
- ['user2'],
- );
+ ->willReturnCallback(function ($user) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $user);
+ });
} else {
$instance->expects($this->once())
->method('decryptUsersFiles')
@@ -226,7 +230,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'decryptAllUsersFiles', [$user]);
}
- public function dataTestDecryptAllUsersFiles() {
+ public static function dataTestDecryptAllUsersFiles(): array {
return [
['user1'],
['']
@@ -243,7 +247,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
- ->setMethods(['decryptFile'])
+ ->onlyMethods(['decryptFile'])
->getMock();
$storage = $this->getMockBuilder(IStorage::class)
@@ -253,25 +257,29 @@ class DecryptAllTest extends TestCase {
$sharedStorage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()->getMock();
- $sharedStorage->expects($this->once())->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\SharedStorage')->willReturn(true);
+ $sharedStorage->expects($this->once())
+ ->method('instanceOfStorage')
+ ->with('OCA\Files_Sharing\SharedStorage')
+ ->willReturn(true);
$this->view->expects($this->exactly(2))
->method('getDirectoryContent')
- ->withConsecutive(
- ['/user1/files'],
- ['/user1/files/foo']
- )
- ->willReturnOnConsecutiveCalls(
+ ->willReturnMap([
[
- new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null),
- new FileInfo('path', $storage, 'intPath', ['name' => 'bar', 'type' => 'file', 'encrypted' => true], null),
- new FileInfo('path', $sharedStorage, 'intPath', ['name' => 'shared', 'type' => 'file', 'encrypted' => true], null),
+ '/user1/files', '', null,
+ [
+ new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null),
+ new FileInfo('path', $storage, 'intPath', ['name' => 'bar', 'type' => 'file', 'encrypted' => true], null),
+ new FileInfo('path', $sharedStorage, 'intPath', ['name' => 'shared', 'type' => 'file', 'encrypted' => true], null),
+ ],
],
[
- new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type' => 'file', 'encrypted' => true], null)
- ]
- );
+ '/user1/files/foo', '', null,
+ [
+ new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type' => 'file', 'encrypted' => true], null)
+ ],
+ ],
+ ]);
$this->view->expects($this->any())->method('is_dir')
->willReturnCallback(
@@ -283,12 +291,16 @@ class DecryptAllTest extends TestCase {
}
);
+ $calls = [
+ '/user1/files/bar',
+ '/user1/files/foo/subfile',
+ ];
$instance->expects($this->exactly(2))
->method('decryptFile')
- ->withConsecutive(
- ['/user1/files/bar'],
- ['/user1/files/foo/subfile'],
- );
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $path);
+ });
/* We need format method to return a string */
@@ -320,7 +332,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
- ->setMethods(['getTimestamp'])
+ ->onlyMethods(['getTimestamp'])
->getMock();
$fileInfo = $this->createMock(FileInfo::class);
@@ -360,7 +372,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
- ->setMethods(['getTimestamp'])
+ ->onlyMethods(['getTimestamp'])
->getMock();
diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php
index 2ce30105293..bc79c5771ca 100644
--- a/tests/lib/Encryption/Keys/StorageTest.php
+++ b/tests/lib/Encryption/Keys/StorageTest.php
@@ -9,6 +9,7 @@
namespace Test\Encryption\Keys;
use OC\Encryption\Keys\Storage;
+use OC\Encryption\Util;
use OC\Files\View;
use OCP\IConfig;
use OCP\Security\ICrypto;
@@ -36,9 +37,9 @@ class StorageTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->util = $this->getMockBuilder('OC\Encryption\Util')
+ $this->util = $this->getMockBuilder(Util::class)
->disableOriginalConstructor()
- ->setMethodsExcept(['getFileKeyDir'])
+ ->onlyMethods(array_diff(get_class_methods(Util::class), ['getFileKeyDir']))
->getMock();
$this->view = $this->getMockBuilder(View::class)
@@ -114,7 +115,7 @@ class StorageTest extends TestCase {
);
}
- public function dataTestGetFileKey() {
+ public static function dataTestGetFileKey() {
return [
['/files/foo.txt', '/files/foo.txt', true, 'key'],
['/files/foo.txt.ocTransferId2111130212.part', '/files/foo.txt', true, 'key'],
@@ -157,13 +158,10 @@ class StorageTest extends TestCase {
if (!$originalKeyExists) {
$this->view->expects($this->exactly(2))
->method('file_exists')
- ->withConsecutive(
- [$this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')],
- [$this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')],
- )->willReturnOnConsecutiveCalls(
- $originalKeyExists,
- true,
- );
+ ->willReturnMap([
+ ['/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey', $originalKeyExists],
+ ['/user1/files_encryption/keys' . $path . '/encModule/fileKey', true],
+ ]);
$this->view->expects($this->once())
->method('file_get_contents')
@@ -481,7 +479,7 @@ class StorageTest extends TestCase {
return [$parts[1], '/' . implode('/', array_slice($parts, 2))];
}
- public function dataProviderCopyRename() {
+ public static function dataProviderCopyRename() {
return [
['/user1/files/source.txt', '/user1/files/target.txt', false, false,
'/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'],
@@ -534,7 +532,7 @@ class StorageTest extends TestCase {
);
}
- public function dataTestGetPathToKeys() {
+ public static function dataTestGetPathToKeys() {
return [
['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'],
['/user1/files/source.txt', true, '', '/files_encryption/keys/files/source.txt/'],
@@ -577,7 +575,7 @@ class StorageTest extends TestCase {
public function testBackupUserKeys($createBackupDir): void {
$storage = $this->getMockBuilder('OC\Encryption\Keys\Storage')
->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config])
- ->setMethods(['getTimestamp'])
+ ->onlyMethods(['getTimestamp'])
->getMock();
$storage->expects($this->any())->method('getTimestamp')->willReturn('1234567');
@@ -586,11 +584,15 @@ class StorageTest extends TestCase {
->with('user1/files_encryption/backup')->willReturn(!$createBackupDir);
if ($createBackupDir) {
+ $calls = [
+ 'user1/files_encryption/backup',
+ 'user1/files_encryption/backup/test.encryptionModule.1234567',
+ ];
$this->view->expects($this->exactly(2))->method('mkdir')
- ->withConsecutive(
- ['user1/files_encryption/backup'],
- ['user1/files_encryption/backup/test.encryptionModule.1234567'],
- );
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $path);
+ });
} else {
$this->view->expects($this->once())->method('mkdir')
->with('user1/files_encryption/backup/test.encryptionModule.1234567');
@@ -605,7 +607,7 @@ class StorageTest extends TestCase {
$this->assertTrue($storage->backupUserKeys('encryptionModule', 'test', 'user1'));
}
- public function dataTestBackupUserKeys() {
+ public static function dataTestBackupUserKeys() {
return [
[true], [false]
];
diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
index f787c168130..3daf82461cb 100644
--- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
@@ -205,16 +205,12 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
public function testMultiBucketConfigFirstFallBackSingle(): void {
$this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->withConsecutive(
- [$this->equalTo('objectstore_multibucket')],
- [$this->equalTo('objectstore')],
- )->willReturnOnConsecutiveCalls(
- '',
- [
+ ->method('getSystemValue')->willReturnMap([
+ ['objectstore_multibucket', '', ''],
+ ['objectstore', '', [
'class' => 'Test\Files\Mount\FakeObjectStore',
- ],
- );
+ ]],
+ ]);
$this->user->method('getUID')
->willReturn('uid');
diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
index 616fd023414..29277772358 100644
--- a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
+++ b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
@@ -76,12 +76,16 @@ class AvailabilityTest extends \Test\TestCase {
$this->storage->expects($this->once())
->method('test')
->willReturn(true);
+ $calls = [
+ false, // prevents concurrent rechecks
+ true, // sets correct availability
+ ];
$this->storage->expects($this->exactly(2))
->method('setAvailability')
- ->withConsecutive(
- [$this->equalTo(false)], // prevents concurrent rechecks
- [$this->equalTo(true)] // sets correct availability
- );
+ ->willReturnCallback(function ($value) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $value);
+ });
$this->storage->expects($this->once())
->method('mkdir');
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index a11a59bed1e..1005f12786a 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -25,7 +25,7 @@ class DetectionTest extends \Test\TestCase {
);
}
- public function dataDetectPath(): array {
+ public static function dataDetectPath(): array {
return [
['foo.txt', 'text/plain'],
['foo.png', 'image/png'],
@@ -54,7 +54,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $this->detection->detectPath($path));
}
- public function dataDetectContent(): array {
+ public static function dataDetectContent(): array {
return [
['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'],
@@ -74,7 +74,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path));
}
- public function dataDetect(): array {
+ public static function dataDetect(): array {
return [
['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'],
@@ -100,7 +100,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
- public function dataMimeTypeCustom(): array {
+ public static function dataMimeTypeCustom(): array {
return [
['123', 'foobar/123'],
['a123', 'foobar/123'],
@@ -135,7 +135,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($mime, $detection->detectPath('foo.' . $ext));
}
- public function dataGetSecureMimeType(): array {
+ public static function dataGetSecureMimeType(): array {
return [
['image/svg+xml', 'text/plain'],
['image/png', 'image/png'],
@@ -255,14 +255,16 @@ class DetectionTest extends \Test\TestCase {
->getMock();
//Only call the url generator once
+ $calls = [
+ ['core', 'filetypes/my-type.png'],
+ ['core', 'filetypes/my.png'],
+ ];
$urlGenerator->expects($this->exactly(2))
->method('imagePath')
- ->withConsecutive(
- [$this->equalTo('core'), $this->equalTo('filetypes/my-type.png')],
- [$this->equalTo('core'), $this->equalTo('filetypes/my.png')]
- )
->willReturnCallback(
- function ($appName, $file) {
+ function ($appName, $file) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/my.png') {
return 'my.svg';
}
@@ -285,15 +287,17 @@ class DetectionTest extends \Test\TestCase {
->getMock();
//Only call the url generator once
+ $calls = [
+ ['core', 'filetypes/foo-bar.png'],
+ ['core', 'filetypes/foo.png'],
+ ['core', 'filetypes/file.png'],
+ ];
$urlGenerator->expects($this->exactly(3))
->method('imagePath')
- ->withConsecutive(
- [$this->equalTo('core'), $this->equalTo('filetypes/foo-bar.png')],
- [$this->equalTo('core'), $this->equalTo('filetypes/foo.png')],
- [$this->equalTo('core'), $this->equalTo('filetypes/file.png')]
- )
->willReturnCallback(
- function ($appName, $file) {
+ function ($appName, $file) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/file.png') {
return 'file.svg';
}
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 7cebfd01b03..53e5855d0e9 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -64,6 +64,17 @@ class TemporaryNoLocal extends Temporary {
}
}
+class TestEventHandler {
+ public function umount() {
+ }
+ public function post_umount() {
+ }
+ public function preCallback() {
+ }
+ public function postCallback() {
+ }
+}
+
/**
* Class ViewTest
*
@@ -291,7 +302,7 @@ class ViewTest extends \Test\TestCase {
$this->assertCount(4, $folderContent);
}
- public function sharingDisabledPermissionProvider() {
+ public static function sharingDisabledPermissionProvider(): array {
return [
['no', '', true],
['yes', 'group1', false],
@@ -543,7 +554,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($rootView->file_exists('substorage/bar.txt'));
}
- public function rmdirOrUnlinkDataProvider() {
+ public static function rmdirOrUnlinkDataProvider(): array {
return [['rmdir'], ['unlink']];
}
@@ -775,7 +786,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($exists);
}
- public function resolvePathTestProvider() {
+ public static function resolvePathTestProvider(): array {
return [
['foo.txt', 'foo.txt'],
['foo.txt', '/foo.txt'],
@@ -940,7 +951,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals(6, $info->getSize());
}
- public function absolutePathProvider() {
+ public static function absolutePathProvider(): array {
return [
['/files/', ''],
['/files/0', '0'],
@@ -961,8 +972,8 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
}
- public function chrootRelativePathProvider() {
- return $this->relativePathProvider('/');
+ public static function chrootRelativePathProvider(): array {
+ return self::relativePathProvider('/');
}
/**
@@ -973,11 +984,11 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
}
- public function initRelativePathProvider() {
- return $this->relativePathProvider(null);
+ public static function initRelativePathProvider(): array {
+ return self::relativePathProvider(null);
}
- public function relativePathProvider($missingRootExpectedPath) {
+ public static function relativePathProvider($missingRootExpectedPath): array {
return [
// No root - returns the path
['', '/files', '/files'],
@@ -1097,7 +1108,7 @@ class ViewTest extends \Test\TestCase {
call_user_func([$rootView, $operation], $longPath, $param0);
}
- public function tooLongPathDataProvider() {
+ public static function tooLongPathDataProvider(): array {
return [
['getAbsolutePath'],
['getRelativePath'],
@@ -1180,7 +1191,7 @@ class ViewTest extends \Test\TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|Temporary $storage2 */
$storage2 = $this->getMockBuilder(TemporaryNoCross::class)
->setConstructorArgs([[]])
- ->setMethods(['fopen', 'writeStream'])
+ ->onlyMethods(['fopen', 'writeStream'])
->getMock();
$storage2->method('writeStream')
@@ -1226,7 +1237,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setConstructorArgs([[]])
- ->setMethods(['unlink'])
+ ->onlyMethods(['unlink'])
->getMock();
$storage->expects($this->once())
->method('unlink')
@@ -1243,7 +1254,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($cache->inCache('foo.txt'));
}
- public function directoryTraversalProvider() {
+ public static function directoryTraversalProvider(): array {
return [
['../test/'],
['..\\test\\my/../folder'],
@@ -1481,7 +1492,7 @@ class ViewTest extends \Test\TestCase {
$lockingProvider->releaseAll();
}
- public function dataLockPaths() {
+ public static function dataLockPaths(): array {
return [
['/testuser/{folder}', ''],
['/testuser', '/{folder}'],
@@ -1489,7 +1500,7 @@ class ViewTest extends \Test\TestCase {
];
}
- public function pathRelativeToFilesProvider() {
+ public static function pathRelativeToFilesProvider(): array {
return [
['admin/files', ''],
['admin/files/x', 'x'],
@@ -1509,7 +1520,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path));
}
- public function pathRelativeToFilesProviderExceptionCases() {
+ public static function pathRelativeToFilesProviderExceptionCases(): array {
return [
[''],
['x'],
@@ -1552,7 +1563,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
}
- public function hookPathProvider() {
+ public static function hookPathProvider(): array {
return [
['/foo/files', '/foo', true],
['/foo/files/bar', '/foo', true],
@@ -1593,7 +1604,7 @@ class ViewTest extends \Test\TestCase {
$mounts = [];
foreach ($mountPoints as $mountPoint) {
$storage = $this->getMockBuilder(Storage::class)
- ->setMethods([])
+ ->onlyMethods([])
->getMock();
$storage->method('getId')->willReturn('non-null-id');
$storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
@@ -1601,7 +1612,7 @@ class ViewTest extends \Test\TestCase {
});
$mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
- ->setMethods(['moveMount'])
+ ->onlyMethods(['moveMount'])
->setConstructorArgs([$storage, $mountPoint])
->getMock();
}
@@ -1746,7 +1757,7 @@ class ViewTest extends \Test\TestCase {
$userObject->delete();
}
- public function basicOperationProviderForLocks() {
+ public static function basicOperationProviderForLocks(): array {
return [
// --- write hook ----
[
@@ -1931,7 +1942,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary&MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods([$operation])
+ ->onlyMethods([$operation])
->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
@@ -1987,7 +1998,7 @@ class ViewTest extends \Test\TestCase {
$path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods(['fopen'])
+ ->onlyMethods(['fopen'])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@@ -2026,7 +2037,7 @@ class ViewTest extends \Test\TestCase {
$path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods(['fopen'])
+ ->onlyMethods(['fopen'])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@@ -2081,7 +2092,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods([$operation])
+ ->onlyMethods([$operation])
->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
@@ -2169,7 +2180,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods([$operation])
+ ->onlyMethods([$operation])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@@ -2187,7 +2198,7 @@ class ViewTest extends \Test\TestCase {
$this->assertNull($this->getFileLockType($view, $path), 'File got unlocked after exception');
}
- public function lockFileRenameOrCopyDataProvider() {
+ public static function lockFileRenameOrCopyDataProvider(): array {
return [
['rename', ILockingProvider::LOCK_EXCLUSIVE],
['copy', ILockingProvider::LOCK_SHARED],
@@ -2208,7 +2219,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods([$operation, 'getMetaData', 'filemtime'])
+ ->onlyMethods([$operation, 'getMetaData', 'filemtime'])
->getMock();
$storage->expects($this->any())
@@ -2274,7 +2285,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods(['copy'])
+ ->onlyMethods(['copy'])
->getMock();
$sourcePath = 'original.txt';
@@ -2371,7 +2382,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
}
- public function lockFileRenameOrCopyCrossStorageDataProvider() {
+ public static function lockFileRenameOrCopyCrossStorageDataProvider(): array {
return [
['rename', 'moveFromStorage', ILockingProvider::LOCK_EXCLUSIVE],
['copy', 'copyFromStorage', ILockingProvider::LOCK_SHARED],
@@ -2393,11 +2404,11 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
- ->setMethods([$storageOperation])
+ ->onlyMethods([$storageOperation])
->getMock();
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage2 */
$storage2 = $this->getMockBuilder(Temporary::class)
- ->setMethods([$storageOperation, 'getMetaData', 'filemtime'])
+ ->onlyMethods([$storageOperation, 'getMetaData', 'filemtime'])
->getMock();
$storage2->expects($this->any())
@@ -2532,8 +2543,8 @@ class ViewTest extends \Test\TestCase {
return;
}
- $eventHandler = $this->getMockBuilder(\stdclass::class)
- ->setMethods(['preCallback', 'postCallback'])
+ $eventHandler = $this->getMockBuilder(TestEventHandler::class)
+ ->onlyMethods(['preCallback', 'postCallback'])
->getMock();
$eventHandler->expects($this->any())
@@ -2607,8 +2618,8 @@ class ViewTest extends \Test\TestCase {
Filesystem::getMountManager()->addMount($mount);
// Listen for events
- $eventHandler = $this->getMockBuilder(\stdclass::class)
- ->setMethods(['umount', 'post_umount'])
+ $eventHandler = $this->getMockBuilder(TestEventHandler::class)
+ ->onlyMethods(['umount', 'post_umount'])
->getMock();
$eventHandler->expects($this->once())
->method('umount')
@@ -2634,7 +2645,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('foo', $view->rmdir('mount'));
}
- public function mimeFilterProvider() {
+ public static function mimeFilterProvider(): array {
return [
[null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']],
['text/plain', ['test1.txt', 'test2.txt']],
@@ -2742,7 +2753,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectories(): void {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
- ->setMethods([
+ ->onlyMethods([
'is_file',
'file_exists',
'mkdir',
@@ -2751,29 +2762,26 @@ class ViewTest extends \Test\TestCase {
$view->expects($this->exactly(3))
->method('is_file')
- ->withConsecutive(
- ['/new'],
- ['/new/folder'],
- ['/new/folder/structure'],
- )
- ->willReturn(false);
+ ->willReturnMap([
+ ['/new', false],
+ ['/new/folder', false],
+ ['/new/folder/structure', false],
+ ]);
$view->expects($this->exactly(3))
->method('file_exists')
- ->withConsecutive(
- ['/new'],
- ['/new/folder'],
- ['/new/folder/structure'],
- )->willReturnOnConsecutiveCalls(
- true,
- false,
- false,
- );
+ ->willReturnMap([
+ ['/new', true],
+ ['/new/folder', false],
+ ['/new/folder/structure', false],
+ ]);
+
+ $calls = ['/new/folder', '/new/folder/structure'];
$view->expects($this->exactly(2))
->method('mkdir')
- ->withConsecutive(
- ['/new/folder'],
- ['/new/folder/structure'],
- );
+ ->willReturnCallback(function ($dir) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $dir);
+ });
$this->assertTrue(self::invokePrivate($view, 'createParentDirectories', ['/new/folder/structure']));
}
@@ -2781,7 +2789,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectoriesWithExistingFile(): void {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
- ->setMethods([
+ ->onlyMethods([
'is_file',
'file_exists',
'mkdir',
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php
index 47a6b885aed..92e5f04d7f0 100644
--- a/tests/lib/Http/Client/ClientTest.php
+++ b/tests/lib/Http/Client/ClientTest.php
@@ -92,14 +92,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
- ->withConsecutive(
- ['proxy', ''],
- ['proxyuserpwd', ''],
- )
- ->willReturnOnConsecutiveCalls(
- 'foo',
- 'username:password',
- );
+ ->willReturnMap([
+ ['proxy', '', 'foo'],
+ ['proxyuserpwd', '', 'username:password'],
+ ]);
$this->assertEquals([
'http' => 'username:password@foo',
'https' => 'username:password@foo'
@@ -115,14 +111,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
- ->withConsecutive(
- ['proxy', ''],
- ['proxyuserpwd', ''],
- )
- ->willReturnOnConsecutiveCalls(
- 'foo',
- 'username:password',
- );
+ ->willReturnMap([
+ ['proxy', '', 'foo'],
+ ['proxyuserpwd', '', 'username:password'],
+ ]);
$this->assertEquals([
'http' => 'username:password@foo',
'https' => 'username:password@foo',
@@ -137,7 +129,7 @@ class ClientTest extends \Test\TestCase {
self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]);
}
- public function dataPreventLocalAddress():array {
+ public static function dataPreventLocalAddress(): array {
return [
['https://localhost/foo.bar'],
['https://localHost/foo.bar'],
@@ -461,14 +453,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['installed', false],
- ['allow_local_remote_servers', false],
- )
- ->willReturnOnConsecutiveCalls(
- false,
- false,
- );
+ ->willReturnMap([
+ ['installed', false, false],
+ ['allow_local_remote_servers', false, false],
+ ]);
$this->config
->expects($this->once())
->method('getSystemValueString')
@@ -503,14 +491,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['installed', false],
- ['allow_local_remote_servers', false],
- )
- ->willReturnOnConsecutiveCalls(
- true,
- false,
- );
+ ->willReturnMap([
+ ['installed', false, true],
+ ['allow_local_remote_servers', false, false],
+ ]);
$this->config
->expects($this->once())
->method('getSystemValue')
@@ -519,14 +503,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
- ->withConsecutive(
- ['proxy', ''],
- ['proxyuserpwd', ''],
- )
- ->willReturnOnConsecutiveCalls(
- 'foo',
- '',
- );
+ ->willReturnMap([
+ ['proxy', '', 'foo'],
+ ['proxyuserpwd', '', ''],
+ ]);
$this->certificateManager
->expects($this->once())
->method('getAbsoluteBundlePath')
@@ -562,14 +542,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['installed', false],
- ['allow_local_remote_servers', false],
- )
- ->willReturnOnConsecutiveCalls(
- true,
- false,
- );
+ ->willReturnMap([
+ ['installed', false, true],
+ ['allow_local_remote_servers', false, false],
+ ]);
$this->config
->expects($this->once())
->method('getSystemValue')
@@ -578,14 +554,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
- ->withConsecutive(
- ['proxy', ''],
- ['proxyuserpwd', ''],
- )
- ->willReturnOnConsecutiveCalls(
- 'foo',
- '',
- );
+ ->willReturnMap([
+ ['proxy', '', 'foo'],
+ ['proxyuserpwd', '', ''],
+ ]);
$this->certificateManager
->expects($this->once())
->method('getAbsoluteBundlePath')
diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php
index 5858a01203f..c5a4f255397 100644
--- a/tests/lib/IntegrityCheck/CheckerTest.php
+++ b/tests/lib/IntegrityCheck/CheckerTest.php
@@ -200,14 +200,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )
- ->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
}
@@ -239,14 +235,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )
- ->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'EXCEPTION' => [
@@ -284,14 +276,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )
- ->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
@@ -344,15 +332,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )
- ->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
-
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'INVALID_HASH' => [
@@ -405,13 +388,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'EXCEPTION' => [
@@ -449,13 +429,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
- ['/resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
+ ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
}
@@ -689,13 +666,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@@ -726,14 +700,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt'],
- )
- ->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@@ -816,13 +786,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@@ -853,13 +820,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'EXCEPTION' => [
@@ -896,13 +860,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'INVALID_HASH' => [
@@ -954,13 +915,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'EXCEPTION' => [
@@ -997,13 +955,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
- ->withConsecutive(
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
- [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
- )->willReturnOnConsecutiveCalls(
- $signatureDataFile,
- file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
- );
+ ->willReturnMap([
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
+ [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
+ ]);
$expected = [
'EXCEPTION' => [
@@ -1027,7 +982,7 @@ class CheckerTest extends TestCase {
$this->appManager,
$this->mimeTypeDetector,
])
- ->setMethods([
+ ->onlyMethods([
'verifyCoreSignature',
'verifyAppSignature',
])
@@ -1048,45 +1003,40 @@ class CheckerTest extends TestCase {
$this->appManager
->expects($this->exactly(4))
->method('isShipped')
- ->withConsecutive(
- ['files'],
- ['calendar'],
- ['contacts'],
- ['dav'],
- )->willReturnOnConsecutiveCalls(
- true,
- false,
- false,
- true,
- );
+ ->willReturnMap([
+ ['files', true],
+ ['calendar', false],
+ ['contacts', false],
+ ['dav', true],
+ ]);
+
+ $calls = [
+ 'files',
+ 'calendar',
+ 'dav',
+ ];
$this->checker
->expects($this->exactly(3))
->method('verifyAppSignature')
- ->withConsecutive(
- ['files'],
- ['calendar'],
- ['dav'],
- );
+ ->willReturnCallback(function ($app) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertSame($expected, $app);
+ return [];
+ });
$this->appLocator
->expects($this->exactly(2))
->method('getAppPath')
- ->withConsecutive(
- ['calendar'],
- ['contacts'],
- )->willReturnOnConsecutiveCalls(
- '/apps/calendar',
- '/apps/contacts',
- );
+ ->willReturnMap([
+ ['calendar', '/apps/calendar'],
+ ['contacts', '/apps/contacts'],
+ ]);
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_exists')
- ->withConsecutive(
- ['/apps/calendar/appinfo/signature.json'],
- ['/apps/contacts/appinfo/signature.json'],
- )->willReturnOnConsecutiveCalls(
- true,
- false,
- );
+ ->willReturnMap([
+ ['/apps/calendar/appinfo/signature.json', true],
+ ['/apps/contacts/appinfo/signature.json', false],
+ ]);
$this->appConfig
->expects($this->once())
->method('deleteKey')
@@ -1110,10 +1060,7 @@ class CheckerTest extends TestCase {
$this->assertSame($expected, $this->checker->verifyAppSignature('SomeApp'));
}
- /**
- * @return array
- */
- public function channelDataProvider() {
+ public static function channelDataProvider(): array {
return [
['stable', true],
['git', false],
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 03731a90754..9e778207a8e 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -59,6 +59,13 @@ use PHPUnit\Framework\MockObject\MockBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
+class DummyShareManagerListener {
+ public function post() {
+ }
+ public function listener() {
+ }
+}
+
/**
* Class ManagerTest
*
@@ -225,13 +232,7 @@ class ManagerTest extends \Test\TestCase {
$this->manager->deleteShare($share);
}
- public function dataTestDelete() {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('sharedWithUser');
-
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('sharedWithGroup');
-
+ public static function dataTestDelete(): array {
return [
[IShare::TYPE_USER, 'sharedWithUser'],
[IShare::TYPE_GROUP, 'sharedWithGroup'],
@@ -245,7 +246,7 @@ class ManagerTest extends \Test\TestCase {
*/
public function testDelete($shareType, $sharedWith): void {
$manager = $this->createManagerMock()
- ->setMethods(['getShareById', 'deleteChildren', 'promoteReshares'])
+ ->onlyMethods(['getShareById', 'deleteChildren', 'promoteReshares'])
->getMock();
$manager->method('deleteChildren')->willReturn([]);
@@ -270,25 +271,24 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
+ $calls = [
+ BeforeShareDeletedEvent::class,
+ ShareDeletedEvent::class,
+ ];
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
- ->withConsecutive(
- [
- $this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
- return $e->getShare() === $share;
- })],
- [
- $this->callBack(function (ShareDeletedEvent $e) use ($share) {
- return $e->getShare() === $share;
- })]
- );
+ ->willReturnCallback(function ($event) use (&$calls, $share) {
+ $expected = array_shift($calls);
+ $this->assertInstanceOf($expected, $event);
+ $this->assertEquals($share, $event->getShare());
+ });
$manager->deleteShare($share);
}
public function testDeleteLazyShare(): void {
$manager = $this->createManagerMock()
- ->setMethods(['getShareById', 'deleteChildren', 'promoteReshares'])
+ ->onlyMethods(['getShareById', 'deleteChildren', 'promoteReshares'])
->getMock();
$manager->method('deleteChildren')->willReturn([]);
@@ -314,25 +314,24 @@ class ManagerTest extends \Test\TestCase {
->method('delete')
->with($share);
+ $calls = [
+ BeforeShareDeletedEvent::class,
+ ShareDeletedEvent::class,
+ ];
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
- ->withConsecutive(
- [
- $this->callBack(function (BeforeShareDeletedEvent $e) use ($share) {
- return $e->getShare() === $share;
- })],
- [
- $this->callBack(function (ShareDeletedEvent $e) use ($share) {
- return $e->getShare() === $share;
- })]
- );
+ ->willReturnCallback(function ($event) use (&$calls, $share) {
+ $expected = array_shift($calls);
+ $this->assertInstanceOf($expected, $event);
+ $this->assertEquals($share, $event->getShare());
+ });
$manager->deleteShare($share);
}
public function testDeleteNested(): void {
$manager = $this->createManagerMock()
- ->setMethods(['getShareById', 'promoteReshares'])
+ ->onlyMethods(['getShareById', 'promoteReshares'])
->getMock();
$path = $this->createMock(File::class);
@@ -374,51 +373,40 @@ class ManagerTest extends \Test\TestCase {
[$share3, []],
]);
- $this->defaultProvider
+ $deleteCalls = [
+ $share3,
+ $share2,
+ $share1,
+ ];
+ $this->defaultProvider->expects($this->exactly(3))
->method('delete')
- ->withConsecutive([$share3], [$share2], [$share1]);
+ ->willReturnCallback(function ($share) use (&$deleteCalls) {
+ $expected = array_shift($deleteCalls);
+ $this->assertEquals($expected, $share);
+ });
+ $dispatchCalls = [
+ [BeforeShareDeletedEvent::class, $share1],
+ [BeforeShareDeletedEvent::class, $share2],
+ [BeforeShareDeletedEvent::class, $share3],
+ [ShareDeletedEvent::class, $share3],
+ [ShareDeletedEvent::class, $share2],
+ [ShareDeletedEvent::class, $share1],
+ ];
$this->dispatcher->expects($this->exactly(6))
->method('dispatchTyped')
- ->withConsecutive(
- [
- $this->callBack(function (BeforeShareDeletedEvent $e) use ($share1) {
- return $e->getShare()->getId() === $share1->getId();
- })
- ],
- [
- $this->callBack(function (BeforeShareDeletedEvent $e) use ($share2) {
- return $e->getShare()->getId() === $share2->getId();
- })
- ],
- [
- $this->callBack(function (BeforeShareDeletedEvent $e) use ($share3) {
- return $e->getShare()->getId() === $share3->getId();
- })
- ],
- [
- $this->callBack(function (ShareDeletedEvent $e) use ($share3) {
- return $e->getShare()->getId() === $share3->getId();
- })
- ],
- [
- $this->callBack(function (ShareDeletedEvent $e) use ($share2) {
- return $e->getShare()->getId() === $share2->getId();
- })
- ],
- [
- $this->callBack(function (ShareDeletedEvent $e) use ($share1) {
- return $e->getShare()->getId() === $share1->getId();
- })
- ],
- );
+ ->willReturnCallback(function ($event) use (&$dispatchCalls) {
+ $expected = array_shift($dispatchCalls);
+ $this->assertInstanceOf($expected[0], $event);
+ $this->assertEquals($expected[1]->getId(), $event->getShare()->getId());
+ });
$manager->deleteShare($share1);
}
public function testDeleteFromSelf(): void {
$manager = $this->createManagerMock()
- ->setMethods(['getShareById'])
+ ->onlyMethods(['getShareById'])
->getMock();
$recipientId = 'unshareFrom';
@@ -451,7 +439,7 @@ class ManagerTest extends \Test\TestCase {
public function testDeleteChildren(): void {
$manager = $this->createManagerMock()
- ->setMethods(['deleteShare'])
+ ->onlyMethods(['deleteShare'])
->getMock();
$share = $this->createMock(IShare::class);
@@ -480,10 +468,17 @@ class ManagerTest extends \Test\TestCase {
return [];
});
- $this->defaultProvider
- ->expects($this->exactly(3))
+ $calls = [
+ $child1,
+ $child2,
+ $child3,
+ ];
+ $this->defaultProvider->expects($this->exactly(3))
->method('delete')
- ->withConsecutive([$child1], [$child2], [$child3]);
+ ->willReturnCallback(function ($share) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $share);
+ });
$result = self::invokePrivate($manager, 'deleteChildren', [$share]);
$this->assertSame($shares, $result);
@@ -491,7 +486,7 @@ class ManagerTest extends \Test\TestCase {
public function testPromoteReshareFile(): void {
$manager = $this->createManagerMock()
- ->setMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
+ ->onlyMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
->getMock();
$file = $this->createMock(File::class);
@@ -528,7 +523,7 @@ class ManagerTest extends \Test\TestCase {
public function testPromoteReshare(): void {
$manager = $this->createManagerMock()
- ->setMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
+ ->onlyMethods(['updateShare', 'getSharesInFolder', 'generalCreateChecks'])
->getMock();
$folder = $this->createFolderMock('/path/to/folder');
@@ -571,14 +566,23 @@ class ManagerTest extends \Test\TestCase {
});
$manager->method('generalCreateChecks')->willThrowException(new GenericShareException());
- $manager->expects($this->exactly(2))->method('updateShare')->withConsecutive([$reShare], [$reShareInSubFolder]);
+ $calls = [
+ $reShare,
+ $reShareInSubFolder,
+ ];
+ $manager->expects($this->exactly(2))
+ ->method('updateShare')
+ ->willReturnCallback(function ($share) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $share);
+ });
self::invokePrivate($manager, 'promoteReshares', [$share]);
}
public function testPromoteReshareWhenUserHasAnotherShare(): void {
$manager = $this->createManagerMock()
- ->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
+ ->onlyMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
->getMock();
$folder = $this->createFolderMock('/path/to/folder');
@@ -606,7 +610,7 @@ class ManagerTest extends \Test\TestCase {
public function testPromoteReshareOfUsersInGroupShare(): void {
$manager = $this->createManagerMock()
- ->setMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
+ ->onlyMethods(['updateShare', 'getSharesInFolder', 'getSharedWith', 'generalCreateChecks'])
->getMock();
$folder = $this->createFolderMock('/path/to/folder');
@@ -656,7 +660,16 @@ class ManagerTest extends \Test\TestCase {
$manager->method('getSharedWith')->willReturn([]);
- $manager->expects($this->exactly(2))->method('updateShare')->withConsecutive([$reShare1], [$reShare2]);
+ $calls = [
+ $reShare1,
+ $reShare2,
+ ];
+ $manager->expects($this->exactly(2))
+ ->method('updateShare')
+ ->willReturnCallback(function ($share) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $share);
+ });
self::invokePrivate($manager, 'promoteReshares', [$share]);
}
@@ -678,7 +691,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
$manager = $this->createManagerMock()
- ->setMethods(['deleteShare'])
+ ->onlyMethods(['deleteShare'])
->getMock();
$date = new \DateTime();
@@ -1055,7 +1068,7 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'generalCreateChecks', [$share]);
}
- public function validateExpirationDateInternalProvider() {
+ public static function validateExpirationDateInternalProvider() {
return [[IShare::TYPE_USER], [IShare::TYPE_REMOTE], [IShare::TYPE_REMOTE_GROUP]];
}
@@ -1263,7 +1276,7 @@ class ManagerTest extends \Test\TestCase {
]);
}
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($future) {
return $data['expirationDate'] == $future;
@@ -1289,7 +1302,7 @@ class ManagerTest extends \Test\TestCase {
$share->setShareType($shareType);
$share->setExpirationDate($date);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected && $data['passwordSet'] === false;
@@ -1304,7 +1317,7 @@ class ManagerTest extends \Test\TestCase {
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalNoDateNoDefault($shareType): void {
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) {
return $data['expirationDate'] === null && $data['passwordSet'] === true;
@@ -1347,7 +1360,7 @@ class ManagerTest extends \Test\TestCase {
]);
}
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected;
@@ -1389,7 +1402,7 @@ class ManagerTest extends \Test\TestCase {
]);
}
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected;
@@ -1410,7 +1423,7 @@ class ManagerTest extends \Test\TestCase {
$save = clone $nextWeek;
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['expirationDate']->sub(new \DateInterval('P2D'));
@@ -1441,7 +1454,7 @@ class ManagerTest extends \Test\TestCase {
$share->setShareType($shareType);
$share->setExpirationDate($nextWeek);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['accepted'] = false;
@@ -1602,7 +1615,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_default_expire_date', 'no', 'yes'],
]);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($future) {
return $data['expirationDate'] == $future;
@@ -1625,7 +1638,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setExpirationDate($date);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected && $data['passwordSet'] === false;
@@ -1637,7 +1650,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testValidateExpirationDateNoDateNoDefault(): void {
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) {
return $data['expirationDate'] === null && $data['passwordSet'] === true;
@@ -1666,7 +1679,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'link_defaultExpDays', '3', '3'],
]);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected;
@@ -1696,7 +1709,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'link_defaultExpDays', '3', '1'],
]);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected;
@@ -1727,7 +1740,7 @@ class ManagerTest extends \Test\TestCase {
['core', 'link_defaultExpDays', '3', '1'],
]);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) {
return $data['expirationDate'] == $expected;
@@ -1747,7 +1760,7 @@ class ManagerTest extends \Test\TestCase {
$save->sub(new \DateInterval('P2D'));
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['expirationDate']->sub(new \DateInterval('P2D'));
@@ -1772,7 +1785,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setExpirationDate($nextWeek);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['accepted'] = false;
@@ -2301,7 +2314,7 @@ class ManagerTest extends \Test\TestCase {
$this->addToAssertionCount(1);
}
- public function dataIsSharingDisabledForUser() {
+ public static function dataIsSharingDisabledForUser() {
$data = [];
// No exclude groups
@@ -2375,7 +2388,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $res);
}
- public function dataCanShare() {
+ public static function dataCanShare() {
$data = [];
/*
@@ -2404,7 +2417,7 @@ class ManagerTest extends \Test\TestCase {
]);
$manager = $this->createManagerMock()
- ->setMethods(['sharingDisabledForUser'])
+ ->onlyMethods(['sharingDisabledForUser'])
->getMock();
$manager->method('sharingDisabledForUser')
@@ -2482,7 +2495,7 @@ class ManagerTest extends \Test\TestCase {
public function testCreateShareGroup(): void {
$manager = $this->createManagerMock()
- ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
+ ->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
->getMock();
$shareOwner = $this->createMock(IUser::class);
@@ -2537,7 +2550,7 @@ class ManagerTest extends \Test\TestCase {
public function testCreateShareLink(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'generalCreateChecks',
'linkCreateChecks',
@@ -2610,40 +2623,30 @@ class ManagerTest extends \Test\TestCase {
return $share->setId(42);
});
+ $calls = [
+ BeforeShareCreatedEvent::class,
+ ShareCreatedEvent::class,
+ ];
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
- ->withConsecutive(
- // Pre share
- [
- $this->callback(function (BeforeShareCreatedEvent $e) use ($path, $date) {
- $share = $e->getShare();
-
- return $share->getShareType() === IShare::TYPE_LINK &&
- $share->getNode() === $path &&
- $share->getSharedBy() === 'sharedBy' &&
- $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
- $share->getExpirationDate() === $date &&
- $share->getPassword() === 'hashed' &&
- $share->getToken() === 'token';
- })
- ],
- // Post share
- [
- $this->callback(function (ShareCreatedEvent $e) use ($path, $date) {
- $share = $e->getShare();
-
- return $share->getShareType() === IShare::TYPE_LINK &&
- $share->getNode() === $path &&
- $share->getSharedBy() === 'sharedBy' &&
- $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
- $share->getExpirationDate() === $date &&
- $share->getPassword() === 'hashed' &&
- $share->getToken() === 'token' &&
- $share->getId() === '42' &&
- $share->getTarget() === '/target';
- })
- ]
- );
+ ->willReturnCallback(function ($event) use (&$calls, $date, $path) {
+ $expected = array_shift($calls);
+ $this->assertInstanceOf($expected, $event);
+ $share = $event->getShare();
+
+ $this->assertEquals(IShare::TYPE_LINK, $share->getShareType(), 'getShareType');
+ $this->assertEquals($path, $share->getNode(), 'getNode');
+ $this->assertEquals('sharedBy', $share->getSharedBy(), 'getSharedBy');
+ $this->assertEquals(\OCP\Constants::PERMISSION_ALL, $share->getPermissions(), 'getPermissions');
+ $this->assertEquals($date, $share->getExpirationDate(), 'getExpirationDate');
+ $this->assertEquals('hashed', $share->getPassword(), 'getPassword');
+ $this->assertEquals('token', $share->getToken(), 'getToken');
+
+ if ($expected === ShareCreatedEvent::class) {
+ $this->assertEquals('42', $share->getId(), 'getId');
+ $this->assertEquals('/target', $share->getTarget(), 'getTarget');
+ }
+ });
/** @var IShare $share */
$share = $manager->createShare($share);
@@ -2657,7 +2660,7 @@ class ManagerTest extends \Test\TestCase {
public function testCreateShareMail(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'generalCreateChecks',
'linkCreateChecks',
@@ -2717,38 +2720,30 @@ class ManagerTest extends \Test\TestCase {
return $share->setId(42);
});
+ $calls = [
+ BeforeShareCreatedEvent::class,
+ ShareCreatedEvent::class,
+ ];
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
- ->withConsecutive(
- [
- $this->callback(function (BeforeShareCreatedEvent $e) use ($path) {
- $share = $e->getShare();
-
- return $share->getShareType() === IShare::TYPE_EMAIL &&
- $share->getNode() === $path &&
- $share->getSharedBy() === 'sharedBy' &&
- $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
- $share->getExpirationDate() === null &&
- $share->getPassword() === null &&
- $share->getToken() === 'token';
- })
- ],
- [
- $this->callback(function (ShareCreatedEvent $e) use ($path) {
- $share = $e->getShare();
-
- return $share->getShareType() === IShare::TYPE_EMAIL &&
- $share->getNode() === $path &&
- $share->getSharedBy() === 'sharedBy' &&
- $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
- $share->getExpirationDate() === null &&
- $share->getPassword() === null &&
- $share->getToken() === 'token' &&
- $share->getId() === '42' &&
- $share->getTarget() === '/target';
- })
- ],
- );
+ ->willReturnCallback(function ($event) use (&$calls, $path) {
+ $expected = array_shift($calls);
+ $this->assertInstanceOf($expected, $event);
+ $share = $event->getShare();
+
+ $this->assertEquals(IShare::TYPE_EMAIL, $share->getShareType(), 'getShareType');
+ $this->assertEquals($path, $share->getNode(), 'getNode');
+ $this->assertEquals('sharedBy', $share->getSharedBy(), 'getSharedBy');
+ $this->assertEquals(\OCP\Constants::PERMISSION_ALL, $share->getPermissions(), 'getPermissions');
+ $this->assertNull($share->getExpirationDate(), 'getExpirationDate');
+ $this->assertNull($share->getPassword(), 'getPassword');
+ $this->assertEquals('token', $share->getToken(), 'getToken');
+
+ if ($expected === ShareCreatedEvent::class) {
+ $this->assertEquals('42', $share->getId(), 'getId');
+ $this->assertEquals('/target', $share->getTarget(), 'getTarget');
+ }
+ });
/** @var IShare $share */
$share = $manager->createShare($share);
@@ -2764,7 +2759,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('I won\'t let you share');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'generalCreateChecks',
'userCreateChecks',
@@ -2829,7 +2824,7 @@ class ManagerTest extends \Test\TestCase {
public function testCreateShareOfIncomingFederatedShare(): void {
$manager = $this->createManagerMock()
- ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
+ ->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
->getMock();
$shareOwner = $this->createMock(IUser::class);
@@ -2958,7 +2953,7 @@ class ManagerTest extends \Test\TestCase {
*/
public function testGetSharesByExpiredLinkShares(): void {
$manager = $this->createManagerMock()
- ->setMethods(['deleteShare'])
+ ->onlyMethods(['deleteShare'])
->getMock();
/** @var \OCP\Share\IShare[] $shares */
@@ -3109,13 +3104,17 @@ class ManagerTest extends \Test\TestCase {
$share = $this->createMock(IShare::class);
+ $calls = [
+ [IShare::TYPE_LINK],
+ [IShare::TYPE_REMOTE],
+ ];
$factory->expects($this->exactly(2))
->method('getProviderForType')
- ->withConsecutive(
- [IShare::TYPE_LINK],
- [IShare::TYPE_REMOTE]
- )
- ->willReturn($this->defaultProvider);
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ return $this->defaultProvider;
+ });
$this->defaultProvider->expects($this->exactly(2))
->method('getShareByToken')
@@ -3147,7 +3146,7 @@ class ManagerTest extends \Test\TestCase {
->willReturnArgument(0);
$manager = $this->createManagerMock()
- ->setMethods(['deleteShare'])
+ ->onlyMethods(['deleteShare'])
->getMock();
$date = new \DateTime();
@@ -3200,7 +3199,7 @@ class ManagerTest extends \Test\TestCase {
->willReturnArgument(0);
$manager = $this->createManagerMock()
- ->setMethods(['deleteShare'])
+ ->onlyMethods(['deleteShare'])
->getMock();
$date = new \DateTime();
@@ -3346,7 +3345,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot change share type');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById'
])
@@ -3374,7 +3373,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Can only update recipient on user shares');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById'
])
@@ -3402,7 +3401,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot share with the share owner');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById'
])
@@ -3429,7 +3428,7 @@ class ManagerTest extends \Test\TestCase {
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3468,14 +3467,14 @@ class ManagerTest extends \Test\TestCase {
->with($share)
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
$this->rootFolder->method('getUserFolder')->with('newUser')->willReturnSelf();
$this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post');
$hookListener2->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3493,7 +3492,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareGroup(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3526,11 +3525,11 @@ class ManagerTest extends \Test\TestCase {
->with($share)
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
@@ -3539,7 +3538,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareLink(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3588,7 +3587,7 @@ class ManagerTest extends \Test\TestCase {
->with($share)
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3597,7 +3596,7 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3607,7 +3606,7 @@ class ManagerTest extends \Test\TestCase {
'disabled' => false,
]);
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -3620,7 +3619,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3669,15 +3668,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -3686,7 +3685,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareMail(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3738,7 +3737,7 @@ class ManagerTest extends \Test\TestCase {
->with($share, 'password')
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3747,7 +3746,7 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3757,7 +3756,7 @@ class ManagerTest extends \Test\TestCase {
'disabled' => false,
]);
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -3766,7 +3765,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareMailEnableSendPasswordByTalk(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3821,7 +3820,7 @@ class ManagerTest extends \Test\TestCase {
->with($share, 'password')
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3830,7 +3829,7 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3840,7 +3839,7 @@ class ManagerTest extends \Test\TestCase {
'disabled' => false,
]);
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -3849,7 +3848,7 @@ class ManagerTest extends \Test\TestCase {
public function testUpdateShareMailEnableSendPasswordByTalkWithDifferentPassword(): void {
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3909,7 +3908,7 @@ class ManagerTest extends \Test\TestCase {
->with($share, 'password')
->willReturn($share);
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3918,7 +3917,7 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->once())->method('post')->with([
'itemType' => 'file',
@@ -3928,7 +3927,7 @@ class ManagerTest extends \Test\TestCase {
'disabled' => false,
]);
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -3940,7 +3939,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -3992,15 +3991,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4013,7 +4012,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -4065,15 +4064,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4086,7 +4085,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -4138,15 +4137,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4159,7 +4158,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot enable sending the password by Talk without setting a new password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -4213,15 +4212,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4233,7 +4232,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot disable sending the password by Talk without setting a new password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -4287,15 +4286,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4307,7 +4306,7 @@ class ManagerTest extends \Test\TestCase {
$this->expectExceptionMessage('Cannot disable sending the password by Talk without setting a new password');
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'canShare',
'getShareById',
'generalCreateChecks',
@@ -4361,15 +4360,15 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider->expects($this->never())
->method('update');
- $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post');
$hookListener->expects($this->never())->method('post');
- $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener2 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post');
$hookListener2->expects($this->never())->method('post');
- $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ $hookListener3 = $this->createMock(DummyShareManagerListener::class);
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post');
$hookListener3->expects($this->never())->method('post');
@@ -4492,7 +4491,7 @@ class ManagerTest extends \Test\TestCase {
);
}
- public function dataTestShareProviderExists() {
+ public static function dataTestShareProviderExists() {
return [
[IShare::TYPE_USER, true],
[42, false],
@@ -4831,7 +4830,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($expects, $result);
}
- public function dataCurrentUserCanEnumerateTargetUser(): array {
+ public static function dataCurrentUserCanEnumerateTargetUser(): array {
return [
'Full match guest' => [true, true, false, false, false, false, false, true],
'Full match user' => [false, true, false, false, false, false, false, true],
@@ -4860,7 +4859,7 @@ class ManagerTest extends \Test\TestCase {
public function testCurrentUserCanEnumerateTargetUser(bool $currentUserIsGuest, bool $allowEnumerationFullMatch, bool $allowEnumeration, bool $limitEnumerationToPhone, bool $limitEnumerationToGroups, bool $isKnownToUser, bool $haveCommonGroup, bool $expected): void {
/** @var IManager|MockObject $manager */
$manager = $this->createManagerMock()
- ->setMethods([
+ ->onlyMethods([
'allowEnumerationFullMatch',
'allowEnumeration',
'limitEnumerationToPhone',