Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-08-26 14:47:35 +0300
committerBackportbot <backportbot-noreply@rullzer.com>2019-09-09 17:51:31 +0300
commitf48f8f94c7451d93024d8f285586bc81f1dd8396 (patch)
tree86b1425859437175b6657ae0bb784fd0af30faa9 /tests
parentf42a6e05060e9a173ba71d3fc6efa6483fb81556 (diff)
adjust tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Storage/Wrapper/AvailabilityTest.php94
1 files changed, 53 insertions, 41 deletions
diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
index 5ea7f8403ce..1672d17e36b 100644
--- a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
+++ b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
@@ -21,29 +21,46 @@
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Cache\Storage as StorageCache;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Availability;
+use OCP\Files\StorageNotAvailableException;
+
class AvailabilityTest extends \Test\TestCase {
- protected function getWrapperInstance() {
- $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
- ->disableOriginalConstructor()
- ->getMock();
- $wrapper = new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
- return [$storage, $wrapper];
+
+ /** @var \PHPUnit\Framework\MockObject\MockObject|StorageCache */
+ protected $storageCache;
+ /** @var \PHPUnit\Framework\MockObject\MockObject|Temporary */
+ protected $storage;
+ /** @var Availability */
+ protected $wrapper;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->storageCache = $this->createMock(StorageCache::class);
+
+ $this->storage = $this->createMock(Temporary::class);
+ $this->storage->expects($this->any())
+ ->method('getStorageCache')
+ ->willReturn($this->storageCache);
+
+ $this->wrapper = new Availability(['storage' => $this->storage]);
}
/**
* Storage is available
*/
public function testAvailable() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('test');
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('mkdir');
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
/**
@@ -52,39 +69,37 @@ class AvailabilityTest extends \Test\TestCase {
* @expectedException \OCP\Files\StorageNotAvailableException
*/
public function testUnavailable() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => false, 'last_checked' => time()]);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('test');
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('mkdir');
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
/**
* Storage marked unavailable, TTL expired
*/
public function testUnavailableRecheck() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => false, 'last_checked' => 0]);
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('test')
->willReturn(true);
- $storage->expects($this->exactly(2))
+ $this->storage->expects($this->exactly(2))
->method('setAvailability')
->withConsecutive(
[$this->equalTo(false)], // prevents concurrent rechecks
[$this->equalTo(true)] // sets correct availability
);
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('mkdir');
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
/**
@@ -93,20 +108,19 @@ class AvailabilityTest extends \Test\TestCase {
* @expectedException \OCP\Files\StorageNotAvailableException
*/
public function testAvailableThrowStorageNotAvailable() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('test');
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('mkdir')
- ->will($this->throwException(new \OCP\Files\StorageNotAvailableException()));
- $storage->expects($this->once())
+ ->will($this->throwException(new StorageNotAvailableException()));
+ $this->storageCache->expects($this->once())
->method('setAvailability')
->with($this->equalTo(false));
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
/**
@@ -114,19 +128,18 @@ class AvailabilityTest extends \Test\TestCase {
* Method failure does not indicate storage unavailability
*/
public function testAvailableFailure() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('test');
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('mkdir')
->willReturn(false);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('setAvailability');
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
/**
@@ -136,18 +149,17 @@ class AvailabilityTest extends \Test\TestCase {
* @expectedException \Exception
*/
public function testAvailableThrow() {
- list($storage, $wrapper) = $this->getWrapperInstance();
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('test');
- $storage->expects($this->once())
+ $this->storage->expects($this->once())
->method('mkdir')
->will($this->throwException(new \Exception()));
- $storage->expects($this->never())
+ $this->storage->expects($this->never())
->method('setAvailability');
- $wrapper->mkdir('foobar');
+ $this->wrapper->mkdir('foobar');
}
}