|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | /** |
4 | 6 | * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors |
5 | 7 | * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
|
21 | 23 | use OCP\IUser; |
22 | 24 | use OCP\IUserManager; |
23 | 25 | use OCP\Server; |
| 26 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 27 | +use PHPUnit\Framework\Attributes\Group; |
24 | 28 | use Psr\Log\LoggerInterface; |
| 29 | +use Test\TestCase; |
| 30 | +use Test\Util\User\Dummy; |
25 | 31 |
|
26 | 32 | class TestScanner extends Scanner { |
27 | | - /** |
28 | | - * @var MountPoint[] $mounts |
29 | | - */ |
30 | | - private $mounts = []; |
31 | | - |
32 | | - /** |
33 | | - * @param MountPoint $mount |
34 | | - */ |
35 | | - public function addMount($mount) { |
36 | | - $this->mounts[] = $mount; |
| 33 | + /** @var array<string, MountPoint> $mounts */ |
| 34 | + private array $mounts = []; |
| 35 | + |
| 36 | + public function addMount(MountPoint $mount): void { |
| 37 | + $this->mounts[$mount->getMountPoint()] = $mount; |
37 | 38 | } |
38 | 39 |
|
39 | 40 | #[\Override] |
40 | | - protected function getMounts($dir) { |
| 41 | + protected function getMounts(string $dir): array { |
41 | 42 | return $this->mounts; |
42 | 43 | } |
43 | 44 | } |
44 | 45 |
|
45 | | -/** |
46 | | - * Class ScannerTest |
47 | | - * |
48 | | - * |
49 | | - * @package Test\Files\Utils |
50 | | - */ |
51 | | -#[\PHPUnit\Framework\Attributes\Group('DB')] |
52 | | -class ScannerTest extends \Test\TestCase { |
53 | | - /** |
54 | | - * @var \Test\Util\User\Dummy |
55 | | - */ |
56 | | - private $userBackend; |
| 46 | +#[Group('DB')] |
| 47 | +class ScannerTest extends TestCase { |
| 48 | + private Dummy $userBackend; |
57 | 49 |
|
58 | 50 | #[\Override] |
59 | 51 | protected function setUp(): void { |
60 | 52 | parent::setUp(); |
61 | 53 |
|
62 | | - $this->userBackend = new \Test\Util\User\Dummy(); |
| 54 | + $this->userBackend = new Dummy(); |
63 | 55 | Server::get(IUserManager::class)->registerBackend($this->userBackend); |
64 | 56 | $this->loginAsUser(); |
65 | 57 | } |
@@ -166,25 +158,14 @@ public function testScanSubMount(): void { |
166 | 158 | $this->assertTrue($cache->inCache('folder/bar.txt')); |
167 | 159 | } |
168 | 160 |
|
169 | | - public static function invalidPathProvider(): array { |
170 | | - return [ |
171 | | - [ |
172 | | - '../', |
173 | | - ], |
174 | | - [ |
175 | | - '..\\', |
176 | | - ], |
177 | | - [ |
178 | | - '../..\\../', |
179 | | - ], |
180 | | - ]; |
| 161 | + public static function invalidPathProvider(): \Generator { |
| 162 | + yield [ '../' ]; |
| 163 | + yield [ '..\\' ]; |
| 164 | + yield [ '../..\\../' ]; |
181 | 165 | } |
182 | 166 |
|
183 | | - /** |
184 | | - * @param string $invalidPath |
185 | | - */ |
186 | | - #[\PHPUnit\Framework\Attributes\DataProvider('invalidPathProvider')] |
187 | | - public function testInvalidPathScanning($invalidPath): void { |
| 167 | + #[DataProvider(methodName: 'invalidPathProvider')] |
| 168 | + public function testInvalidPathScanning(string $invalidPath): void { |
188 | 169 | $this->expectException(\InvalidArgumentException::class); |
189 | 170 | $this->expectExceptionMessage('Invalid path to scan'); |
190 | 171 |
|
@@ -249,14 +230,14 @@ public function testShallow(): void { |
249 | 230 | ); |
250 | 231 | $scanner->addMount($mount); |
251 | 232 |
|
252 | | - $scanner->scan('', $recusive = false); |
| 233 | + $scanner->scan('', false); |
253 | 234 | $this->assertTrue($cache->inCache('folder')); |
254 | 235 | $this->assertFalse($cache->inCache('folder/subfolder')); |
255 | 236 | $this->assertTrue($cache->inCache('foo.txt')); |
256 | 237 | $this->assertFalse($cache->inCache('folder/bar.txt')); |
257 | 238 | $this->assertFalse($cache->inCache('folder/subfolder/foobar.txt')); |
258 | 239 |
|
259 | | - $scanner->scan('folder', $recusive = false); |
| 240 | + $scanner->scan('folder', false); |
260 | 241 | $this->assertTrue($cache->inCache('folder')); |
261 | 242 | $this->assertTrue($cache->inCache('folder/subfolder')); |
262 | 243 | $this->assertTrue($cache->inCache('foo.txt')); |
|
0 commit comments