diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-05-02 19:17:11 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-05-02 20:56:09 +0200 |
commit | f82c5f0146e6e6ffb0a1daa4532d52d5a371641e (patch) | |
tree | eae7724f0e6514a3aa6c83f34b733d1f9555a3b2 /apps | |
parent | dbd2bc7a666bc23fc47b940f188e386d83b210de (diff) | |
download | nextcloud-server-f82c5f0146e6e6ffb0a1daa4532d52d5a371641e.tar.gz nextcloud-server-f82c5f0146e6e6ffb0a1daa4532d52d5a371641e.zip |
fix(tests): Replace deprecated methods in `FileTest`
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FileTest.php | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 688b1ac6b44..a858c57b952 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -42,6 +42,8 @@ use OCP\Files\ForbiddenException; use OCP\Files\Storage; use OCP\IConfig; use OCP\IRequestId; +use OCP\ITempManager; +use OCP\IUserManager; use OCP\Lock\ILockingProvider; use PHPUnit\Framework\MockObject\MockObject; use Test\HookHelper; @@ -86,7 +88,7 @@ class FileTest extends TestCase { } protected function tearDown(): void { - $userManager = \OC::$server->getUserManager(); + $userManager = \OCP\Server::get(IUserManager::class); $userManager->get($this->user)->delete(); parent::tearDown(); @@ -177,13 +179,13 @@ class FileTest extends TestCase { public function testSimplePutFails($thrownException, $expectedException, $checkPreviousClass = true): void { // setup $storage = $this->getMockBuilder(Local::class) - ->setMethods(['writeStream']) - ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]) + ->onlyMethods(['writeStream']) + ->setConstructorArgs([['datadir' => \OCP\Server::get(ITempManager::class)->getTemporaryFolder()]]) ->getMock(); \OC\Files\Filesystem::mount($storage, [], $this->user . '/'); /** @var View | MockObject $view */ $view = $this->getMockBuilder(View::class) - ->setMethods(['getRelativePath', 'resolvePath']) + ->onlyMethods(['getRelativePath', 'resolvePath']) ->getMock(); $view->expects($this->atLeastOnce()) ->method('resolvePath') @@ -238,12 +240,13 @@ class FileTest extends TestCase { public function testChunkedPutFails($thrownException, $expectedException, $checkPreviousClass = false): void { // setup $storage = $this->getMockBuilder(Local::class) - ->setMethods(['fopen']) - ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]) + ->onlyMethods(['fopen']) + ->setConstructorArgs([['datadir' => \OCP\Server::get(ITempManager::class)->getTemporaryFolder()]]) ->getMock(); \OC\Files\Filesystem::mount($storage, [], $this->user . '/'); + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['getRelativePath', 'resolvePath']) + ->onlyMethods(['getRelativePath', 'resolvePath']) ->getMock(); $view->expects($this->atLeastOnce()) ->method('resolvePath') @@ -340,7 +343,7 @@ class FileTest extends TestCase { /** @var \OCA\DAV\Connector\Sabre\File | MockObject $file */ $file = $this->getMockBuilder(\OCA\DAV\Connector\Sabre\File::class) ->setConstructorArgs([$view, $info, null, $request]) - ->setMethods(['header']) + ->onlyMethods(['header']) ->getMock(); // beforeMethod locks @@ -690,8 +693,9 @@ class FileTest extends TestCase { */ public function testSimplePutFailsSizeCheck(): void { // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['rename', 'getRelativePath', 'filesize']) + ->onlyMethods(['rename', 'getRelativePath', 'filesize']) ->getMock(); $view->expects($this->any()) ->method('rename') @@ -820,8 +824,9 @@ class FileTest extends TestCase { */ public function testSimplePutInvalidChars(): void { // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['getRelativePath']) + ->onlyMethods(['getRelativePath']) ->getMock(); $view->expects($this->any()) ->method('getRelativePath') @@ -859,8 +864,9 @@ class FileTest extends TestCase { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['getRelativePath']) + ->onlyMethods(['getRelativePath']) ->getMock(); $view->expects($this->any()) @@ -878,8 +884,9 @@ class FileTest extends TestCase { public function testUploadAbort(): void { // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['rename', 'getRelativePath', 'filesize']) + ->onlyMethods(['rename', 'getRelativePath', 'filesize']) ->getMock(); $view->expects($this->any()) ->method('rename') @@ -927,6 +934,7 @@ class FileTest extends TestCase { public function testDeleteWhenAllowed(): void { // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -950,6 +958,7 @@ class FileTest extends TestCase { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -969,6 +978,7 @@ class FileTest extends TestCase { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -993,6 +1003,7 @@ class FileTest extends TestCase { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -1060,7 +1071,7 @@ class FileTest extends TestCase { $wasLockedPre = false; $wasLockedPost = false; $eventHandler = $this->getMockBuilder(\stdclass::class) - ->setMethods(['writeCallback', 'postWriteCallback']) + ->addMethods(['writeCallback', 'postWriteCallback']) ->getMock(); // both pre and post hooks might need access to the file, @@ -1166,8 +1177,9 @@ class FileTest extends TestCase { public function testGetFopenFails(): void { $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['fopen']) + ->onlyMethods(['fopen']) ->getMock(); $view->expects($this->atLeastOnce()) ->method('fopen') @@ -1187,8 +1199,9 @@ class FileTest extends TestCase { public function testGetFopenThrows(): void { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['fopen']) + ->onlyMethods(['fopen']) ->getMock(); $view->expects($this->atLeastOnce()) ->method('fopen') @@ -1208,8 +1221,9 @@ class FileTest extends TestCase { public function testGetThrowsIfNoPermission(): void { $this->expectException(\Sabre\DAV\Exception\NotFound::class); + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) - ->setMethods(['fopen']) + ->onlyMethods(['fopen']) ->getMock(); $view->expects($this->never()) ->method('fopen'); |