test: Finish migrating tests/Core/ to PHPUnit 10 compatible code

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/52588/head
Joas Schilling 2025-05-02 14:00:10 +07:00
parent 9a16e4fd14
commit c24f5fb256
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
46 changed files with 864 additions and 880 deletions

@ -50,7 +50,7 @@ class AppsDisableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode()); $this->assertSame($statusCode, $this->commandTester->getStatusCode());
} }
public function dataCommandInput(): array { public static function dataCommandInput(): array {
return [ return [
[['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'], [['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
[['comments'], 0, 'comments ([\d\.]*) disabled'], [['comments'], 0, 'comments ([\d\.]*) disabled'],

@ -57,7 +57,7 @@ class AppsEnableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode()); $this->assertSame($statusCode, $this->commandTester->getStatusCode());
} }
public function dataCommandInput(): array { public static function dataCommandInput(): array {
return [ return [
[['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'], [['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'],
[['comments'], null, 0, 'comments ([\d\.]*) enabled'], [['comments'], null, 0, 'comments ([\d\.]*) enabled'],

@ -38,7 +38,7 @@ class ImportTest extends TestCase {
$this->command = new Import($config); $this->command = new Import($config);
} }
public function validateAppsArrayData() { public static function validateAppsArrayData(): array {
return [ return [
[0], [0],
[1], [1],
@ -58,7 +58,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown'); $this->assertTrue(true, 'Asserting that no exception is thrown');
} }
public function validateAppsArrayThrowsData() { public static function validateAppsArrayThrowsData(): array {
return [ return [
[false], [false],
[true], [true],
@ -81,7 +81,7 @@ class ImportTest extends TestCase {
} }
} }
public function checkTypeRecursivelyData() { public static function checkTypeRecursivelyData(): array {
return [ return [
[0], [0],
[1], [1],
@ -107,7 +107,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown'); $this->assertTrue(true, 'Asserting that no exception is thrown');
} }
public function checkTypeRecursivelyThrowsData() { public static function checkTypeRecursivelyThrowsData(): array {
return [ return [
[new \Exception()], [new \Exception()],
[[new \Exception()]], [[new \Exception()]],
@ -130,7 +130,7 @@ class ImportTest extends TestCase {
} }
} }
public function validateArrayData() { public static function validateArrayData(): array {
return [ return [
[['system' => []]], [['system' => []]],
[['apps' => []]], [['apps' => []]],
@ -148,7 +148,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown'); $this->assertTrue(true, 'Asserting that no exception is thrown');
} }
public function validateArrayThrowsData() { public static function validateArrayThrowsData(): array {
return [ return [
[[], 'At least one key of the following is expected:'], [[], 'At least one key of the following is expected:'],
[[0 => []], 'Found invalid entries in root'], [[0 => []], 'Found invalid entries in root'],

@ -46,7 +46,7 @@ class ListConfigsTest extends TestCase {
$this->command = new ListConfigs($systemConfig, $appConfig); $this->command = new ListConfigs($systemConfig, $appConfig);
} }
public function listData() { public static function listData(): array {
return [ return [
[ [
'all', 'all',

@ -38,7 +38,7 @@ class DeleteConfigTest extends TestCase {
$this->command = new DeleteConfig($systemConfig); $this->command = new DeleteConfig($systemConfig);
} }
public function deleteData() { public static function deleteData(): array {
return [ return [
[ [
'name1', 'name1',
@ -105,7 +105,7 @@ class DeleteConfigTest extends TestCase {
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
} }
public function deleteArrayData() { public static function deleteArrayData(): array {
return [ return [
[ [
['name', 'sub'], ['name', 'sub'],

@ -39,7 +39,7 @@ class GetConfigTest extends TestCase {
} }
public function getData() { public static function getData(): array {
return [ return [
// String output as json // String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],

@ -76,7 +76,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
public function setUpdateOnlyProvider() { public static function setUpdateOnlyProvider(): array {
return [ return [
[['name'], null], [['name'], null],
[['a', 'b', 'c'], null], [['a', 'b', 'c'], null],
@ -113,7 +113,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
public function castValueProvider() { public static function castValueProvider(): array {
return [ return [
[null, 'string', ['value' => '', 'readable-value' => 'empty string']], [null, 'string', ['value' => '', 'readable-value' => 'empty string']],
@ -141,7 +141,7 @@ class SetConfigTest extends TestCase {
); );
} }
public function castValueInvalidProvider() { public static function castValueInvalidProvider(): array {
return [ return [
['123', 'foobar'], ['123', 'foobar'],

@ -89,7 +89,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util, $this->util,
$this->questionHelper $this->questionHelper
] ]
)->setMethods(['moveAllKeys'])->getMock(); )->onlyMethods(['moveAllKeys'])->getMock();
$this->util->expects($this->once())->method('getKeyStorageRoot') $this->util->expects($this->once())->method('getKeyStorageRoot')
->willReturn(''); ->willReturn('');
@ -122,7 +122,7 @@ class ChangeKeyStorageRootTest extends TestCase {
); );
} }
public function dataTestExecute() { public static function dataTestExecute(): array {
return [ return [
[null, true, true], [null, true, true],
[null, true, false], [null, true, false],
@ -143,7 +143,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util, $this->util,
$this->questionHelper $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('prepareNewRoot')->with('newRoot');
$changeKeyStorageRoot->expects($this->once())->method('moveSystemKeys')->with('oldRoot', 'newRoot'); $changeKeyStorageRoot->expects($this->once())->method('moveSystemKeys')->with('oldRoot', 'newRoot');
@ -179,7 +179,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']); $this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
} }
public function dataTestPrepareNewRootException() { public static function dataTestPrepareNewRootException(): array {
return [ return [
[true, false], [true, false],
[true, null], [true, null],
@ -204,7 +204,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util, $this->util,
$this->questionHelper $this->questionHelper
] ]
)->setMethods(['targetExists'])->getMock(); )->onlyMethods(['targetExists'])->getMock();
$this->view->expects($this->once())->method('is_dir') $this->view->expects($this->once())->method('is_dir')
->with('oldRoot/files_encryption')->willReturn($dirExists); ->with('oldRoot/files_encryption')->willReturn($dirExists);
@ -221,7 +221,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveSystemKeys', ['oldRoot', 'newRoot']); $this->invokePrivate($changeKeyStorageRoot, 'moveSystemKeys', ['oldRoot', 'newRoot']);
} }
public function dataTestMoveSystemKeys() { public static function dataTestMoveSystemKeys(): array {
return [ return [
[true, false, true], [true, false, true],
[false, true, false], [false, true, false],
@ -241,7 +241,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util, $this->util,
$this->questionHelper $this->questionHelper
] ]
)->setMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock(); )->onlyMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
$this->userManager->expects($this->once())->method('getBackends') $this->userManager->expects($this->once())->method('getBackends')
->willReturn([$this->userInterface]); ->willReturn([$this->userInterface]);
@ -271,7 +271,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util, $this->util,
$this->questionHelper $this->questionHelper
] ]
)->setMethods(['targetExists', 'prepareParentFolder'])->getMock(); )->onlyMethods(['targetExists', 'prepareParentFolder'])->getMock();
$this->userManager->expects($this->once())->method('userExists') $this->userManager->expects($this->once())->method('userExists')
->willReturn($userExists); ->willReturn($userExists);
@ -293,7 +293,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveUserEncryptionFolder', ['user1', 'oldRoot', 'newRoot']); $this->invokePrivate($changeKeyStorageRoot, 'moveUserEncryptionFolder', ['user1', 'oldRoot', 'newRoot']);
} }
public function dataTestMoveUserEncryptionFolder() { public static function dataTestMoveUserEncryptionFolder(): array {
return [ return [
[true, true, false, true], [true, true, false, true],
[true, false, true, false], [true, false, true, false],
@ -334,7 +334,7 @@ class ChangeKeyStorageRootTest extends TestCase {
); );
} }
public function dataTestPrepareParentFolder() { public static function dataTestPrepareParentFolder(): array {
return [ return [
['/user/folder/sub_folder/keystorage', true], ['/user/folder/sub_folder/keystorage', true],
['/user/folder/sub_folder/keystorage', false] ['/user/folder/sub_folder/keystorage', false]

@ -73,12 +73,16 @@ class DecryptAllTest extends TestCase {
public function testMaintenanceAndTrashbin(): void { public function testMaintenanceAndTrashbin(): void {
// on construct we enable single-user-mode and disable the trash bin // 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 // on destruct we disable single-user-mode again and enable the trash bin
$calls = [
['maintenance', true],
['maintenance', false],
];
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('setSystemValue') ->method('setSystemValue')
->withConsecutive( ->willReturnCallback(function () use (&$calls) {
['maintenance', true], $expected = array_shift($calls);
['maintenance', false], $this->assertEquals($expected, func_get_args());
); });
$this->appManager->expects($this->once()) $this->appManager->expects($this->once())
->method('disableApp') ->method('disableApp')
->with('files_trashbin'); ->with('files_trashbin');
@ -127,12 +131,16 @@ class DecryptAllTest extends TestCase {
->willReturn('user1'); ->willReturn('user1');
if ($encryptionEnabled) { if ($encryptionEnabled) {
$calls = [
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', 'yes'],
];
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->willReturnCallback(function () use (&$calls) {
['core', 'encryption_enabled', 'no'], $expected = array_shift($calls);
['core', 'encryption_enabled', 'yes'], $this->assertEquals($expected, func_get_args());
); });
$this->questionHelper->expects($this->once()) $this->questionHelper->expects($this->once())
->method('ask') ->method('ask')
->willReturn($continue); ->willReturn($continue);
@ -152,7 +160,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'execute', [$this->consoleInput, $this->consoleOutput]); $this->invokePrivate($instance, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
public function dataTestExecute() { public static function dataTestExecute(): array {
return [ return [
[true, true], [true, true],
[true, false], [true, false],
@ -174,13 +182,16 @@ class DecryptAllTest extends TestCase {
); );
// make sure that we enable encryption again after a exception was thrown // 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)) $this->config->expects($this->exactly(2))
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->willReturnCallback(function () use (&$calls) {
['core', 'encryption_enabled', 'no'], $expected = array_shift($calls);
['core', 'encryption_enabled', 'yes'], $this->assertEquals($expected, func_get_args());
); });
$this->encryptionManager->expects($this->once()) $this->encryptionManager->expects($this->once())
->method('isEnabled') ->method('isEnabled')
->willReturn(true); ->willReturn(true);

@ -38,7 +38,7 @@ class DisableTest extends TestCase {
} }
public function dataDisable() { public static function dataDisable(): array {
return [ return [
['yes', true, 'Encryption disabled'], ['yes', true, 'Encryption disabled'],
['no', false, 'Encryption is already disabled'], ['no', false, 'Encryption is already disabled'],

@ -99,7 +99,7 @@ class EncryptAllTest extends TestCase {
$this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]); $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
public function dataTestExecute() { public static function dataTestExecute(): array {
return [ return [
['y', true], ['Y', true], ['n', false], ['N', false], ['', false] ['y', true], ['Y', true], ['n', false], ['N', false], ['', false]
]; ];

@ -43,7 +43,7 @@ class SetDefaultModuleTest extends TestCase {
} }
public function dataSetDefaultModule() { public static function dataSetDefaultModule(): array {
return [ return [
['ID0', 'ID0', null, null, 'already'], ['ID0', 'ID0', null, null, 'already'],
['ID0', 'ID1', 'ID1', true, 'info'], ['ID0', 'ID1', 'ID1', true, 'info'],
@ -113,12 +113,16 @@ class SetDefaultModuleTest extends TestCase {
->with('maintenance', false) ->with('maintenance', false)
->willReturn(true); ->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)) $this->consoleOutput->expects($this->exactly(2))
->method('writeln') ->method('writeln')
->withConsecutive( ->willReturnCallback(function ($message) use (&$calls) {
[$this->stringContains('Maintenance mode must be disabled when setting default module,')], $expected = array_shift($calls);
[$this->stringContains('in order to load the relevant encryption modules correctly.')], $this->assertStringContainsString($expected, $message);
); });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }

@ -32,7 +32,7 @@ class InfoTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(Info::class) $this->command = $this->getMockBuilder(Info::class)
->setConstructorArgs([$this->groupManager]) ->setConstructorArgs([$this->groupManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -33,7 +33,7 @@ class ListCommandTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(ListCommand::class) $this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->groupManager]) ->setConstructorArgs([$this->groupManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -33,15 +33,10 @@ class UpdateDBTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->detector = $this->getMockBuilder(Detection::class) $this->detector = $this->createMock(Detection::class);
->disableOriginalConstructor() $this->loader = $this->createMock(Loader::class);
->getMock(); $this->consoleInput = $this->createMock(InputInterface::class);
$this->loader = $this->getMockBuilder(Loader::class) $this->consoleOutput = $this->createMock(OutputInterface::class);
->disableOriginalConstructor()
->getMock();
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
$this->command = new UpdateDB($this->detector, $this->loader); $this->command = new UpdateDB($this->detector, $this->loader);
} }
@ -64,12 +59,16 @@ class UpdateDBTest extends TestCase {
$this->loader->expects($this->never()) $this->loader->expects($this->never())
->method('updateFilecache'); ->method('updateFilecache');
$calls = [
'Added 0 new mimetypes',
'Updated 0 filecache rows',
];
$this->consoleOutput->expects($this->exactly(2)) $this->consoleOutput->expects($this->exactly(2))
->method('writeln') ->method('writeln')
->withConsecutive( ->willReturnCallback(function ($message) use (&$calls) {
['Added 0 new mimetypes'], $expected = array_shift($calls);
['Updated 0 filecache rows'], $this->assertStringContainsString($expected, $message);
); });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
@ -103,14 +102,18 @@ class UpdateDBTest extends TestCase {
->with('new', 2) ->with('new', 2)
->willReturn(3); ->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)) $this->consoleOutput->expects($this->exactly(4))
->method('writeln') ->method('writeln')
->withConsecutive( ->willReturnCallback(function ($message) use (&$calls) {
['Added mimetype "testing/newmimetype" to database'], $expected = array_shift($calls);
['Updated 3 filecache rows for mimetype "testing/newmimetype"'], $this->assertStringContainsString($expected, $message);
['Added 1 new mimetypes'], });
['Updated 3 filecache rows'],
);
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }
@ -153,13 +156,17 @@ class UpdateDBTest extends TestCase {
->with('ext', 1) ->with('ext', 1)
->willReturn(3); ->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)) $this->consoleOutput->expects($this->exactly(3))
->method('writeln') ->method('writeln')
->withConsecutive( ->willReturnCallback(function ($message) use (&$calls) {
['Updated 3 filecache rows for mimetype "testing/existingmimetype"'], $expected = array_shift($calls);
['Added 0 new mimetypes'], $this->assertStringContainsString($expected, $message);
['Updated 3 filecache rows'], });
);
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
} }

@ -67,7 +67,7 @@ class ModeTest extends TestCase {
* *
* @return array * @return array
*/ */
public function getExecuteTestData(): array { public static function getExecuteTestData(): array {
return [ return [
'off -> on' => [ 'off -> on' => [
'on', // command option 'on', // command option

@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase; use Test\TestCase;
@ -54,8 +55,7 @@ class RepairTest extends TestCase {
$this->iniGetWrapper, $this->iniGetWrapper,
$this->createMock(ILockingProvider::class) $this->createMock(ILockingProvider::class)
); );
$this->input = $this->getMockBuilder(InputInterface::class) $this->input = $this->createMock(InputInterface::class);
->getMock();
$this->input->expects($this->any()) $this->input->expects($this->any())
->method('getOption') ->method('getOption')
->willReturnCallback(function ($parameter) { ->willReturnCallback(function ($parameter) {
@ -64,13 +64,10 @@ class RepairTest extends TestCase {
} }
return null; return null;
}); });
$this->output = $this->getMockBuilder(OutputInterface::class) $this->output = $this->getMockBuilder(ConsoleOutput::class)
->setMethods(['section', 'writeln', 'write', 'setVerbosity', 'getVerbosity', 'isQuiet', 'isVerbose', 'isVeryVerbose', 'isDebug', 'setDecorated', 'isDecorated', 'setFormatter', 'getFormatter']) ->onlyMethods(['section', 'writeln', 'getFormatter'])
->getMock(); ->getMock();
$self = $this; $self = $this;
$this->output->expects($this->any())
->method('section')
->willReturn($this->output);
/* We need format method to return a string */ /* We need format method to return a string */
$outputFormatter = $this->createMock(OutputFormatterInterface::class); $outputFormatter = $this->createMock(OutputFormatterInterface::class);
@ -87,7 +84,7 @@ class RepairTest extends TestCase {
}); });
} }
public function emptyTestDataProvider() { public static function dataEmptyTest(): array {
/** directoryNames, expectedOutput */ /** directoryNames, expectedOutput */
return [ return [
[ [
@ -114,7 +111,7 @@ class RepairTest extends TestCase {
} }
/** /**
* @dataProvider emptyTestDataProvider * @dataProvider dataEmptyTest
*/ */
public function testEmptyExecute($directoryNames, $expectedOutput): void { public function testEmptyExecute($directoryNames, $expectedOutput): void {
$previewFolder = $this->getMockBuilder(Folder::class) $previewFolder = $this->getMockBuilder(Folder::class)

@ -33,7 +33,7 @@ class AddTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class); $this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Add::class) $this->command = $this->getMockBuilder(Add::class)
->setConstructorArgs([$this->systemTagManager]) ->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -32,7 +32,7 @@ class DeleteTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class); $this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Delete::class) $this->command = $this->getMockBuilder(Delete::class)
->setConstructorArgs([$this->systemTagManager]) ->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -33,7 +33,7 @@ class EditTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class); $this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Edit::class) $this->command = $this->getMockBuilder(Edit::class)
->setConstructorArgs([$this->systemTagManager]) ->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -32,7 +32,7 @@ class ListCommandTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class); $this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(ListCommand::class) $this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->systemTagManager]) ->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat']) ->onlyMethods(['writeArrayInOutputFormat'])
->getMock(); ->getMock();
$this->input = $this->createMock(InputInterface::class); $this->input = $this->createMock(InputInterface::class);

@ -126,7 +126,7 @@ class AddTest extends TestCase {
/** /**
* @return array * @return array
*/ */
public function addEmailDataProvider(): array { public static function addEmailDataProvider(): array {
return [ return [
'Valid E-Mail' => [ 'Valid E-Mail' => [
'info@example.com', 'info@example.com',

@ -39,7 +39,7 @@ class DeleteTest extends TestCase {
} }
public function validUserLastSeen() { public static function validUserLastSeen(): array {
return [ return [
[true, 'The specified user was deleted'], [true, 'The specified user was deleted'],
[false, 'The specified user could not be deleted'], [false, 'The specified user could not be deleted'],

@ -38,7 +38,7 @@ class LastSeenTest extends TestCase {
$this->command = new LastSeen($userManager); $this->command = new LastSeen($userManager);
} }
public function validUserLastSeen() { public static function validUserLastSeen(): array {
return [ return [
[0, 'never logged in'], [0, 'never logged in'],
[time(), 'last login'], [time(), 'last login'],

@ -62,7 +62,7 @@ class SettingTest extends TestCase {
} }
} }
public function dataCheckInput() { public static function dataCheckInput(): array {
return [ return [
[ [
[['uid', 'username']], [['uid', 'username']],
@ -235,7 +235,7 @@ class SettingTest extends TestCase {
$this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); $this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
} }
public function dataExecuteDelete() { public static function dataExecuteDelete(): array {
return [ return [
['config', false, null, 0], ['config', false, null, 0],
['config', true, 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])); $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
} }
public function dataExecuteSet() { public static function dataExecuteSet(): array {
return [ return [
['config', false, null, 0], ['config', false, null, 0],
['config', true, 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])); $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
} }
public function dataExecuteGet() { public static function dataExecuteGet(): array {
return [ return [
['config', null, 'config', 0], ['config', null, 'config', 0],
[null, 'config', 'config', 0], [null, 'config', 'config', 0],

@ -42,7 +42,7 @@ class AutoCompleteControllerTest extends TestCase {
); );
} }
public function searchDataProvider() { public static function searchDataProvider(): array {
return [ return [
[ #0 regular search [ #0 regular search
// searchResults // searchResults

@ -118,10 +118,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOcsHeader(): void { public function testShowAuthPickerPageWithOcsHeader(): void {
$this->request $this->request
->method('getHeader') ->method('getHeader')
->withConsecutive(
['USER_AGENT'],
['OCS-APIREQUEST']
)
->willReturnMap([ ->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'], ['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'true'], ['OCS-APIREQUEST', 'true'],
@ -181,10 +177,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOauth(): void { public function testShowAuthPickerPageWithOauth(): void {
$this->request $this->request
->method('getHeader') ->method('getHeader')
->withConsecutive(
['USER_AGENT'],
['OCS-APIREQUEST']
)
->willReturnMap([ ->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'], ['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'false'], ['OCS-APIREQUEST', 'false'],
@ -404,20 +396,20 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl): void { public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl): void {
$this->session $this->session
->method('get') ->method('get')
->withConsecutive(
['client.flow.state.token'],
['oauth.state']
)
->willReturnMap([ ->willReturnMap([
['client.flow.state.token', 'MyStateToken'], ['client.flow.state.token', 'MyStateToken'],
['oauth.state', 'MyOauthState'], ['oauth.state', 'MyOauthState'],
]); ]);
$calls = [
'client.flow.state.token',
'oauth.state',
];
$this->session $this->session
->method('remove') ->method('remove')
->withConsecutive( ->willReturnCallback(function ($key) use (&$calls) {
['client.flow.state.token'], $expected = array_shift($calls);
['oauth.state'] $this->assertEquals($expected, $key);
); });
$this->session $this->session
->expects($this->once()) ->expects($this->once())
->method('getId') ->method('getId')
@ -439,10 +431,6 @@ class ClientFlowLoginControllerTest extends TestCase {
->willReturn('MyPassword'); ->willReturn('MyPassword');
$this->random $this->random
->method('generate') ->method('generate')
->withConsecutive(
[72],
[128]
)
->willReturnMap([ ->willReturnMap([
[72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'], [72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'],
[128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyAccessCode'], [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')); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
} }
public function dataGeneratePasswordWithHttpsProxy() { public static function dataGeneratePasswordWithHttpsProxy(): array {
return [ return [
[ [
[ [

@ -255,9 +255,9 @@ class LoginControllerTest extends TestCase {
], ],
] ]
); );
$this->initialState->expects($this->exactly(13))
->method('provideInitialState') $calls = [
->withConsecutive([ [
'loginMessages', 'loginMessages',
[ [
'MessageArray1', 'MessageArray1',
@ -265,17 +265,26 @@ class LoginControllerTest extends TestCase {
'This community release of Nextcloud is unsupported and push notifications are limited.', '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( $expectedResponse = new TemplateResponse(
'core', 'core',
@ -294,15 +303,25 @@ class LoginControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('isLoggedIn') ->method('isLoggedIn')
->willReturn(false); ->willReturn(false);
$this->initialState->expects($this->exactly(14)) $calls = [
->method('provideInitialState') [], [], [],
->withConsecutive([], [], [], [ [
'loginAutocomplete', 'loginAutocomplete',
false false
], [ ],
[
'loginRedirectUrl', 'loginRedirectUrl',
'login/flow' '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( $expectedResponse = new TemplateResponse(
'core', 'core',
@ -319,7 +338,7 @@ class LoginControllerTest extends TestCase {
/** /**
* @return array * @return array
*/ */
public function passwordResetDataProvider(): array { public static function passwordResetDataProvider(): array {
return [ return [
[ [
true, true,
@ -363,15 +382,26 @@ class LoginControllerTest extends TestCase {
->method('get') ->method('get')
->with('LdapUser') ->with('LdapUser')
->willReturn($user); ->willReturn($user);
$this->initialState->expects($this->exactly(13)) $calls = [
->method('provideInitialState') [], [],
->withConsecutive([], [], [ [
'loginUsername', 'loginUsername',
'LdapUser' 'LdapUser'
], [], [], [], [ ],
[], [], [],
[
'loginCanResetPassword', 'loginCanResetPassword',
$expectedResult $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( $expectedResponse = new TemplateResponse(
'core', 'core',
@ -411,18 +441,30 @@ class LoginControllerTest extends TestCase {
->method('get') ->method('get')
->with('0') ->with('0')
->willReturn($user); ->willReturn($user);
$this->initialState->expects($this->exactly(13)) $calls = [
->method('provideInitialState') [], [], [],
->withConsecutive([], [], [], [ [
'loginAutocomplete', 'loginAutocomplete',
true true
], [], [ ],
[],
[
'loginResetPasswordLink', 'loginResetPasswordLink',
false false
], [ ],
[
'loginCanResetPassword', 'loginCanResetPassword',
false 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( $expectedResponse = new TemplateResponse(
'core', 'core',

@ -172,13 +172,18 @@ class LostControllerTest extends TestCase {
->method('linkToRouteAbsolute') ->method('linkToRouteAbsolute')
->with('core.lost.setPassword', ['userId' => 'ValidTokenUser', 'token' => 'MySecretToken']) ->with('core.lost.setPassword', ['userId' => 'ValidTokenUser', 'token' => 'MySecretToken'])
->willReturn('https://example.tld/index.php/lostpassword/set/sometoken/someuser'); ->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 $this->initialState
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('provideInitialState') ->method('provideInitialState')
->withConsecutive( ->willReturnCallback(function () use (&$calls) {
['resetPasswordUser', 'ValidTokenUser'], $expected = array_shift($calls);
['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser'] $this->assertEquals($expected, func_get_args());
); });
$response = $this->lostController->resetform('MySecretToken', 'ValidTokenUser'); $response = $this->lostController->resetform('MySecretToken', 'ValidTokenUser');
$expectedResponse = new TemplateResponse('core', $expectedResponse = new TemplateResponse('core',
@ -448,12 +453,19 @@ class LostControllerTest extends TestCase {
$this->userManager->method('get') $this->userManager->method('get')
->with('ValidTokenUser') ->with('ValidTokenUser')
->willReturn($this->existingUser); ->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 $this->eventDispatcher
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('dispatchTyped') ->method('dispatchTyped')
->withConsecutive([$beforePasswordResetEvent], [$passwordResetEvent]); ->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('deleteUserValue') ->method('deleteUserValue')
->with('ValidTokenUser', 'core', 'lostpassword'); ->with('ValidTokenUser', 'core', 'lostpassword');
@ -666,15 +678,15 @@ class LostControllerTest extends TestCase {
/** /**
* @return array * @return array
*/ */
public function dataTwoUserswithSameEmailOneDisabled(): array { public static function dataTwoUsersWithSameEmailOneDisabled(): array {
return [ return [
['user1' => true, 'user2' => false], ['userEnabled1' => true, 'userEnabled2' => false],
['user1' => false, 'user2' => true] ['userEnabled1' => false, 'userEnabled2' => true]
]; ];
} }
/** /**
* @dataProvider dataTwoUserswithSameEmailOneDisabled * @dataProvider dataTwoUsersWithSameEmailOneDisabled
* @param bool $userEnabled1 * @param bool $userEnabled1
* @param bool $userEnabled2 * @param bool $userEnabled2
*/ */

@ -68,7 +68,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->logger, $this->logger,
]) ])
->setMethods(['getLogoutUrl']) ->onlyMethods(['getLogoutUrl'])
->getMock(); ->getMock();
$this->controller->expects($this->any()) $this->controller->expects($this->any())
->method('getLogoutUrl') ->method('getLogoutUrl')
@ -302,12 +302,16 @@ class TwoFactorChallengeControllerTest extends TestCase {
->method('verifyChallenge') ->method('verifyChallenge')
->with('myprovider', $user, 'token') ->with('myprovider', $user, 'token')
->will($this->throwException($exception)); ->will($this->throwException($exception));
$calls = [
['two_factor_auth_error_message', '2FA failed'],
['two_factor_auth_error', true],
];
$this->session->expects($this->exactly(2)) $this->session->expects($this->exactly(2))
->method('set') ->method('set')
->withConsecutive( ->willReturnCallback(function () use (&$calls) {
['two_factor_auth_error_message', '2FA failed'], $expected = array_shift($calls);
['two_factor_auth_error', true] $this->assertEquals($expected, func_get_args());
); });
$this->urlGenerator->expects($this->once()) $this->urlGenerator->expects($this->once())
->method('linkToRoute') ->method('linkToRoute')
->with('core.TwoFactorChallenge.showChallenge', [ ->with('core.TwoFactorChallenge.showChallenge', [

@ -33,7 +33,7 @@ class WipeControllerTest extends TestCase {
$this->remoteWipe); $this->remoteWipe);
} }
public function dataTest() { public static function dataTest(): array {
return [ return [
// valid token, could perform operation, valid result // valid token, could perform operation, valid result
[ true, true, true], [ true, true, true],

@ -234,23 +234,29 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($twoFactorChallengeController, 'index'); $this->middleware->beforeController($twoFactorChallengeController, 'index');
} }
public function dataRequires2FASetupDone() { public static function dataRequires2FASetupDone(): array {
$provider = $this->createMock(IProvider::class);
$provider->method('getId')
->willReturn('2FAftw');
return [ return [
[[], false, false], [false, false, false],
[[], true, true], [false, true, true],
[[$provider], false, true], [true, false, true],
[[$provider], true, true], [true, true, true],
]; ];
} }
/** /**
* @dataProvider dataRequires2FASetupDone * @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); $user = $this->createMock(IUser::class);
$this->reflector $this->reflector

@ -67,26 +67,13 @@ class LoginFlowV2ServiceUnitTest extends TestCase {
* Code was moved to separate function to keep setUp function small and clear. * Code was moved to separate function to keep setUp function small and clear.
*/ */
private function setupSubjectUnderTest(): void { private function setupSubjectUnderTest(): void {
$this->config = $this->getMockBuilder(IConfig::class) $this->config = $this->createMock(IConfig::class);
->disableOriginalConstructor()->getMock(); $this->crypto = $this->createMock(ICrypto::class);
$this->mapper = $this->createMock(LoginFlowV2Mapper::class);
$this->crypto = $this->getMockBuilder(ICrypto::class) $this->logger = $this->createMock(LoggerInterface::class);
->disableOriginalConstructor()->getMock(); $this->tokenProvider = $this->createMock(IProvider::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->mapper = $this->getMockBuilder(LoginFlowV2Mapper::class) $this->timeFactory = $this->createMock(ITimeFactory::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->subjectUnderTest = new LoginFlowV2Service( $this->subjectUnderTest = new LoginFlowV2Service(
$this->mapper, $this->mapper,

@ -76,13 +76,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes'); ->willReturn('yes');
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['gs.enabled', false], ['gs.enabled', false, true],
['has_internet_connection', true], ['has_internet_connection', true, true],
)->willReturnOnConsecutiveCalls( ]);
true,
true,
);
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
@ -105,13 +102,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes'); ->willReturn('yes');
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['gs.enabled', false], ['gs.enabled', false, false],
['has_internet_connection', true], ['has_internet_connection', true, false],
)->willReturnOnConsecutiveCalls( ]);
false,
false,
);
$this->clientService->expects($this->never()) $this->clientService->expects($this->never())
->method('newClient'); ->method('newClient');
@ -141,13 +135,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes'); ->willReturn('yes');
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['gs.enabled', false], ['gs.enabled', false, true],
['has_internet_connection', true], ['has_internet_connection', true, true],
)->willReturnOnConsecutiveCalls( ]);
true,
true,
);
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
@ -206,13 +197,10 @@ class LookupPluginTest extends TestCase {
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['gs.enabled', false], ['gs.enabled', false, $GSEnabled],
['has_internet_connection', true], ['has_internet_connection', true, true],
)->willReturnOnConsecutiveCalls( ]);
$GSEnabled,
true,
);
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com') ->with('lookup_server', 'https://lookup.nextcloud.com')
@ -239,13 +227,10 @@ class LookupPluginTest extends TestCase {
$searchResult->expects($this->never())->method('addResultSet'); $searchResult->expects($this->never())->method('addResultSet');
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['gs.enabled', false], ['gs.enabled', false, $GSEnabled],
['has_internet_connection', true], ['has_internet_connection', true, true],
)->willReturnOnConsecutiveCalls( ]);
$GSEnabled,
true,
);
} }
$moreResults = $this->plugin->search( $moreResults = $this->plugin->search(
$searchParams['search'], $searchParams['search'],
@ -276,7 +261,7 @@ class LookupPluginTest extends TestCase {
$this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult)); $this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult));
} }
public function dataSearchEnableDisableLookupServer() { public static function dataSearchEnableDisableLookupServer(): array {
$fedIDs = [ $fedIDs = [
'foo@enceladus.moon', 'foo@enceladus.moon',
'foobar@enceladus.moon', 'foobar@enceladus.moon',
@ -449,7 +434,7 @@ class LookupPluginTest extends TestCase {
]; ];
} }
public function searchDataProvider() { public static function searchDataProvider(): array {
$fedIDs = [ $fedIDs = [
'foo@enceladus.moon', 'foo@enceladus.moon',
'foobar@enceladus.moon', 'foobar@enceladus.moon',

@ -255,29 +255,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class); $user2 = $this->createMock(IUser::class);
$user3 = $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)) $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds') ->method('getUserGroupIds')
->withConsecutive( ->willReturnCallback(function () use (&$calls): array {
[$this->equalTo($currentUser)], $expected = array_shift($calls);
[$this->equalTo($user1)], $this->assertEquals($expected[0], func_get_args());
[$this->equalTo($user2)], return $expected[1];
[$this->equalTo($user3)] });
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
$this->userManager->expects($this->exactly(3)) $this->userManager->expects($this->exactly(3))
->method('get') ->method('get')
->withConsecutive( ->willReturnMap([
['user1'], ['user1', $user1],
['user2'], ['user2', $user2],
['user3'] ['user3', $user3],
) ]);
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->contactsManager->expects($this->once()) $this->contactsManager->expects($this->once())
->method('search') ->method('search')
@ -330,29 +328,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class); $user2 = $this->createMock(IUser::class);
$user3 = $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)) $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds') ->method('getUserGroupIds')
->withConsecutive( ->willReturnCallback(function () use (&$calls): array {
[$this->equalTo($currentUser)], $expected = array_shift($calls);
[$this->equalTo($user1)], $this->assertEquals($expected[0], func_get_args());
[$this->equalTo($user2)], return $expected[1];
[$this->equalTo($user3)] });
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
$this->userManager->expects($this->exactly(3)) $this->userManager->expects($this->exactly(3))
->method('get') ->method('get')
->withConsecutive( ->willReturnMap([
['user1'], ['user1', $user1],
['user2'], ['user2', $user2],
['user3'] ['user3', $user3],
) ]);
->willReturn($user1, $user2, $user3);
$this->contactsManager->expects($this->once()) $this->contactsManager->expects($this->once())
->method('search') ->method('search')
@ -463,29 +459,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class); $user2 = $this->createMock(IUser::class);
$user3 = $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)) $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds') ->method('getUserGroupIds')
->withConsecutive( ->willReturnCallback(function () use (&$calls): array {
[$this->equalTo($currentUser)], $expected = array_shift($calls);
[$this->equalTo($user1)], $this->assertEquals($expected[0], func_get_args());
[$this->equalTo($user2)], return $expected[1];
[$this->equalTo($user3)] });
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
$this->userManager->expects($this->exactly(3)) $this->userManager->expects($this->exactly(3))
->method('get') ->method('get')
->withConsecutive( ->willReturnMap([
['user1'], ['user1', $user1],
['user2'], ['user2', $user2],
['user3'] ['user3', $user3],
) ]);
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser') $this->knownUserService->method('isKnownToUser')
->willReturnMap([ ->willReturnMap([
@ -542,16 +536,17 @@ class ContactsStoreTest extends TestCase {
$user1 = $this->createMock(IUser::class); $user1 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
];
$this->groupManager->expects($this->exactly(2)) $this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds') ->method('getUserGroupIds')
->withConsecutive( ->willReturnCallback(function () use (&$calls): array {
[$this->equalTo($currentUser)], $expected = array_shift($calls);
[$this->equalTo($user1)] $this->assertEquals($expected[0], func_get_args());
) return $expected[1];
->willReturnOnConsecutiveCalls( });
['group1', 'group2', 'group3'],
['group1']
);
$this->userManager->expects($this->once()) $this->userManager->expects($this->once())
->method('get') ->method('get')
@ -617,29 +612,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class); $user2 = $this->createMock(IUser::class);
$user3 = $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)) $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds') ->method('getUserGroupIds')
->withConsecutive( ->willReturnCallback(function () use (&$calls): array {
[$this->equalTo($currentUser)], $expected = array_shift($calls);
[$this->equalTo($user1)], $this->assertEquals($expected[0], func_get_args());
[$this->equalTo($user2)], return $expected[1];
[$this->equalTo($user3)] });
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
$this->userManager->expects($this->exactly(3)) $this->userManager->expects($this->exactly(3))
->method('get') ->method('get')
->withConsecutive( ->willReturnMap([
['user1'], ['user1', $user1],
['user2'], ['user2', $user2],
['user3'] ['user3', $user3],
) ]);
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser') $this->knownUserService->method('isKnownToUser')
->willReturnMap([ ->willReturnMap([

@ -65,11 +65,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueInt') ->method('getSystemValueInt')
->withConsecutive( ->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT], ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 25],
['sharing.minSearchStringLength', 0] ['sharing.minSearchStringLength', 0, 0],
) ]);
->willReturnOnConsecutiveCalls(25, 0);
$this->contactsStore->expects($this->once()) $this->contactsStore->expects($this->once())
->method('getContacts') ->method('getContacts')
->with($user, $filter) ->with($user, $filter)
@ -102,11 +101,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueInt') ->method('getSystemValueInt')
->withConsecutive( ->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT], ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
['sharing.minSearchStringLength', 0] ['sharing.minSearchStringLength', 0, 0],
) ]);
->willReturnOnConsecutiveCalls(3, 0);
$this->contactsStore->expects($this->once()) $this->contactsStore->expects($this->once())
->method('getContacts') ->method('getContacts')
->with($user, $filter) ->with($user, $filter)
@ -138,11 +136,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValueInt') ->method('getSystemValueInt')
->withConsecutive( ->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT], ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
['sharing.minSearchStringLength', 0] ['sharing.minSearchStringLength', 0, 4],
) ]);
->willReturnOnConsecutiveCalls(3, 4);
$this->appManager->expects($this->once()) $this->appManager->expects($this->once())
->method('isEnabledForUser') ->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user) ->with($this->equalTo('contacts'), $user)

@ -173,8 +173,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class); $folder = $this->createMock(Folder::class);
$this->userFolder $this->userFolder
->method('nodeExists') ->method('nodeExists')
->withConsecutive(['/File.txt'], ['/']) ->willReturnMap([
->willReturnOnConsecutiveCalls(false, true); ['/File.txt', false],
['/', true],
]);
$this->userFolder $this->userFolder
->method('get') ->method('get')
->with('/') ->with('/')
@ -198,8 +200,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class); $folder = $this->createMock(Folder::class);
$this->userFolder $this->userFolder
->method('nodeExists') ->method('nodeExists')
->withConsecutive(['/File.txt'], ['/']) ->willReturnMap([
->willReturnOnConsecutiveCalls(false, true); ['/File.txt', false],
['/', true],
]);
$this->userFolder $this->userFolder
->method('get') ->method('get')
->with('/') ->with('/')
@ -226,11 +230,12 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once()) $this->random->expects($this->once())
->method('generate') ->method('generate')
->willReturn($expectedToken); ->willReturn($expectedToken);
$folder = $this->createMock(Folder::class);
$this->userFolder $this->userFolder
->method('nodeExists') ->method('nodeExists')
->withConsecutive(['/File.txt'], ['/']) ->willReturnMap([
->willReturnOnConsecutiveCalls(false, true); ['/File.txt', false],
['/', true],
]);
$this->userFolder $this->userFolder
->method('get') ->method('get')
->with('/File.txt') ->with('/File.txt')
@ -277,8 +282,10 @@ class ManagerTest extends TestCase {
]); ]);
$this->userFolder $this->userFolder
->method('nodeExists') ->method('nodeExists')
->withConsecutive(['/File.txt'], ['/']) ->willReturnMap([
->willReturnOnConsecutiveCalls(false, true); ['/File.txt', false],
['/', true],
]);
$this->userFolder $this->userFolder
->method('get') ->method('get')
->with('/') ->with('/')

@ -82,7 +82,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($this->instance, 'output', [$this->outputInterface]); $this->invokePrivate($this->instance, 'output', [$this->outputInterface]);
} }
public function dataDecryptAll() { public static function dataDecryptAll(): array {
return [ return [
[true, 'user1', true], [true, 'user1', true],
[false, 'user1', true], [false, 'user1', true],
@ -113,7 +113,7 @@ class DecryptAllTest extends TestCase {
$this->view $this->view
] ]
) )
->setMethods(['prepareEncryptionModules', 'decryptAllUsersFiles']) ->onlyMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
->getMock(); ->getMock();
$instance->expects($this->once()) $instance->expects($this->once())
@ -145,7 +145,7 @@ class DecryptAllTest extends TestCase {
); );
} }
public function dataTrueFalse() { public static function dataTrueFalse(): array {
return [ return [
[true], [true],
[false], [false],
@ -198,7 +198,7 @@ class DecryptAllTest extends TestCase {
$this->view $this->view
] ]
) )
->setMethods(['decryptUsersFiles']) ->onlyMethods(['decryptUsersFiles'])
->getMock(); ->getMock();
$this->invokePrivate($instance, 'input', [$this->inputInterface]); $this->invokePrivate($instance, 'input', [$this->inputInterface]);
@ -211,12 +211,16 @@ class DecryptAllTest extends TestCase {
$this->userInterface->expects($this->any()) $this->userInterface->expects($this->any())
->method('getUsers') ->method('getUsers')
->willReturn(['user1', 'user2']); ->willReturn(['user1', 'user2']);
$calls = [
'user1',
'user2',
];
$instance->expects($this->exactly(2)) $instance->expects($this->exactly(2))
->method('decryptUsersFiles') ->method('decryptUsersFiles')
->withConsecutive( ->willReturnCallback(function ($user) use (&$calls) {
['user1'], $expected = array_shift($calls);
['user2'], $this->assertEquals($expected, $user);
); });
} else { } else {
$instance->expects($this->once()) $instance->expects($this->once())
->method('decryptUsersFiles') ->method('decryptUsersFiles')
@ -226,7 +230,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'decryptAllUsersFiles', [$user]); $this->invokePrivate($instance, 'decryptAllUsersFiles', [$user]);
} }
public function dataTestDecryptAllUsersFiles() { public static function dataTestDecryptAllUsersFiles(): array {
return [ return [
['user1'], ['user1'],
[''] ['']
@ -243,7 +247,7 @@ class DecryptAllTest extends TestCase {
$this->view $this->view
] ]
) )
->setMethods(['decryptFile']) ->onlyMethods(['decryptFile'])
->getMock(); ->getMock();
$storage = $this->getMockBuilder(IStorage::class) $storage = $this->getMockBuilder(IStorage::class)
@ -253,25 +257,29 @@ class DecryptAllTest extends TestCase {
$sharedStorage = $this->getMockBuilder(IStorage::class) $sharedStorage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$sharedStorage->expects($this->once())->method('instanceOfStorage') $sharedStorage->expects($this->once())
->with('OCA\Files_Sharing\SharedStorage')->willReturn(true); ->method('instanceOfStorage')
->with('OCA\Files_Sharing\SharedStorage')
->willReturn(true);
$this->view->expects($this->exactly(2)) $this->view->expects($this->exactly(2))
->method('getDirectoryContent') ->method('getDirectoryContent')
->withConsecutive( ->willReturnMap([
['/user1/files'],
['/user1/files/foo']
)
->willReturnOnConsecutiveCalls(
[ [
new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null), '/user1/files', '', 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' => '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') $this->view->expects($this->any())->method('is_dir')
->willReturnCallback( ->willReturnCallback(
@ -283,12 +291,16 @@ class DecryptAllTest extends TestCase {
} }
); );
$calls = [
'/user1/files/bar',
'/user1/files/foo/subfile',
];
$instance->expects($this->exactly(2)) $instance->expects($this->exactly(2))
->method('decryptFile') ->method('decryptFile')
->withConsecutive( ->willReturnCallback(function ($path) use (&$calls) {
['/user1/files/bar'], $expected = array_shift($calls);
['/user1/files/foo/subfile'], $this->assertEquals($expected, $path);
); });
/* We need format method to return a string */ /* We need format method to return a string */
@ -320,7 +332,7 @@ class DecryptAllTest extends TestCase {
$this->view $this->view
] ]
) )
->setMethods(['getTimestamp']) ->onlyMethods(['getTimestamp'])
->getMock(); ->getMock();
$fileInfo = $this->createMock(FileInfo::class); $fileInfo = $this->createMock(FileInfo::class);
@ -360,7 +372,7 @@ class DecryptAllTest extends TestCase {
$this->view $this->view
] ]
) )
->setMethods(['getTimestamp']) ->onlyMethods(['getTimestamp'])
->getMock(); ->getMock();

@ -9,6 +9,7 @@
namespace Test\Encryption\Keys; namespace Test\Encryption\Keys;
use OC\Encryption\Keys\Storage; use OC\Encryption\Keys\Storage;
use OC\Encryption\Util;
use OC\Files\View; use OC\Files\View;
use OCP\IConfig; use OCP\IConfig;
use OCP\Security\ICrypto; use OCP\Security\ICrypto;
@ -36,9 +37,9 @@ class StorageTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->util = $this->getMockBuilder('OC\Encryption\Util') $this->util = $this->getMockBuilder(Util::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethodsExcept(['getFileKeyDir']) ->onlyMethods(array_diff(get_class_methods(Util::class), ['getFileKeyDir']))
->getMock(); ->getMock();
$this->view = $this->getMockBuilder(View::class) $this->view = $this->getMockBuilder(View::class)
@ -114,7 +115,7 @@ class StorageTest extends TestCase {
); );
} }
public function dataTestGetFileKey() { public static function dataTestGetFileKey() {
return [ return [
['/files/foo.txt', '/files/foo.txt', true, 'key'], ['/files/foo.txt', '/files/foo.txt', true, 'key'],
['/files/foo.txt.ocTransferId2111130212.part', '/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) { if (!$originalKeyExists) {
$this->view->expects($this->exactly(2)) $this->view->expects($this->exactly(2))
->method('file_exists') ->method('file_exists')
->withConsecutive( ->willReturnMap([
[$this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')], ['/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey', $originalKeyExists],
[$this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')], ['/user1/files_encryption/keys' . $path . '/encModule/fileKey', true],
)->willReturnOnConsecutiveCalls( ]);
$originalKeyExists,
true,
);
$this->view->expects($this->once()) $this->view->expects($this->once())
->method('file_get_contents') ->method('file_get_contents')
@ -481,7 +479,7 @@ class StorageTest extends TestCase {
return [$parts[1], '/' . implode('/', array_slice($parts, 2))]; return [$parts[1], '/' . implode('/', array_slice($parts, 2))];
} }
public function dataProviderCopyRename() { public static function dataProviderCopyRename() {
return [ return [
['/user1/files/source.txt', '/user1/files/target.txt', false, false, ['/user1/files/source.txt', '/user1/files/target.txt', false, false,
'/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'], '/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 [ return [
['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'], ['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'],
['/user1/files/source.txt', true, '', '/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 { public function testBackupUserKeys($createBackupDir): void {
$storage = $this->getMockBuilder('OC\Encryption\Keys\Storage') $storage = $this->getMockBuilder('OC\Encryption\Keys\Storage')
->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config]) ->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config])
->setMethods(['getTimestamp']) ->onlyMethods(['getTimestamp'])
->getMock(); ->getMock();
$storage->expects($this->any())->method('getTimestamp')->willReturn('1234567'); $storage->expects($this->any())->method('getTimestamp')->willReturn('1234567');
@ -586,11 +584,15 @@ class StorageTest extends TestCase {
->with('user1/files_encryption/backup')->willReturn(!$createBackupDir); ->with('user1/files_encryption/backup')->willReturn(!$createBackupDir);
if ($createBackupDir) { if ($createBackupDir) {
$calls = [
'user1/files_encryption/backup',
'user1/files_encryption/backup/test.encryptionModule.1234567',
];
$this->view->expects($this->exactly(2))->method('mkdir') $this->view->expects($this->exactly(2))->method('mkdir')
->withConsecutive( ->willReturnCallback(function ($path) use (&$calls) {
['user1/files_encryption/backup'], $expected = array_shift($calls);
['user1/files_encryption/backup/test.encryptionModule.1234567'], $this->assertEquals($expected, $path);
); });
} else { } else {
$this->view->expects($this->once())->method('mkdir') $this->view->expects($this->once())->method('mkdir')
->with('user1/files_encryption/backup/test.encryptionModule.1234567'); ->with('user1/files_encryption/backup/test.encryptionModule.1234567');
@ -605,7 +607,7 @@ class StorageTest extends TestCase {
$this->assertTrue($storage->backupUserKeys('encryptionModule', 'test', 'user1')); $this->assertTrue($storage->backupUserKeys('encryptionModule', 'test', 'user1'));
} }
public function dataTestBackupUserKeys() { public static function dataTestBackupUserKeys() {
return [ return [
[true], [false] [true], [false]
]; ];

@ -205,16 +205,12 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
public function testMultiBucketConfigFirstFallBackSingle(): void { public function testMultiBucketConfigFirstFallBackSingle(): void {
$this->config->expects($this->exactly(2)) $this->config->expects($this->exactly(2))
->method('getSystemValue') ->method('getSystemValue')->willReturnMap([
->withConsecutive( ['objectstore_multibucket', '', ''],
[$this->equalTo('objectstore_multibucket')], ['objectstore', '', [
[$this->equalTo('objectstore')],
)->willReturnOnConsecutiveCalls(
'',
[
'class' => 'Test\Files\Mount\FakeObjectStore', 'class' => 'Test\Files\Mount\FakeObjectStore',
], ]],
); ]);
$this->user->method('getUID') $this->user->method('getUID')
->willReturn('uid'); ->willReturn('uid');

@ -76,12 +76,16 @@ class AvailabilityTest extends \Test\TestCase {
$this->storage->expects($this->once()) $this->storage->expects($this->once())
->method('test') ->method('test')
->willReturn(true); ->willReturn(true);
$calls = [
false, // prevents concurrent rechecks
true, // sets correct availability
];
$this->storage->expects($this->exactly(2)) $this->storage->expects($this->exactly(2))
->method('setAvailability') ->method('setAvailability')
->withConsecutive( ->willReturnCallback(function ($value) use (&$calls) {
[$this->equalTo(false)], // prevents concurrent rechecks $expected = array_shift($calls);
[$this->equalTo(true)] // sets correct availability $this->assertEquals($expected, $value);
); });
$this->storage->expects($this->once()) $this->storage->expects($this->once())
->method('mkdir'); ->method('mkdir');

@ -25,7 +25,7 @@ class DetectionTest extends \Test\TestCase {
); );
} }
public function dataDetectPath(): array { public static function dataDetectPath(): array {
return [ return [
['foo.txt', 'text/plain'], ['foo.txt', 'text/plain'],
['foo.png', 'image/png'], ['foo.png', 'image/png'],
@ -54,7 +54,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $this->detection->detectPath($path)); $this->assertEquals($expected, $this->detection->detectPath($path));
} }
public function dataDetectContent(): array { public static function dataDetectContent(): array {
return [ return [
['/', 'httpd/unix-directory'], ['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'], ['/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)); $this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path));
} }
public function dataDetect(): array { public static function dataDetect(): array {
return [ return [
['/', 'httpd/unix-directory'], ['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'], ['/data.tar.gz', 'application/gzip'],
@ -100,7 +100,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
public function dataMimeTypeCustom(): array { public static function dataMimeTypeCustom(): array {
return [ return [
['123', 'foobar/123'], ['123', 'foobar/123'],
['a123', 'foobar/123'], ['a123', 'foobar/123'],
@ -135,7 +135,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($mime, $detection->detectPath('foo.' . $ext)); $this->assertEquals($mime, $detection->detectPath('foo.' . $ext));
} }
public function dataGetSecureMimeType(): array { public static function dataGetSecureMimeType(): array {
return [ return [
['image/svg+xml', 'text/plain'], ['image/svg+xml', 'text/plain'],
['image/png', 'image/png'], ['image/png', 'image/png'],
@ -255,14 +255,16 @@ class DetectionTest extends \Test\TestCase {
->getMock(); ->getMock();
//Only call the url generator once //Only call the url generator once
$calls = [
['core', 'filetypes/my-type.png'],
['core', 'filetypes/my.png'],
];
$urlGenerator->expects($this->exactly(2)) $urlGenerator->expects($this->exactly(2))
->method('imagePath') ->method('imagePath')
->withConsecutive(
[$this->equalTo('core'), $this->equalTo('filetypes/my-type.png')],
[$this->equalTo('core'), $this->equalTo('filetypes/my.png')]
)
->willReturnCallback( ->willReturnCallback(
function ($appName, $file) { function ($appName, $file) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/my.png') { if ($file === 'filetypes/my.png') {
return 'my.svg'; return 'my.svg';
} }
@ -285,15 +287,17 @@ class DetectionTest extends \Test\TestCase {
->getMock(); ->getMock();
//Only call the url generator once //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)) $urlGenerator->expects($this->exactly(3))
->method('imagePath') ->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( ->willReturnCallback(
function ($appName, $file) { function ($appName, $file) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/file.png') { if ($file === 'filetypes/file.png') {
return 'file.svg'; return 'file.svg';
} }

@ -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 * Class ViewTest
* *
@ -291,7 +302,7 @@ class ViewTest extends \Test\TestCase {
$this->assertCount(4, $folderContent); $this->assertCount(4, $folderContent);
} }
public function sharingDisabledPermissionProvider() { public static function sharingDisabledPermissionProvider(): array {
return [ return [
['no', '', true], ['no', '', true],
['yes', 'group1', false], ['yes', 'group1', false],
@ -543,7 +554,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($rootView->file_exists('substorage/bar.txt')); $this->assertFalse($rootView->file_exists('substorage/bar.txt'));
} }
public function rmdirOrUnlinkDataProvider() { public static function rmdirOrUnlinkDataProvider(): array {
return [['rmdir'], ['unlink']]; return [['rmdir'], ['unlink']];
} }
@ -775,7 +786,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($exists); $this->assertTrue($exists);
} }
public function resolvePathTestProvider() { public static function resolvePathTestProvider(): array {
return [ return [
['foo.txt', 'foo.txt'], ['foo.txt', 'foo.txt'],
['foo.txt', '/foo.txt'], ['foo.txt', '/foo.txt'],
@ -940,7 +951,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals(6, $info->getSize()); $this->assertEquals(6, $info->getSize());
} }
public function absolutePathProvider() { public static function absolutePathProvider(): array {
return [ return [
['/files/', ''], ['/files/', ''],
['/files/0', '0'], ['/files/0', '0'],
@ -961,8 +972,8 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath)); $this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
} }
public function chrootRelativePathProvider() { public static function chrootRelativePathProvider(): array {
return $this->relativePathProvider('/'); return self::relativePathProvider('/');
} }
/** /**
@ -973,11 +984,11 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath)); $this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
} }
public function initRelativePathProvider() { public static function initRelativePathProvider(): array {
return $this->relativePathProvider(null); return self::relativePathProvider(null);
} }
public function relativePathProvider($missingRootExpectedPath) { public static function relativePathProvider($missingRootExpectedPath): array {
return [ return [
// No root - returns the path // No root - returns the path
['', '/files', '/files'], ['', '/files', '/files'],
@ -1097,7 +1108,7 @@ class ViewTest extends \Test\TestCase {
call_user_func([$rootView, $operation], $longPath, $param0); call_user_func([$rootView, $operation], $longPath, $param0);
} }
public function tooLongPathDataProvider() { public static function tooLongPathDataProvider(): array {
return [ return [
['getAbsolutePath'], ['getAbsolutePath'],
['getRelativePath'], ['getRelativePath'],
@ -1180,7 +1191,7 @@ class ViewTest extends \Test\TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|Temporary $storage2 */ /** @var \PHPUnit\Framework\MockObject\MockObject|Temporary $storage2 */
$storage2 = $this->getMockBuilder(TemporaryNoCross::class) $storage2 = $this->getMockBuilder(TemporaryNoCross::class)
->setConstructorArgs([[]]) ->setConstructorArgs([[]])
->setMethods(['fopen', 'writeStream']) ->onlyMethods(['fopen', 'writeStream'])
->getMock(); ->getMock();
$storage2->method('writeStream') $storage2->method('writeStream')
@ -1226,7 +1237,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setConstructorArgs([[]]) ->setConstructorArgs([[]])
->setMethods(['unlink']) ->onlyMethods(['unlink'])
->getMock(); ->getMock();
$storage->expects($this->once()) $storage->expects($this->once())
->method('unlink') ->method('unlink')
@ -1243,7 +1254,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($cache->inCache('foo.txt')); $this->assertTrue($cache->inCache('foo.txt'));
} }
public function directoryTraversalProvider() { public static function directoryTraversalProvider(): array {
return [ return [
['../test/'], ['../test/'],
['..\\test\\my/../folder'], ['..\\test\\my/../folder'],
@ -1481,7 +1492,7 @@ class ViewTest extends \Test\TestCase {
$lockingProvider->releaseAll(); $lockingProvider->releaseAll();
} }
public function dataLockPaths() { public static function dataLockPaths(): array {
return [ return [
['/testuser/{folder}', ''], ['/testuser/{folder}', ''],
['/testuser', '/{folder}'], ['/testuser', '/{folder}'],
@ -1489,7 +1500,7 @@ class ViewTest extends \Test\TestCase {
]; ];
} }
public function pathRelativeToFilesProvider() { public static function pathRelativeToFilesProvider(): array {
return [ return [
['admin/files', ''], ['admin/files', ''],
['admin/files/x', 'x'], ['admin/files/x', 'x'],
@ -1509,7 +1520,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path)); $this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path));
} }
public function pathRelativeToFilesProviderExceptionCases() { public static function pathRelativeToFilesProviderExceptionCases(): array {
return [ return [
[''], [''],
['x'], ['x'],
@ -1552,7 +1563,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
} }
public function hookPathProvider() { public static function hookPathProvider(): array {
return [ return [
['/foo/files', '/foo', true], ['/foo/files', '/foo', true],
['/foo/files/bar', '/foo', true], ['/foo/files/bar', '/foo', true],
@ -1593,7 +1604,7 @@ class ViewTest extends \Test\TestCase {
$mounts = []; $mounts = [];
foreach ($mountPoints as $mountPoint) { foreach ($mountPoints as $mountPoint) {
$storage = $this->getMockBuilder(Storage::class) $storage = $this->getMockBuilder(Storage::class)
->setMethods([]) ->onlyMethods([])
->getMock(); ->getMock();
$storage->method('getId')->willReturn('non-null-id'); $storage->method('getId')->willReturn('non-null-id');
$storage->method('getStorageCache')->willReturnCallback(function () use ($storage) { $storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
@ -1601,7 +1612,7 @@ class ViewTest extends \Test\TestCase {
}); });
$mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class) $mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
->setMethods(['moveMount']) ->onlyMethods(['moveMount'])
->setConstructorArgs([$storage, $mountPoint]) ->setConstructorArgs([$storage, $mountPoint])
->getMock(); ->getMock();
} }
@ -1746,7 +1757,7 @@ class ViewTest extends \Test\TestCase {
$userObject->delete(); $userObject->delete();
} }
public function basicOperationProviderForLocks() { public static function basicOperationProviderForLocks(): array {
return [ return [
// --- write hook ---- // --- write hook ----
[ [
@ -1931,7 +1942,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary&MockObject $storage */ /** @var Temporary&MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation]) ->onlyMethods([$operation])
->getMock(); ->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */ /* 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'; $path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods(['fopen']) ->onlyMethods(['fopen'])
->getMock(); ->getMock();
Filesystem::mount($storage, [], $this->user . '/'); Filesystem::mount($storage, [], $this->user . '/');
@ -2026,7 +2037,7 @@ class ViewTest extends \Test\TestCase {
$path = 'test_file_put_contents.txt'; $path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods(['fopen']) ->onlyMethods(['fopen'])
->getMock(); ->getMock();
Filesystem::mount($storage, [], $this->user . '/'); Filesystem::mount($storage, [], $this->user . '/');
@ -2081,7 +2092,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation]) ->onlyMethods([$operation])
->getMock(); ->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */ /* 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 */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation]) ->onlyMethods([$operation])
->getMock(); ->getMock();
Filesystem::mount($storage, [], $this->user . '/'); 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'); $this->assertNull($this->getFileLockType($view, $path), 'File got unlocked after exception');
} }
public function lockFileRenameOrCopyDataProvider() { public static function lockFileRenameOrCopyDataProvider(): array {
return [ return [
['rename', ILockingProvider::LOCK_EXCLUSIVE], ['rename', ILockingProvider::LOCK_EXCLUSIVE],
['copy', ILockingProvider::LOCK_SHARED], ['copy', ILockingProvider::LOCK_SHARED],
@ -2208,7 +2219,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation, 'getMetaData', 'filemtime']) ->onlyMethods([$operation, 'getMetaData', 'filemtime'])
->getMock(); ->getMock();
$storage->expects($this->any()) $storage->expects($this->any())
@ -2274,7 +2285,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods(['copy']) ->onlyMethods(['copy'])
->getMock(); ->getMock();
$sourcePath = 'original.txt'; $sourcePath = 'original.txt';
@ -2371,7 +2382,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('test', $folderInfo[0]->getOwner()->getUID()); $this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
} }
public function lockFileRenameOrCopyCrossStorageDataProvider() { public static function lockFileRenameOrCopyCrossStorageDataProvider(): array {
return [ return [
['rename', 'moveFromStorage', ILockingProvider::LOCK_EXCLUSIVE], ['rename', 'moveFromStorage', ILockingProvider::LOCK_EXCLUSIVE],
['copy', 'copyFromStorage', ILockingProvider::LOCK_SHARED], ['copy', 'copyFromStorage', ILockingProvider::LOCK_SHARED],
@ -2393,11 +2404,11 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class) $storage = $this->getMockBuilder(Temporary::class)
->setMethods([$storageOperation]) ->onlyMethods([$storageOperation])
->getMock(); ->getMock();
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage2 */ /** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage2 */
$storage2 = $this->getMockBuilder(Temporary::class) $storage2 = $this->getMockBuilder(Temporary::class)
->setMethods([$storageOperation, 'getMetaData', 'filemtime']) ->onlyMethods([$storageOperation, 'getMetaData', 'filemtime'])
->getMock(); ->getMock();
$storage2->expects($this->any()) $storage2->expects($this->any())
@ -2532,8 +2543,8 @@ class ViewTest extends \Test\TestCase {
return; return;
} }
$eventHandler = $this->getMockBuilder(\stdclass::class) $eventHandler = $this->getMockBuilder(TestEventHandler::class)
->setMethods(['preCallback', 'postCallback']) ->onlyMethods(['preCallback', 'postCallback'])
->getMock(); ->getMock();
$eventHandler->expects($this->any()) $eventHandler->expects($this->any())
@ -2607,8 +2618,8 @@ class ViewTest extends \Test\TestCase {
Filesystem::getMountManager()->addMount($mount); Filesystem::getMountManager()->addMount($mount);
// Listen for events // Listen for events
$eventHandler = $this->getMockBuilder(\stdclass::class) $eventHandler = $this->getMockBuilder(TestEventHandler::class)
->setMethods(['umount', 'post_umount']) ->onlyMethods(['umount', 'post_umount'])
->getMock(); ->getMock();
$eventHandler->expects($this->once()) $eventHandler->expects($this->once())
->method('umount') ->method('umount')
@ -2634,7 +2645,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('foo', $view->rmdir('mount')); $this->assertEquals('foo', $view->rmdir('mount'));
} }
public function mimeFilterProvider() { public static function mimeFilterProvider(): array {
return [ return [
[null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']], [null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']],
['text/plain', ['test1.txt', 'test2.txt']], ['text/plain', ['test1.txt', 'test2.txt']],
@ -2742,7 +2753,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectories(): void { public function testCreateParentDirectories(): void {
$view = $this->getMockBuilder(View::class) $view = $this->getMockBuilder(View::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods([ ->onlyMethods([
'is_file', 'is_file',
'file_exists', 'file_exists',
'mkdir', 'mkdir',
@ -2751,29 +2762,26 @@ class ViewTest extends \Test\TestCase {
$view->expects($this->exactly(3)) $view->expects($this->exactly(3))
->method('is_file') ->method('is_file')
->withConsecutive( ->willReturnMap([
['/new'], ['/new', false],
['/new/folder'], ['/new/folder', false],
['/new/folder/structure'], ['/new/folder/structure', false],
) ]);
->willReturn(false);
$view->expects($this->exactly(3)) $view->expects($this->exactly(3))
->method('file_exists') ->method('file_exists')
->withConsecutive( ->willReturnMap([
['/new'], ['/new', true],
['/new/folder'], ['/new/folder', false],
['/new/folder/structure'], ['/new/folder/structure', false],
)->willReturnOnConsecutiveCalls( ]);
true,
false, $calls = ['/new/folder', '/new/folder/structure'];
false,
);
$view->expects($this->exactly(2)) $view->expects($this->exactly(2))
->method('mkdir') ->method('mkdir')
->withConsecutive( ->willReturnCallback(function ($dir) use (&$calls) {
['/new/folder'], $expected = array_shift($calls);
['/new/folder/structure'], $this->assertEquals($expected, $dir);
); });
$this->assertTrue(self::invokePrivate($view, 'createParentDirectories', ['/new/folder/structure'])); $this->assertTrue(self::invokePrivate($view, 'createParentDirectories', ['/new/folder/structure']));
} }
@ -2781,7 +2789,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectoriesWithExistingFile(): void { public function testCreateParentDirectoriesWithExistingFile(): void {
$view = $this->getMockBuilder(View::class) $view = $this->getMockBuilder(View::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods([ ->onlyMethods([
'is_file', 'is_file',
'file_exists', 'file_exists',
'mkdir', 'mkdir',

@ -92,14 +92,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueString') ->method('getSystemValueString')
->withConsecutive( ->willReturnMap([
['proxy', ''], ['proxy', '', 'foo'],
['proxyuserpwd', ''], ['proxyuserpwd', '', 'username:password'],
) ]);
->willReturnOnConsecutiveCalls(
'foo',
'username:password',
);
$this->assertEquals([ $this->assertEquals([
'http' => 'username:password@foo', 'http' => 'username:password@foo',
'https' => 'username:password@foo' 'https' => 'username:password@foo'
@ -115,14 +111,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueString') ->method('getSystemValueString')
->withConsecutive( ->willReturnMap([
['proxy', ''], ['proxy', '', 'foo'],
['proxyuserpwd', ''], ['proxyuserpwd', '', 'username:password'],
) ]);
->willReturnOnConsecutiveCalls(
'foo',
'username:password',
);
$this->assertEquals([ $this->assertEquals([
'http' => 'username:password@foo', 'http' => 'username:password@foo',
'https' => 'username:password@foo', 'https' => 'username:password@foo',
@ -137,7 +129,7 @@ class ClientTest extends \Test\TestCase {
self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]); self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]);
} }
public function dataPreventLocalAddress():array { public static function dataPreventLocalAddress(): array {
return [ return [
['https://localhost/foo.bar'], ['https://localhost/foo.bar'],
['https://localHost/foo.bar'], ['https://localHost/foo.bar'],
@ -461,14 +453,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['installed', false], ['installed', false, false],
['allow_local_remote_servers', false], ['allow_local_remote_servers', false, false],
) ]);
->willReturnOnConsecutiveCalls(
false,
false,
);
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
@ -503,14 +491,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['installed', false], ['installed', false, true],
['allow_local_remote_servers', false], ['allow_local_remote_servers', false, false],
) ]);
->willReturnOnConsecutiveCalls(
true,
false,
);
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getSystemValue')
@ -519,14 +503,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueString') ->method('getSystemValueString')
->withConsecutive( ->willReturnMap([
['proxy', ''], ['proxy', '', 'foo'],
['proxyuserpwd', ''], ['proxyuserpwd', '', ''],
) ]);
->willReturnOnConsecutiveCalls(
'foo',
'',
);
$this->certificateManager $this->certificateManager
->expects($this->once()) ->expects($this->once())
->method('getAbsoluteBundlePath') ->method('getAbsoluteBundlePath')
@ -562,14 +542,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueBool') ->method('getSystemValueBool')
->withConsecutive( ->willReturnMap([
['installed', false], ['installed', false, true],
['allow_local_remote_servers', false], ['allow_local_remote_servers', false, false],
) ]);
->willReturnOnConsecutiveCalls(
true,
false,
);
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValue') ->method('getSystemValue')
@ -578,14 +554,10 @@ class ClientTest extends \Test\TestCase {
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getSystemValueString') ->method('getSystemValueString')
->withConsecutive( ->willReturnMap([
['proxy', ''], ['proxy', '', 'foo'],
['proxyuserpwd', ''], ['proxyuserpwd', '', ''],
) ]);
->willReturnOnConsecutiveCalls(
'foo',
'',
);
$this->certificateManager $this->certificateManager
->expects($this->once()) ->expects($this->once())
->method('getAbsoluteBundlePath') ->method('getAbsoluteBundlePath')

@ -200,14 +200,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
) ]);
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp')); $this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
} }
@ -239,14 +235,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
) ]);
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'EXCEPTION' => [ 'EXCEPTION' => [
@ -284,14 +276,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
) ]);
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
@ -344,15 +332,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
) ]);
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'INVALID_HASH' => [ 'INVALID_HASH' => [
@ -405,13 +388,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'EXCEPTION' => [ 'EXCEPTION' => [
@ -449,13 +429,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt'], ['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp')); $this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
} }
@ -689,13 +666,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$this->assertSame([], $this->checker->verifyCoreSignature()); $this->assertSame([], $this->checker->verifyCoreSignature());
} }
@ -726,14 +700,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
) ]);
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$this->assertSame([], $this->checker->verifyCoreSignature()); $this->assertSame([], $this->checker->verifyCoreSignature());
} }
@ -816,13 +786,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$this->assertSame([], $this->checker->verifyCoreSignature()); $this->assertSame([], $this->checker->verifyCoreSignature());
} }
@ -853,13 +820,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'EXCEPTION' => [ 'EXCEPTION' => [
@ -896,13 +860,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'INVALID_HASH' => [ 'INVALID_HASH' => [
@ -954,13 +915,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'EXCEPTION' => [ 'EXCEPTION' => [
@ -997,13 +955,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_get_contents') ->method('file_get_contents')
->withConsecutive( ->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
)->willReturnOnConsecutiveCalls( ]);
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
$expected = [ $expected = [
'EXCEPTION' => [ 'EXCEPTION' => [
@ -1027,7 +982,7 @@ class CheckerTest extends TestCase {
$this->appManager, $this->appManager,
$this->mimeTypeDetector, $this->mimeTypeDetector,
]) ])
->setMethods([ ->onlyMethods([
'verifyCoreSignature', 'verifyCoreSignature',
'verifyAppSignature', 'verifyAppSignature',
]) ])
@ -1048,45 +1003,40 @@ class CheckerTest extends TestCase {
$this->appManager $this->appManager
->expects($this->exactly(4)) ->expects($this->exactly(4))
->method('isShipped') ->method('isShipped')
->withConsecutive( ->willReturnMap([
['files'], ['files', true],
['calendar'], ['calendar', false],
['contacts'], ['contacts', false],
['dav'], ['dav', true],
)->willReturnOnConsecutiveCalls( ]);
true,
false, $calls = [
false, 'files',
true, 'calendar',
); 'dav',
];
$this->checker $this->checker
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('verifyAppSignature') ->method('verifyAppSignature')
->withConsecutive( ->willReturnCallback(function ($app) use (&$calls) {
['files'], $expected = array_shift($calls);
['calendar'], $this->assertSame($expected, $app);
['dav'], return [];
); });
$this->appLocator $this->appLocator
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getAppPath') ->method('getAppPath')
->withConsecutive( ->willReturnMap([
['calendar'], ['calendar', '/apps/calendar'],
['contacts'], ['contacts', '/apps/contacts'],
)->willReturnOnConsecutiveCalls( ]);
'/apps/calendar',
'/apps/contacts',
);
$this->fileAccessHelper $this->fileAccessHelper
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('file_exists') ->method('file_exists')
->withConsecutive( ->willReturnMap([
['/apps/calendar/appinfo/signature.json'], ['/apps/calendar/appinfo/signature.json', true],
['/apps/contacts/appinfo/signature.json'], ['/apps/contacts/appinfo/signature.json', false],
)->willReturnOnConsecutiveCalls( ]);
true,
false,
);
$this->appConfig $this->appConfig
->expects($this->once()) ->expects($this->once())
->method('deleteKey') ->method('deleteKey')
@ -1110,10 +1060,7 @@ class CheckerTest extends TestCase {
$this->assertSame($expected, $this->checker->verifyAppSignature('SomeApp')); $this->assertSame($expected, $this->checker->verifyAppSignature('SomeApp'));
} }
/** public static function channelDataProvider(): array {
* @return array
*/
public function channelDataProvider() {
return [ return [
['stable', true], ['stable', true],
['git', false], ['git', false],

File diff suppressed because it is too large Load Diff