|
9 | 9 |
|
10 | 10 | use OC\Files\View; |
11 | 11 | use OCA\Files\Command\DeleteOrphanedFiles; |
| 12 | +use OCP\Files\IRootFolder; |
12 | 13 | use OCP\Files\StorageNotAvailableException; |
| 14 | +use OCP\IDBConnection; |
13 | 15 | use Symfony\Component\Console\Input\InputInterface; |
14 | 16 | use Symfony\Component\Console\Output\OutputInterface; |
15 | 17 | use Test\TestCase; |
|
23 | 25 | */ |
24 | 26 | class DeleteOrphanedFilesTest extends TestCase { |
25 | 27 |
|
26 | | - /** |
27 | | - * @var DeleteOrphanedFiles |
28 | | - */ |
29 | | - private $command; |
30 | | - |
31 | | - /** |
32 | | - * @var \OCP\IDBConnection |
33 | | - */ |
34 | | - private $connection; |
35 | | - |
36 | | - /** |
37 | | - * @var string |
38 | | - */ |
39 | | - private $user1; |
| 28 | + private DeleteOrphanedFiles $command; |
| 29 | + private IDBConnection $connection; |
| 30 | + private string $user1; |
40 | 31 |
|
41 | 32 | protected function setUp(): void { |
42 | 33 | parent::setUp(); |
43 | 34 |
|
44 | | - $this->connection = \OC::$server->getDatabaseConnection(); |
| 35 | + $this->connection = \OCP\Server::get(IDBConnection::class); |
45 | 36 |
|
46 | 37 | $this->user1 = $this->getUniqueID('user1_'); |
47 | 38 |
|
@@ -90,12 +81,13 @@ public function testClearFiles(): void { |
90 | 81 | ->disableOriginalConstructor() |
91 | 82 | ->getMock(); |
92 | 83 |
|
| 84 | + $rootFolder = \OCP\Server::get(IRootFolder::class); |
| 85 | + |
93 | 86 | // scan home storage so that mounts are properly setup |
94 | | - \OC::$server->getRootFolder()->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
| 87 | + $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
95 | 88 |
|
96 | 89 | $this->loginAsUser($this->user1); |
97 | 90 |
|
98 | | - |
99 | 91 | $view = new View('/' . $this->user1 . '/'); |
100 | 92 | $view->mkdir('files/test'); |
101 | 93 |
|
@@ -132,6 +124,8 @@ public function testClearFiles(): void { |
132 | 124 | $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up'); |
133 | 125 | $this->assertCount(0, $this->getMounts($numericStorageId), 'Asserts that mount gets cleaned up'); |
134 | 126 |
|
| 127 | + // Rescan folder to add back to cache before deleting |
| 128 | + $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
135 | 129 | // since we deleted the storage it might throw a (valid) StorageNotAvailableException |
136 | 130 | try { |
137 | 131 | $view->unlink('files/test'); |
|
0 commit comments