Skip to content

Commit

Permalink
Merge pull request #45159 from nextcloud/fix/tests-deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
Altahrim authored May 3, 2024
2 parents 6e39a15 + f82c5f0 commit 73e61c5
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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())
Expand All @@ -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')
Expand Down Expand Up @@ -927,6 +934,7 @@ public function testUploadAbort(): void {

public function testDeleteWhenAllowed(): void {
// setup
/** @var View|MockObject */
$view = $this->getMockBuilder(View::class)
->getMock();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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');
Expand Down

0 comments on commit 73e61c5

Please sign in to comment.