Skip to content

Commit 7be047a

Browse files
Merge pull request #53459 from nextcloud/rector-tests
2 parents 1f0086f + 3561937 commit 7be047a

File tree

259 files changed

+1953
-1595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+1953
-1595
lines changed

build/rector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
1313
use Rector\Config\RectorConfig;
1414
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
15+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector;
1516
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
1617
use Rector\ValueObject\Application\File;
1718

@@ -64,9 +65,9 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
6465
$nextcloudDir . '/status.php',
6566
$nextcloudDir . '/version.php',
6667
$nextcloudDir . '/lib/private/Share20/ProviderFactory.php',
68+
$nextcloudDir . '/tests',
6769
// $nextcloudDir . '/config',
6870
// $nextcloudDir . '/lib',
69-
// $nextcloudDir . '/tests',
7071
// $nextcloudDir . '/themes',
7172
])
7273
->withSkip([
@@ -79,6 +80,9 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
7980
// ->withPhpSets()
8081
->withImportNames(importShortClasses:false)
8182
->withTypeCoverageLevel(0)
83+
->withRules([
84+
UseSpecificWillMethodRector::class
85+
])
8286
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
8387
'inline_public' => true,
8488
'rename_property' => true,

tests/Core/Command/Apps/AppsDisableTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace Tests\Core\Command\Config;
1010

1111
use OC\Core\Command\App\Disable;
12+
use OCP\App\IAppManager;
13+
use OCP\Server;
1214
use Symfony\Component\Console\Tester\CommandTester;
1315
use Test\TestCase;
1416

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

2729
$command = new Disable(
28-
\OC::$server->getAppManager()
30+
Server::get(IAppManager::class)
2931
);
3032

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

33-
\OC::$server->getAppManager()->enableApp('admin_audit');
34-
\OC::$server->getAppManager()->enableApp('comments');
35+
Server::get(IAppManager::class)->enableApp('admin_audit');
36+
Server::get(IAppManager::class)->enableApp('comments');
3537
}
3638

3739
/**

tests/Core/Command/Apps/AppsEnableTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
use OC\Core\Command\App\Enable;
1212
use OC\Installer;
13+
use OCP\App\IAppManager;
14+
use OCP\IGroupManager;
15+
use OCP\Server;
1316
use Symfony\Component\Console\Tester\CommandTester;
1417
use Test\TestCase;
1518

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

2831
$command = new Enable(
29-
\OC::$server->getAppManager(),
30-
\OC::$server->getGroupManager(),
31-
\OC::$server->get(Installer::class),
32+
Server::get(IAppManager::class),
33+
Server::get(IGroupManager::class),
34+
Server::get(Installer::class),
3235
);
3336

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

36-
\OC::$server->getAppManager()->disableApp('admin_audit');
37-
\OC::$server->getAppManager()->disableApp('comments');
39+
Server::get(IAppManager::class)->disableApp('admin_audit');
40+
Server::get(IAppManager::class)->disableApp('comments');
3841
}
3942

4043
/**

tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Tests\Core\Command\Encryption;
99

1010
use OC\Core\Command\Encryption\ChangeKeyStorageRoot;
11+
use OC\Encryption\Keys\Storage;
1112
use OC\Encryption\Util;
1213
use OC\Files\View;
1314
use OCP\IConfig;
@@ -157,7 +158,7 @@ public function testPrepareNewRoot(): void {
157158
->willReturn(true);
158159

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

163164
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);

tests/Core/Command/Encryption/DecryptAllTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testMaintenanceAndTrashbin(): void {
7979
];
8080
$this->config->expects($this->exactly(2))
8181
->method('setSystemValue')
82-
->willReturnCallback(function () use (&$calls) {
82+
->willReturnCallback(function () use (&$calls): void {
8383
$expected = array_shift($calls);
8484
$this->assertEquals($expected, func_get_args());
8585
});
@@ -137,7 +137,7 @@ public function testExecute($encryptionEnabled, $continue): void {
137137
];
138138
$this->config->expects($this->exactly(2))
139139
->method('setAppValue')
140-
->willReturnCallback(function () use (&$calls) {
140+
->willReturnCallback(function () use (&$calls): void {
141141
$expected = array_shift($calls);
142142
$this->assertEquals($expected, func_get_args());
143143
});
@@ -188,7 +188,7 @@ public function testExecuteFailure(): void {
188188
];
189189
$this->config->expects($this->exactly(2))
190190
->method('setAppValue')
191-
->willReturnCallback(function () use (&$calls) {
191+
->willReturnCallback(function () use (&$calls): void {
192192
$expected = array_shift($calls);
193193
$this->assertEquals($expected, func_get_args());
194194
});
@@ -208,7 +208,7 @@ public function testExecuteFailure(): void {
208208
$this->decryptAll->expects($this->once())
209209
->method('decryptAll')
210210
->with($this->consoleInput, $this->consoleOutput, 'user1')
211-
->willReturnCallback(function () {
211+
->willReturnCallback(function (): void {
212212
throw new \Exception();
213213
});
214214

tests/Core/Command/Encryption/SetDefaultModuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testMaintenanceMode($oldModule, $newModule, $updateModule, $upda
119119
];
120120
$this->consoleOutput->expects($this->exactly(2))
121121
->method('writeln')
122-
->willReturnCallback(function ($message) use (&$calls) {
122+
->willReturnCallback(function ($message) use (&$calls): void {
123123
$expected = array_shift($calls);
124124
$this->assertStringContainsString($expected, $message);
125125
});

tests/Core/Command/Log/FileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testGetConfiguration(): void {
103103
];
104104
$this->consoleOutput->expects($this->exactly(3))
105105
->method('writeln')
106-
->willReturnCallback(function (string $message) use (&$calls) {
106+
->willReturnCallback(function (string $message) use (&$calls): void {
107107
$expected = array_shift($calls);
108108
$this->assertEquals($expected[0], $message);
109109
});

tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testNoop(): void {
6565
];
6666
$this->consoleOutput->expects($this->exactly(2))
6767
->method('writeln')
68-
->willReturnCallback(function ($message) use (&$calls) {
68+
->willReturnCallback(function ($message) use (&$calls): void {
6969
$expected = array_shift($calls);
7070
$this->assertStringContainsString($expected, $message);
7171
});
@@ -110,7 +110,7 @@ public function testAddMimetype(): void {
110110
];
111111
$this->consoleOutput->expects($this->exactly(4))
112112
->method('writeln')
113-
->willReturnCallback(function ($message) use (&$calls) {
113+
->willReturnCallback(function ($message) use (&$calls): void {
114114
$expected = array_shift($calls);
115115
$this->assertStringContainsString($expected, $message);
116116
});
@@ -163,7 +163,7 @@ public function testRepairFilecache(): void {
163163
];
164164
$this->consoleOutput->expects($this->exactly(3))
165165
->method('writeln')
166-
->willReturnCallback(function ($message) use (&$calls) {
166+
->willReturnCallback(function ($message) use (&$calls): void {
167167
$expected = array_shift($calls);
168168
$this->assertStringContainsString($expected, $message);
169169
});

tests/Core/Command/Preview/RepairTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function setUp(): void {
7979
->willReturn($outputFormatter);
8080
$this->output->expects($this->any())
8181
->method('writeln')
82-
->willReturnCallback(function ($line) use ($self) {
82+
->willReturnCallback(function ($line) use ($self): void {
8383
$self->outputLines .= $line . "\n";
8484
});
8585
}

tests/Core/Command/SystemTag/AddTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testAlreadyExists(): void {
9393
$tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC);
9494

9595
$this->systemTagManager->method('createTag')
96-
->willReturnCallback(function ($tagName, $userVisible, $userAssignable) {
96+
->willReturnCallback(function ($tagName, $userVisible, $userAssignable): void {
9797
throw new TagAlreadyExistsException(
9898
'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists'
9999
);

0 commit comments

Comments
 (0)