From f82c5f0146e6e6ffb0a1daa4532d52d5a371641e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 2 May 2024 19:17:11 +0200 Subject: [PATCH] fix(tests): Replace deprecated methods in `FileTest` Signed-off-by: Ferdinand Thiessen --- .../tests/unit/Connector/Sabre/FileTest.php | 46 ++++++++++++------- 1 file 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 688b1ac6b44b9..a858c57b952a6 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\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 @@ protected function setUp(): void { } 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 @@ public function fopenFailuresProvider() { 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 @@ function ($path) use ($storage) { 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 @@ private function doPut($path, $viewRoot = null, ?Request $request = null) { /** @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 @@ public function testPutSingleFileCancelPreHook(): void { */ 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 @@ public function testChunkedPutFailsFinalRename(): void { */ 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 @@ public function testSetNameInvalidChars(): void { $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 @@ public function testSetNameInvalidChars(): void { 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 @@ public function testUploadAbort(): void { public function testDeleteWhenAllowed(): void { // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -950,6 +958,7 @@ public function testDeleteThrowsWhenDeletionNotAllowed(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -969,6 +978,7 @@ public function testDeleteThrowsWhenDeletionFailed(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -993,6 +1003,7 @@ public function testDeleteThrowsWhenDeletionThrows(): void { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); // setup + /** @var View|MockObject */ $view = $this->getMockBuilder(View::class) ->getMock(); @@ -1060,7 +1071,7 @@ public function testPutLocking(): void { $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 @@ private function getFileInfos($path = '', ?View $userView = null) { 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 @@ public function testGetFopenFails(): void { 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 @@ public function testGetFopenThrows(): void { 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');