aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core')
-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
33 files changed, 249 insertions, 191 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,