Skip to content

Commit

Permalink
Fix locking tests in ViewTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Mar 9, 2017
1 parent d7091b5 commit eeb8f07
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,8 @@ public function basicOperationProviderForLocks() {
ILockingProvider::LOCK_SHARED,
ILockingProvider::LOCK_SHARED,
null,
// shared lock stays until fclose
ILockingProvider::LOCK_SHARED,
],
[
'opendir',
Expand Down Expand Up @@ -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;
}
));
Expand All @@ -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');
Expand All @@ -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));
}
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit eeb8f07

Please sign in to comment.