aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-11-23 15:41:20 +0100
committerGitHub <noreply@github.com>2021-11-23 15:41:20 +0100
commitfd487c1a43874bf7eaeebe2ff822e18978b6d1e1 (patch)
treea69c74aa76577beac40700eaf47d28b5e8bd1af9 /tests
parent20dd46fcaed56b7df151fe1a5273cdadc22a583e (diff)
parent18a91f02fadf108bfa1a60f258ebacd2f802224b (diff)
downloadnextcloud-server-fd487c1a43874bf7eaeebe2ff822e18978b6d1e1.tar.gz
nextcloud-server-fd487c1a43874bf7eaeebe2ff822e18978b6d1e1.zip
Merge pull request #29432 from nextcloud/fix/support-php-8.1
Support PHP 8.1 - First batch
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php7
-rw-r--r--tests/Core/Command/Log/FileTest.php3
-rw-r--r--tests/Core/Command/Preview/RepairTest.php7
-rw-r--r--tests/Core/Controller/AvatarControllerTest.php6
-rw-r--r--tests/Core/Controller/CssControllerTest.php6
-rw-r--r--tests/Core/Controller/GuestAvatarControllerTest.php2
-rw-r--r--tests/Core/Controller/JsControllerTest.php6
-rw-r--r--tests/Core/Controller/PreviewControllerTest.php2
-rw-r--r--tests/lib/AppFramework/Http/DispatcherTest.php2
-rw-r--r--tests/lib/AppFramework/Http/ResponseTest.php6
-rw-r--r--tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php2
-rw-r--r--tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php2
-rw-r--r--tests/lib/Encryption/DecryptAllTest.php13
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php13
-rw-r--r--tests/lib/Files/Node/FolderTest.php6
-rw-r--r--tests/lib/Http/Client/ResponseTest.php4
-rw-r--r--tests/lib/InitialStateServiceTest.php2
-rw-r--r--tests/lib/TempManagerTest.php4
-rw-r--r--tests/lib/User/ManagerTest.php14
19 files changed, 85 insertions, 22 deletions
diff --git a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
index 02cc824ee0c..fc916ad4099 100644
--- a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
+++ b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
@@ -74,9 +74,12 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->outputInterface = $this->getMockBuilder(OutputInterface::class)->getMock();
$this->userInterface = $this->getMockBuilder(UserInterface::class)->getMock();
- $outputFormatterInterface = $this->getMockBuilder(OutputFormatterInterface::class)->getMock();
+ /* We need format method to return a string */
+ $outputFormatter = $this->createMock(OutputFormatterInterface::class);
+ $outputFormatter->method('format')->willReturnArgument(0);
+
$this->outputInterface->expects($this->any())->method('getFormatter')
- ->willReturn($outputFormatterInterface);
+ ->willReturn($outputFormatter);
$this->changeKeyStorageRoot = new ChangeKeyStorageRoot(
$this->view,
diff --git a/tests/Core/Command/Log/FileTest.php b/tests/Core/Command/Log/FileTest.php
index 1a8a86759f5..103888de287 100644
--- a/tests/Core/Command/Log/FileTest.php
+++ b/tests/Core/Command/Log/FileTest.php
@@ -51,6 +51,7 @@ class FileTest extends TestCase {
}
public function testEnable() {
+ $this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['enable', 'true']
@@ -63,6 +64,7 @@ class FileTest extends TestCase {
}
public function testChangeFile() {
+ $this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['file', '/foo/bar/file.log']
@@ -87,6 +89,7 @@ class FileTest extends TestCase {
* @dataProvider changeRotateSizeProvider
*/
public function testChangeRotateSize($optionValue, $configValue) {
+ $this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['rotate-size', $optionValue]
diff --git a/tests/Core/Command/Preview/RepairTest.php b/tests/Core/Command/Preview/RepairTest.php
index c37e57f848c..a6591745817 100644
--- a/tests/Core/Command/Preview/RepairTest.php
+++ b/tests/Core/Command/Preview/RepairTest.php
@@ -68,9 +68,14 @@ class RepairTest extends TestCase {
$this->output->expects($this->any())
->method('section')
->willReturn($this->output);
+
+ /* We need format method to return a string */
+ $outputFormatter = $this->createMock(OutputFormatterInterface::class);
+ $outputFormatter->method('format')->willReturnArgument(0);
+
$this->output->expects($this->any())
->method('getFormatter')
- ->willReturn($this->getMockBuilder(OutputFormatterInterface::class)->getMock());
+ ->willReturn($outputFormatter);
$this->output->expects($this->any())
->method('writeln')
->willReturnCallback(function ($line) use ($self) {
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php
index d6c4ea6217c..35d89c24a45 100644
--- a/tests/Core/Controller/AvatarControllerTest.php
+++ b/tests/Core/Controller/AvatarControllerTest.php
@@ -119,6 +119,8 @@ class AvatarControllerTest extends \Test\TestCase {
$this->avatarFile->method('getContent')->willReturn('image data');
$this->avatarFile->method('getMimeType')->willReturn('image type');
$this->avatarFile->method('getEtag')->willReturn('my etag');
+ $this->avatarFile->method('getName')->willReturn('my name');
+ $this->avatarFile->method('getMTime')->willReturn(42);
}
protected function tearDown(): void {
@@ -290,7 +292,7 @@ class AvatarControllerTest extends \Test\TestCase {
*/
public function testPostAvatarFile() {
//Create temp file
- $fileName = tempnam(null, "avatarTest");
+ $fileName = tempnam('', "avatarTest");
$copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.jpg', $fileName);
$this->assertTrue($copyRes);
@@ -328,7 +330,7 @@ class AvatarControllerTest extends \Test\TestCase {
*/
public function testPostAvatarFileGif() {
//Create temp file
- $fileName = tempnam(null, "avatarTest");
+ $fileName = tempnam('', "avatarTest");
$copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.gif', $fileName);
$this->assertTrue($copyRes);
diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php
index 1179bc0c070..d2a791ec1b0 100644
--- a/tests/Core/Controller/CssControllerTest.php
+++ b/tests/Core/Controller/CssControllerTest.php
@@ -102,6 +102,8 @@ class CssControllerTest extends TestCase {
public function testGetFile() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
+ $file->method('getName')->willReturn('my name');
+ $file->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
@@ -125,6 +127,8 @@ class CssControllerTest extends TestCase {
public function testGetGzipFile() {
$folder = $this->createMock(ISimpleFolder::class);
$gzipFile = $this->createMock(ISimpleFile::class);
+ $gzipFile->method('getName')->willReturn('my name');
+ $gzipFile->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
@@ -153,6 +157,8 @@ class CssControllerTest extends TestCase {
public function testGetGzipFileNotFound() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
+ $file->method('getName')->willReturn('my name');
+ $file->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php
index 8870faac4c7..e14a5416c49 100644
--- a/tests/Core/Controller/GuestAvatarControllerTest.php
+++ b/tests/Core/Controller/GuestAvatarControllerTest.php
@@ -56,6 +56,8 @@ class GuestAvatarControllerTest extends \Test\TestCase {
$this->avatar = $this->getMockBuilder(IAvatar::class)->getMock();
$this->avatarManager = $this->getMockBuilder(IAvatarManager::class)->getMock();
$this->file = $this->getMockBuilder(ISimpleFile::class)->getMock();
+ $this->file->method('getName')->willReturn('my name');
+ $this->file->method('getMTime')->willReturn(42);
$this->guestAvatarController = new GuestAvatarController(
'core',
$this->request,
diff --git a/tests/Core/Controller/JsControllerTest.php b/tests/Core/Controller/JsControllerTest.php
index 01228a6a93e..3f76e19efc9 100644
--- a/tests/Core/Controller/JsControllerTest.php
+++ b/tests/Core/Controller/JsControllerTest.php
@@ -102,6 +102,8 @@ class JsControllerTest extends TestCase {
public function testGetFile() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
+ $file->method('getName')->willReturn('my name');
+ $file->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
@@ -125,6 +127,8 @@ class JsControllerTest extends TestCase {
public function testGetGzipFile() {
$folder = $this->createMock(ISimpleFolder::class);
$gzipFile = $this->createMock(ISimpleFile::class);
+ $gzipFile->method('getName')->willReturn('my name');
+ $gzipFile->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
@@ -153,6 +157,8 @@ class JsControllerTest extends TestCase {
public function testGetGzipFileNotFound() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
+ $file->method('getName')->willReturn('my name');
+ $file->method('getMTime')->willReturn(42);
$this->appData->method('getFolder')
->with('myapp')
->willReturn($folder);
diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php
index e1d1529c655..704ddade7a4 100644
--- a/tests/Core/Controller/PreviewControllerTest.php
+++ b/tests/Core/Controller/PreviewControllerTest.php
@@ -212,6 +212,8 @@ class PreviewControllerTest extends \Test\TestCase {
->willReturn(true);
$preview = $this->createMock(ISimpleFile::class);
+ $preview->method('getName')->willReturn('my name');
+ $preview->method('getMTime')->willReturn(42);
$this->previewManager->method('getPreview')
->with($this->equalTo($file), 10, 10, false, $this->equalTo('myMode'))
->willReturn($preview);
diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php
index 966e49effcb..92b772dbe31 100644
--- a/tests/lib/AppFramework/Http/DispatcherTest.php
+++ b/tests/lib/AppFramework/Http/DispatcherTest.php
@@ -148,7 +148,7 @@ class DispatcherTest extends \Test\TestCase {
$this->response = $this->createMock(Response::class);
- $this->lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
+ $this->lastModified = new \DateTime('now', new \DateTimeZone('GMT'));
$this->etag = 'hi';
}
diff --git a/tests/lib/AppFramework/Http/ResponseTest.php b/tests/lib/AppFramework/Http/ResponseTest.php
index 0ef128433cd..97a1ee25588 100644
--- a/tests/lib/AppFramework/Http/ResponseTest.php
+++ b/tests/lib/AppFramework/Http/ResponseTest.php
@@ -216,7 +216,7 @@ class ResponseTest extends \Test\TestCase {
public function testGetLastModified() {
- $lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
+ $lastModified = new \DateTime('now', new \DateTimeZone('GMT'));
$lastModified->setTimestamp(1);
$this->childResponse->setLastModified($lastModified);
$this->assertEquals($lastModified, $this->childResponse->getLastModified());
@@ -252,7 +252,7 @@ class ResponseTest extends \Test\TestCase {
public function testEtagLastModifiedHeaders() {
- $lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
+ $lastModified = new \DateTime('now', new \DateTimeZone('GMT'));
$lastModified->setTimestamp(1);
$this->childResponse->setLastModified($lastModified);
$headers = $this->childResponse->getHeaders();
@@ -260,7 +260,7 @@ class ResponseTest extends \Test\TestCase {
}
public function testChainability() {
- $lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
+ $lastModified = new \DateTime('now', new \DateTimeZone('GMT'));
$lastModified->setTimestamp(1);
$this->childResponse->setEtag('hi')
diff --git a/tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php b/tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php
index 6409ff2dc35..a5038dd23b2 100644
--- a/tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php
+++ b/tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php
@@ -37,7 +37,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
-class RemoteWipeActivityListenerTests extends TestCase {
+class RemoteWipeActivityListenerTest extends TestCase {
/** @var IActivityManager|MockObject */
private $activityManager;
diff --git a/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php b/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php
index 1e03a344404..ef5545438c2 100644
--- a/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php
+++ b/tests/lib/Authentication/Listeners/RemoteWipeNotificationsListenerTest.php
@@ -38,7 +38,7 @@ use OCP\Notification\INotification;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
-class RemoteWipeNotificationListenerTests extends TestCase {
+class RemoteWipeNotificationsListenerTest extends TestCase {
/** @var INotificationManager|MockObject */
private $notificationManager;
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php
index dc7c40f0fe2..90ff045a9b9 100644
--- a/tests/lib/Encryption/DecryptAllTest.php
+++ b/tests/lib/Encryption/DecryptAllTest.php
@@ -81,8 +81,12 @@ class DecryptAllTest extends TestCase {
$this->userInterface = $this->getMockBuilder(UserInterface::class)
->disableOriginalConstructor()->getMock();
+ /* We need format method to return a string */
+ $outputFormatter = $this->createMock(OutputFormatterInterface::class);
+ $outputFormatter->method('format')->willReturn('foo');
+
$this->outputInterface->expects($this->any())->method('getFormatter')
- ->willReturn($this->createMock(OutputFormatterInterface::class));
+ ->willReturn($outputFormatter);
$this->instance = new DecryptAll($this->encryptionManager, $this->userManager, $this->view);
@@ -298,10 +302,15 @@ class DecryptAllTest extends TestCase {
->method('decryptFile')
->with('/user1/files/foo/subfile');
+
+ /* We need format method to return a string */
+ $outputFormatter = $this->createMock(OutputFormatterInterface::class);
+ $outputFormatter->method('format')->willReturn('foo');
+
$output = $this->createMock(OutputInterface::class);
$output->expects($this->any())
->method('getFormatter')
- ->willReturn($this->createMock(OutputFormatterInterface::class));
+ ->willReturn($outputFormatter);
$progressBar = new ProgressBar($output);
$this->invokePrivate($instance, 'decryptUsersFiles', ['user1', $progressBar, '']);
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index 4ee0f730440..321ed2196fd 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -47,7 +47,18 @@ class UserMountCacheTest extends TestCase {
protected function setUp(): void {
$this->fileIds = [];
$this->connection = \OC::$server->getDatabaseConnection();
- $this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class));
+ $config = $this->getMockBuilder(IConfig::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $config
+ ->expects($this->any())
+ ->method('getUserValue')
+ ->willReturnArgument(3);
+ $config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnArgument(2);
+ $this->userManager = new Manager($config, $this->createMock(EventDispatcherInterface::class), $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class));
$userBackend = new Dummy();
$userBackend->createUser('u1', '');
$userBackend->createUser('u2', '');
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 94bcac4aa00..067f7288544 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -418,7 +418,7 @@ class FolderTest extends NodeTest {
$subStorage = $this->createMock(Storage::class);
$subStorage->method('getId')->willReturn('test::2');
$subCache = new Cache($subStorage);
- $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
+ $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
$mount = $this->createMock(IMountPoint::class);
$mount->method('getStorage')
@@ -954,11 +954,11 @@ class FolderTest extends NodeTest {
$subStorage1 = $this->createMock(Storage::class);
$subStorage1->method('getId')->willReturn('test::2');
$subCache1 = new Cache($subStorage1);
- $subMount1 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
+ $subMount1 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
$subStorage2 = $this->createMock(Storage::class);
$subStorage2->method('getId')->willReturn('test::3');
$subCache2 = new Cache($subStorage2);
- $subMount2 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
+ $subMount2 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
$mount = $this->createMock(IMountPoint::class);
$mount->method('getStorage')
diff --git a/tests/lib/Http/Client/ResponseTest.php b/tests/lib/Http/Client/ResponseTest.php
index f8f520d6a73..1384e4e732c 100644
--- a/tests/lib/Http/Client/ResponseTest.php
+++ b/tests/lib/Http/Client/ResponseTest.php
@@ -9,7 +9,7 @@
namespace Test\Http\Client;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
-use function GuzzleHttp\Psr7\stream_for;
+use GuzzleHttp\Psr7\Utils;
use OC\Http\Client\Response;
/**
@@ -25,7 +25,7 @@ class ResponseTest extends \Test\TestCase {
}
public function testGetBody() {
- $response = new Response($this->guzzleResponse->withBody(stream_for('MyResponse')));
+ $response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse')));
$this->assertSame('MyResponse', $response->getBody());
}
diff --git a/tests/lib/InitialStateServiceTest.php b/tests/lib/InitialStateServiceTest.php
index 2a23774baf1..db4c98b20cf 100644
--- a/tests/lib/InitialStateServiceTest.php
+++ b/tests/lib/InitialStateServiceTest.php
@@ -54,7 +54,7 @@ class InitialStateServiceTest extends TestCase {
[23],
[2.3],
[new class implements JsonSerializable {
- public function jsonSerialize() {
+ public function jsonSerialize(): int {
return 3;
}
}],
diff --git a/tests/lib/TempManagerTest.php b/tests/lib/TempManagerTest.php
index 5df0e68d4fa..fd4ef8e2324 100644
--- a/tests/lib/TempManagerTest.php
+++ b/tests/lib/TempManagerTest.php
@@ -26,7 +26,9 @@ class TempManagerTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->baseDir);
+ if ($this->baseDir !== null) {
+ \OC_Helper::rmdirr($this->baseDir);
+ }
$this->baseDir = null;
parent::tearDown();
}
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index cfdecba9803..51a739994a6 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -667,7 +667,19 @@ class ManagerTest extends TestCase {
}
public function testDeleteUser() {
- $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
+ $config = $this->getMockBuilder(AllConfig::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $config
+ ->expects($this->any())
+ ->method('getUserValue')
+ ->willReturnArgument(3);
+ $config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnArgument(2);
+
+ $manager = new \OC\User\Manager($config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
$backend = new \Test\Util\User\Dummy();
$manager->registerBackend($backend);