From eeb8f079433f704d741e9d6b7fc43f24191da7d6 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 9 Mar 2017 16:31:51 +0100 Subject: [PATCH] Fix locking tests in ViewTest --- tests/lib/Files/ViewTest.php | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index fb564344942d..fb09b37c8cfd 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1723,6 +1723,8 @@ public function basicOperationProviderForLocks() { ILockingProvider::LOCK_SHARED, ILockingProvider::LOCK_SHARED, null, + // shared lock stays until fclose + ILockingProvider::LOCK_SHARED, ], [ 'opendir', @@ -1797,9 +1799,12 @@ public function testLockBasicOperation( $storage->expects($this->once()) ->method($operation) ->will($this->returnCallback( - function () use ($view, $lockedPath, &$lockTypeDuring) { + function () use ($view, $lockedPath, &$lockTypeDuring, $operation) { $lockTypeDuring = $this->getFileLockType($view, $lockedPath); + if ($operation === 'fopen') { + return fopen('data://text/plain,test', 'r'); + } return true; } )); @@ -1809,7 +1814,7 @@ function () use ($view, $lockedPath, &$lockTypeDuring) { $this->connectMockHooks($hookType, $view, $lockedPath, $lockTypePre, $lockTypePost); // do operation - call_user_func_array([$view, $operation], $operationArgs); + $result = call_user_func_array([$view, $operation], $operationArgs); if ($hookType !== null) { $this->assertEquals($expectedLockBefore, $lockTypePre, 'File locked properly during pre-hook'); @@ -1820,6 +1825,13 @@ function () use ($view, $lockedPath, &$lockTypeDuring) { } $this->assertEquals($expectedStrayLock, $this->getFileLockType($view, $lockedPath)); + + if (is_resource($result)) { + fclose($result); + + // lock is cleared after fclose + $this->assertNull($this->getFileLockType($view, $lockedPath)); + } } /** @@ -2515,4 +2527,23 @@ public function testDeleteGhostFolder() { $this->assertNotEquals($rootInfo->getEtag(), $newInfo->getEtag()); $this->assertEquals(0, $newInfo->getSize()); } + + public function testFopenFail() { + // since stream wrappers influence the streams, + // this test makes sure that all stream wrappers properly return a failure + // to the caller instead of wrapping the boolean + /** @var Temporary | \PHPUnit_Framework_MockObject_MockObject $storage */ + $storage = $this->getMockBuilder(Temporary::class) + ->setMethods(['fopen']) + ->getMock(); + + $storage->expects($this->once()) + ->method('fopen') + ->willReturn(false); + + Filesystem::mount($storage, [], '/'); + $view = new View('/files'); + $result = $view->fopen('unexist.txt', 'r'); + $this->assertFalse($result); + } }