Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\ValueObject\Application\File;

Expand Down Expand Up @@ -64,9 +65,9 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
$nextcloudDir . '/status.php',
$nextcloudDir . '/version.php',
$nextcloudDir . '/lib/private/Share20/ProviderFactory.php',
$nextcloudDir . '/tests',
// $nextcloudDir . '/config',
// $nextcloudDir . '/lib',
// $nextcloudDir . '/tests',
// $nextcloudDir . '/themes',
])
->withSkip([
Expand All @@ -79,6 +80,9 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
// ->withPhpSets()
->withImportNames(importShortClasses:false)
->withTypeCoverageLevel(0)
->withRules([
UseSpecificWillMethodRector::class
])
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
'inline_public' => true,
'rename_property' => true,
Expand Down
8 changes: 5 additions & 3 deletions tests/Core/Command/Apps/AppsDisableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace Tests\Core\Command\Config;

use OC\Core\Command\App\Disable;
use OCP\App\IAppManager;
use OCP\Server;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

Expand All @@ -25,13 +27,13 @@ protected function setUp(): void {
parent::setUp();

$command = new Disable(
\OC::$server->getAppManager()
Server::get(IAppManager::class)
);

$this->commandTester = new CommandTester($command);

\OC::$server->getAppManager()->enableApp('admin_audit');
\OC::$server->getAppManager()->enableApp('comments');
Server::get(IAppManager::class)->enableApp('admin_audit');
Server::get(IAppManager::class)->enableApp('comments');
}

/**
Expand Down
13 changes: 8 additions & 5 deletions tests/Core/Command/Apps/AppsEnableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

use OC\Core\Command\App\Enable;
use OC\Installer;
use OCP\App\IAppManager;
use OCP\IGroupManager;
use OCP\Server;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

Expand All @@ -26,15 +29,15 @@ protected function setUp(): void {
parent::setUp();

$command = new Enable(
\OC::$server->getAppManager(),
\OC::$server->getGroupManager(),
\OC::$server->get(Installer::class),
Server::get(IAppManager::class),
Server::get(IGroupManager::class),
Server::get(Installer::class),
);

$this->commandTester = new CommandTester($command);

\OC::$server->getAppManager()->disableApp('admin_audit');
\OC::$server->getAppManager()->disableApp('comments');
Server::get(IAppManager::class)->disableApp('admin_audit');
Server::get(IAppManager::class)->disableApp('comments');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Tests\Core\Command\Encryption;

use OC\Core\Command\Encryption\ChangeKeyStorageRoot;
use OC\Encryption\Keys\Storage;
use OC\Encryption\Util;
use OC\Files\View;
use OCP\IConfig;
Expand Down Expand Up @@ -157,7 +158,7 @@ public function testPrepareNewRoot(): void {
->willReturn(true);

$this->view->expects($this->once())->method('file_put_contents')
->with('newRoot/' . \OC\Encryption\Keys\Storage::KEY_STORAGE_MARKER,
->with('newRoot/' . Storage::KEY_STORAGE_MARKER,
'Nextcloud will detect this folder as key storage root only if this file exists')->willReturn(true);

$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
Expand Down
8 changes: 4 additions & 4 deletions tests/Core/Command/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testMaintenanceAndTrashbin(): void {
];
$this->config->expects($this->exactly(2))
->method('setSystemValue')
->willReturnCallback(function () use (&$calls) {
->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testExecute($encryptionEnabled, $continue): void {
];
$this->config->expects($this->exactly(2))
->method('setAppValue')
->willReturnCallback(function () use (&$calls) {
->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testExecuteFailure(): void {
];
$this->config->expects($this->exactly(2))
->method('setAppValue')
->willReturnCallback(function () use (&$calls) {
->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
Expand All @@ -208,7 +208,7 @@ public function testExecuteFailure(): void {
$this->decryptAll->expects($this->once())
->method('decryptAll')
->with($this->consoleInput, $this->consoleOutput, 'user1')
->willReturnCallback(function () {
->willReturnCallback(function (): void {
throw new \Exception();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/Encryption/SetDefaultModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testMaintenanceMode($oldModule, $newModule, $updateModule, $upda
];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
->willReturnCallback(function ($message) use (&$calls) {
->willReturnCallback(function ($message) use (&$calls): void {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/Log/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testGetConfiguration(): void {
];
$this->consoleOutput->expects($this->exactly(3))
->method('writeln')
->willReturnCallback(function (string $message) use (&$calls) {
->willReturnCallback(function (string $message) use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected[0], $message);
});
Expand Down
6 changes: 3 additions & 3 deletions tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testNoop(): void {
];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
->willReturnCallback(function ($message) use (&$calls) {
->willReturnCallback(function ($message) use (&$calls): void {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAddMimetype(): void {
];
$this->consoleOutput->expects($this->exactly(4))
->method('writeln')
->willReturnCallback(function ($message) use (&$calls) {
->willReturnCallback(function ($message) use (&$calls): void {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
Expand Down Expand Up @@ -163,7 +163,7 @@ public function testRepairFilecache(): void {
];
$this->consoleOutput->expects($this->exactly(3))
->method('writeln')
->willReturnCallback(function ($message) use (&$calls) {
->willReturnCallback(function ($message) use (&$calls): void {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/Preview/RepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function setUp(): void {
->willReturn($outputFormatter);
$this->output->expects($this->any())
->method('writeln')
->willReturnCallback(function ($line) use ($self) {
->willReturnCallback(function ($line) use ($self): void {
$self->outputLines .= $line . "\n";
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/SystemTag/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testAlreadyExists(): void {
$tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC);

$this->systemTagManager->method('createTag')
->willReturnCallback(function ($tagName, $userVisible, $userAssignable) {
->willReturnCallback(function ($tagName, $userVisible, $userAssignable): void {
throw new TagAlreadyExistsException(
'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists'
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/SystemTag/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testNotFound(): void {
});

$this->systemTagManager->method('deleteTags')
->willReturnCallback(function ($tagId) {
->willReturnCallback(function ($tagId): void {
throw new TagNotFoundException();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/SystemTag/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testAlreadyExists(): void {
});

$this->systemTagManager->method('updateTag')
->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable) {
->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable): void {
throw new TagAlreadyExistsException(
'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists'
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Command/User/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public function testAddEmail(
->method('sendMail');

$this->consoleInput->method('getOption')
->will(static::returnValueMap([
->willReturnMap([
['generate-password', 'true'],
['email', $email],
['group', []],
]));
]);

$this->invokePrivate($this->addCommand, 'execute', [
$this->consoleInput,
Expand Down
12 changes: 6 additions & 6 deletions tests/Core/Controller/AvatarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function tearDown(): void {
*/
public function testGetAvatarNoAvatar(): void {
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$this->avatarMock->method('getFile')->will($this->throwException(new NotFoundException()));
$this->avatarMock->method('getFile')->willThrowException(new NotFoundException());
$response = $this->avatarController->getAvatar('userId', 32);

//Comment out until JS is fixed
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testGetAvatarNoUser(): void {
$this->avatarManager
->method('getAvatar')
->with('userDoesNotExist')
->will($this->throwException(new \Exception('user does not exist')));
->willThrowException(new \Exception('user does not exist'));

$response = $this->avatarController->getAvatar('userDoesNotExist', 32);

Expand Down Expand Up @@ -287,7 +287,7 @@ public function testDeleteAvatar(): void {
* Test what happens if the removing of the avatar fails
*/
public function testDeleteAvatarException(): void {
$this->avatarMock->method('remove')->will($this->throwException(new \Exception('foo')));
$this->avatarMock->method('remove')->willThrowException(new \Exception('foo'));
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);

$this->logger->expects($this->once())
Expand Down Expand Up @@ -469,7 +469,7 @@ public function testPostAvatarNotPermittedException(): void {
public function testPostAvatarException(): void {
$this->cache->expects($this->once())
->method('set')
->will($this->throwException(new \Exception('foo')));
->willThrowException(new \Exception('foo'));
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()->getMock();
$file->expects($this->once())
Expand Down Expand Up @@ -514,7 +514,7 @@ public function testPostCroppedAvatarNoTmpAvatar(): void {
public function testPostCroppedAvatarNoSquareCrop(): void {
$this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));

$this->avatarMock->method('set')->will($this->throwException(new \OC\NotSquareException));
$this->avatarMock->method('set')->willThrowException(new \OC\NotSquareException);
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]);

Expand All @@ -539,7 +539,7 @@ public function testPostCroppedAvatarValidCrop(): void {
public function testPostCroppedAvatarException(): void {
$this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));

$this->avatarMock->method('set')->will($this->throwException(new \Exception('foo')));
$this->avatarMock->method('set')->willThrowException(new \Exception('foo'));
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);

$this->logger->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Controller/ChangePasswordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testChangePersonalPasswordCommonPassword(): void {
$user->expects($this->once())
->method('setPassword')
->with('new')
->will($this->throwException(new HintException('Common password')));
->willThrowException(new HintException('Common password'));

$expects = new JSONResponse([
'status' => 'error',
Expand Down
21 changes: 12 additions & 9 deletions tests/Core/Controller/ClientFlowLoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
Expand Down Expand Up @@ -168,7 +171,7 @@ public function testShowAuthPickerPageWithOcsHeader(): void {
],
'guest'
);
$csp = new Http\ContentSecurityPolicy();
$csp = new ContentSecurityPolicy();
$csp->addAllowedFormActionDomain('nc://*');
$expected->setContentSecurityPolicy($csp);
$this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage());
Expand Down Expand Up @@ -235,7 +238,7 @@ public function testShowAuthPickerPageWithOauth(): void {
],
'guest'
);
$csp = new Http\ContentSecurityPolicy();
$csp = new ContentSecurityPolicy();
$csp->addAllowedFormActionDomain('https://example.com/redirect.php');
$expected->setContentSecurityPolicy($csp);
$this->assertEquals($expected, $this->clientFlowLoginController->showAuthPickerPage('MyClientIdentifier'));
Expand Down Expand Up @@ -279,7 +282,7 @@ public function testGenerateAppPasswordWithSessionNotAvailableException(): void
->method('getId')
->willThrowException(new SessionNotAvailableException());

$expected = new Http\Response();
$expected = new Response();
$expected->setStatus(Http::STATUS_FORBIDDEN);
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
Expand All @@ -304,7 +307,7 @@ public function testGenerateAppPasswordWithInvalidTokenException(): void {
->with('SessionId')
->willThrowException(new InvalidTokenException());

$expected = new Http\Response();
$expected = new Response();
$expected->setStatus(Http::STATUS_FORBIDDEN);
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
Expand Down Expand Up @@ -380,7 +383,7 @@ public function testGeneratePasswordWithPassword(): void {
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped');

$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$expected = new RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}

Expand All @@ -406,7 +409,7 @@ public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $re
];
$this->session
->method('remove')
->willReturnCallback(function ($key) use (&$calls) {
->willReturnCallback(function ($key) use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, $key);
});
Expand Down Expand Up @@ -470,7 +473,7 @@ public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $re
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped');

$expected = new Http\RedirectResponse($redirectUrl);
$expected = new RedirectResponse($redirectUrl);
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken', 'MyClientIdentifier'));
}

Expand Down Expand Up @@ -545,7 +548,7 @@ public function testGeneratePasswordWithoutPassword(): void {
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped');

$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$expected = new RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}

Expand Down Expand Up @@ -676,7 +679,7 @@ public function testGeneratePasswordWithHttpsProxy(array $headers, $protocol, $e
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped');

$expected = new Http\RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken');
$expected = new RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
}
Loading
Loading