aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Storage/Wrapper/AvailabilityTest.php')
-rw-r--r--tests/lib/Files/Storage/Wrapper/AvailabilityTest.php35
1 files changed, 20 insertions, 15 deletions
diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
index ef7b457636c..d890081cbb6 100644
--- a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
+++ b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,7 +18,7 @@ class AvailabilityTest extends \Test\TestCase {
protected $storageCache;
/** @var \PHPUnit\Framework\MockObject\MockObject|Temporary */
protected $storage;
- /** @var Availability */
+ /** @var Availability */
protected $wrapper;
protected function setUp(): void {
@@ -36,7 +37,7 @@ class AvailabilityTest extends \Test\TestCase {
/**
* Storage is available
*/
- public function testAvailable() {
+ public function testAvailable(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
@@ -52,8 +53,8 @@ class AvailabilityTest extends \Test\TestCase {
* Storage marked unavailable, TTL not expired
*
*/
- public function testUnavailable() {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ public function testUnavailable(): void {
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -69,19 +70,23 @@ class AvailabilityTest extends \Test\TestCase {
/**
* Storage marked unavailable, TTL expired
*/
- public function testUnavailableRecheck() {
+ public function testUnavailableRecheck(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => false, 'last_checked' => 0]);
$this->storage->expects($this->once())
->method('test')
->willReturn(true);
+ $calls = [
+ false, // prevents concurrent rechecks
+ true, // sets correct availability
+ ];
$this->storage->expects($this->exactly(2))
->method('setAvailability')
- ->withConsecutive(
- [$this->equalTo(false)], // prevents concurrent rechecks
- [$this->equalTo(true)] // sets correct availability
- );
+ ->willReturnCallback(function ($value) use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $value);
+ });
$this->storage->expects($this->once())
->method('mkdir');
@@ -92,8 +97,8 @@ class AvailabilityTest extends \Test\TestCase {
* Storage marked available, but throws StorageNotAvailableException
*
*/
- public function testAvailableThrowStorageNotAvailable() {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ public function testAvailableThrowStorageNotAvailable(): void {
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -102,7 +107,7 @@ class AvailabilityTest extends \Test\TestCase {
->method('test');
$this->storage->expects($this->once())
->method('mkdir')
- ->will($this->throwException(new StorageNotAvailableException()));
+ ->willThrowException(new StorageNotAvailableException());
$this->storageCache->expects($this->once())
->method('setAvailability')
->with($this->equalTo(false));
@@ -114,7 +119,7 @@ class AvailabilityTest extends \Test\TestCase {
* Storage available, but call fails
* Method failure does not indicate storage unavailability
*/
- public function testAvailableFailure() {
+ public function testAvailableFailure(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
@@ -134,7 +139,7 @@ class AvailabilityTest extends \Test\TestCase {
* Standard exception does not indicate storage unavailability
*
*/
- public function testAvailableThrow() {
+ public function testAvailableThrow(): void {
$this->expectException(\Exception::class);
$this->storage->expects($this->once())
@@ -144,7 +149,7 @@ class AvailabilityTest extends \Test\TestCase {
->method('test');
$this->storage->expects($this->once())
->method('mkdir')
- ->will($this->throwException(new \Exception()));
+ ->willThrowException(new \Exception());
$this->storage->expects($this->never())
->method('setAvailability');