aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/tests')
-rw-r--r--apps/files_versions/tests/BackgroundJob/ExpireVersionsTest.php17
-rw-r--r--apps/files_versions/tests/Command/CleanupTest.php53
-rw-r--r--apps/files_versions/tests/Command/ExpireTest.php2
-rw-r--r--apps/files_versions/tests/Controller/PreviewControllerTest.php30
-rw-r--r--apps/files_versions/tests/ExpirationTest.php24
-rw-r--r--apps/files_versions/tests/StorageTest.php4
-rw-r--r--apps/files_versions/tests/VersioningTest.php29
-rw-r--r--apps/files_versions/tests/Versions/VersionManagerTest.php7
8 files changed, 63 insertions, 103 deletions
diff --git a/apps/files_versions/tests/BackgroundJob/ExpireVersionsTest.php b/apps/files_versions/tests/BackgroundJob/ExpireVersionsTest.php
index 7a35e9f5f39..21e88e86f90 100644
--- a/apps/files_versions/tests/BackgroundJob/ExpireVersionsTest.php
+++ b/apps/files_versions/tests/BackgroundJob/ExpireVersionsTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -16,17 +18,10 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ExpireVersionsTest extends TestCase {
- /** @var IConfig|MockObject */
- private $config;
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var Expiration|MockObject */
- private $expiration;
-
- /** @var IJobList|MockObject */
- private $jobList;
+ private IConfig&MockObject $config;
+ private IUserManager&MockObject $userManager;
+ private Expiration&MockObject $expiration;
+ private IJobList&MockObject $jobList;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php
index 62d9576e9c5..b0a5c0ca268 100644
--- a/apps/files_versions/tests/Command/CleanupTest.php
+++ b/apps/files_versions/tests/Command/CleanupTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,11 +10,13 @@ namespace OCA\Files_Versions\Tests\Command;
use OC\User\Manager;
use OCA\Files_Versions\Command\CleanUp;
+use OCA\Files_Versions\Db\VersionsMapper;
use OCP\Files\Cache\ICache;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Storage\IStorage;
use OCP\UserInterface;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -23,28 +27,17 @@ use Test\TestCase;
* @package OCA\Files_Versions\Tests\Command
*/
class CleanupTest extends TestCase {
-
- /** @var CleanUp */
- protected $cleanup;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | Manager */
- protected $userManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IRootFolder */
- protected $rootFolder;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | VersionsMapper */
- protected $versionMapper;
+ protected Manager&MockObject $userManager;
+ protected IRootFolder&MockObject $rootFolder;
+ protected VersionsMapper&MockObject $versionMapper;
+ protected CleanUp $cleanup;
protected function setUp(): void {
parent::setUp();
- $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')
- ->disableOriginalConstructor()->getMock();
- $this->userManager = $this->getMockBuilder('OC\User\Manager')
- ->disableOriginalConstructor()->getMock();
- $this->versionMapper = $this->getMockBuilder('OCA\Files_Versions\Db\VersionsMapper')
- ->disableOriginalConstructor()->getMock();
+ $this->rootFolder = $this->createMock(IRootFolder::class);
+ $this->userManager = $this->createMock(Manager::class);
+ $this->versionMapper = $this->createMock(VersionsMapper::class);
$this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->versionMapper);
}
@@ -53,7 +46,7 @@ class CleanupTest extends TestCase {
* @dataProvider dataTestDeleteVersions
* @param boolean $nodeExists
*/
- public function testDeleteVersions($nodeExists): void {
+ public function testDeleteVersions(bool $nodeExists): void {
$this->rootFolder->expects($this->once())
->method('nodeExists')
->with('/testUser/files_versions')
@@ -92,7 +85,7 @@ class CleanupTest extends TestCase {
$this->invokePrivate($this->cleanup, 'deleteVersions', ['testUser']);
}
- public function dataTestDeleteVersions() {
+ public static function dataTestDeleteVersions(): array {
return [
[true],
[false]
@@ -106,8 +99,8 @@ class CleanupTest extends TestCase {
public function testExecuteDeleteListOfUsers(): void {
$userIds = ['user1', 'user2', 'user3'];
- $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
- ->setMethods(['deleteVersions'])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['deleteVersions'])
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
->getMock();
$instance->expects($this->exactly(count($userIds)))
@@ -119,14 +112,12 @@ class CleanupTest extends TestCase {
$this->userManager->expects($this->exactly(count($userIds)))
->method('userExists')->willReturn(true);
- $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()->getMock();
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
$inputInterface->expects($this->once())->method('getArgument')
->with('user_id')
->willReturn($userIds);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
+ $outputInterface = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
$this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
}
@@ -138,8 +129,8 @@ class CleanupTest extends TestCase {
$userIds = [];
$backendUsers = ['user1', 'user2'];
- $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
- ->setMethods(['deleteVersions'])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['deleteVersions'])
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
->getMock();
@@ -155,14 +146,12 @@ class CleanupTest extends TestCase {
$this->assertTrue(in_array($user, $backendUsers));
});
- $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()->getMock();
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
$inputInterface->expects($this->once())->method('getArgument')
->with('user_id')
->willReturn($userIds);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
+ $outputInterface = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
$this->userManager->expects($this->once())
->method('getBackends')
diff --git a/apps/files_versions/tests/Command/ExpireTest.php b/apps/files_versions/tests/Command/ExpireTest.php
index 11f4eb2e2be..b74457a7fd6 100644
--- a/apps/files_versions/tests/Command/ExpireTest.php
+++ b/apps/files_versions/tests/Command/ExpireTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_versions/tests/Controller/PreviewControllerTest.php b/apps/files_versions/tests/Controller/PreviewControllerTest.php
index 0e36703d5aa..542ea2b6b34 100644
--- a/apps/files_versions/tests/Controller/PreviewControllerTest.php
+++ b/apps/files_versions/tests/Controller/PreviewControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,7 +14,6 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\Files\File;
use OCP\Files\Folder;
-use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
@@ -25,29 +26,14 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PreviewControllerTest extends TestCase {
-
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- private $rootFolder;
-
- /** @var string */
- private $userId;
-
- /** @var IMimeTypeDetector|\PHPUnit\Framework\MockObject\MockObject */
- private $mimeTypeDetector;
-
- /** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */
- private $previewManager;
-
- /** @var PreviewController|\PHPUnit\Framework\MockObject\MockObject */
- private $controller;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
-
- /** @var IVersionManager|\PHPUnit\Framework\MockObject\MockObject */
- private $versionManager;
+ private IRootFolder&MockObject $rootFolder;
+ private string $userId;
+ private IPreview&MockObject $previewManager;
+ private IUserSession&MockObject $userSession;
+ private IVersionManager&MockObject $versionManager;
private IMimeIconProvider&MockObject $mimeIconProvider;
+ private PreviewController $controller;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/files_versions/tests/ExpirationTest.php b/apps/files_versions/tests/ExpirationTest.php
index ac8af7c093a..866e4861741 100644
--- a/apps/files_versions/tests/ExpirationTest.php
+++ b/apps/files_versions/tests/ExpirationTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -15,7 +17,7 @@ use Psr\Log\LoggerInterface;
class ExpirationTest extends \Test\TestCase {
public const SECONDS_PER_DAY = 86400; //60*60*24
- public function expirationData() {
+ public static function expirationData(): array {
$today = 100 * self::SECONDS_PER_DAY;
$back10Days = (100 - 10) * self::SECONDS_PER_DAY;
$back20Days = (100 - 20) * self::SECONDS_PER_DAY;
@@ -81,14 +83,8 @@ class ExpirationTest extends \Test\TestCase {
/**
* @dataProvider expirationData
- *
- * @param string $retentionObligation
- * @param int $timeNow
- * @param int $timestamp
- * @param bool $quotaExceeded
- * @param string $expectedResult
*/
- public function testExpiration($retentionObligation, $timeNow, $timestamp, $quotaExceeded, $expectedResult): void {
+ public function testExpiration(string $retentionObligation, int $timeNow, int $timestamp, bool $quotaExceeded, bool $expectedResult): void {
$mockedConfig = $this->getMockedConfig($retentionObligation);
$mockedTimeFactory = $this->getMockedTimeFactory($timeNow);
$mockedLogger = $this->createMock(LoggerInterface::class);
@@ -100,11 +96,7 @@ class ExpirationTest extends \Test\TestCase {
}
- /**
- * @param int $time
- * @return ITimeFactory|MockObject
- */
- private function getMockedTimeFactory($time) {
+ private function getMockedTimeFactory(int $time): ITimeFactory&MockObject {
$mockedTimeFactory = $this->createMock(ITimeFactory::class);
$mockedTimeFactory->expects($this->any())
->method('getTime')
@@ -113,11 +105,7 @@ class ExpirationTest extends \Test\TestCase {
return $mockedTimeFactory;
}
- /**
- * @param string $returnValue
- * @return IConfig|MockObject
- */
- private function getMockedConfig($returnValue) {
+ private function getMockedConfig(string $returnValue): IConfig&MockObject {
$mockedConfig = $this->createMock(IConfig::class);
$mockedConfig->expects($this->any())
->method('getSystemValue')
diff --git a/apps/files_versions/tests/StorageTest.php b/apps/files_versions/tests/StorageTest.php
index dd5b94c7a22..592f03f5e63 100644
--- a/apps/files_versions/tests/StorageTest.php
+++ b/apps/files_versions/tests/StorageTest.php
@@ -24,7 +24,7 @@ class StorageTest extends TestCase {
private $versionsRoot;
private $userFolder;
- private $expireTimestamp = 10;
+ private int $expireTimestamp = 10;
protected function setUp(): void {
parent::setUp();
@@ -46,7 +46,7 @@ class StorageTest extends TestCase {
}
- protected function createPastFile(string $path, int $mtime) {
+ protected function createPastFile(string $path, int $mtime): void {
try {
$file = $this->userFolder->get($path);
} catch (NotFoundException $e) {
diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php
index eaa0a02e261..659b2cff10c 100644
--- a/apps/files_versions/tests/VersioningTest.php
+++ b/apps/files_versions/tests/VersioningTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -163,7 +165,7 @@ class VersioningTest extends \Test\TestCase {
}
}
- public function versionsProvider() {
+ public static function versionsProvider(): array {
return [
// first set of versions uniformly distributed versions
[
@@ -683,7 +685,7 @@ class VersioningTest extends \Test\TestCase {
$firstVersion = current($versions);
- $this->assertFalse(Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user2), 'Revert did not happen');
+ $this->assertFalse(Storage::rollback('folder/test.txt', (int)$firstVersion['version'], $this->user2), 'Revert did not happen');
$this->loginAsUser(self::TEST_VERSIONS_USER);
@@ -743,8 +745,8 @@ class VersioningTest extends \Test\TestCase {
return;
}
- $eventHandler = $this->getMockBuilder(\stdclass::class)
- ->setMethods(['callback'])
+ $eventHandler = $this->getMockBuilder(DummyHookListener::class)
+ ->onlyMethods(['callback'])
->getMock();
$eventHandler->expects($this->any())
@@ -763,7 +765,7 @@ class VersioningTest extends \Test\TestCase {
);
}
- private function doTestRestore() {
+ private function doTestRestore(): void {
$filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
$this->rootView->file_put_contents($filePath, 'test file');
@@ -941,11 +943,7 @@ class VersioningTest extends \Test\TestCase {
);
}
- /**
- * @param View $view
- * @param string $path
- */
- private function createAndCheckVersions(View $view, $path) {
+ private function createAndCheckVersions(View $view, string $path): array {
$view->file_put_contents($path, 'test file');
$view->file_put_contents($path, 'version 1');
$view->file_put_contents($path, 'version 2');
@@ -967,11 +965,7 @@ class VersioningTest extends \Test\TestCase {
return $versions;
}
- /**
- * @param string $user
- * @param bool $create
- */
- public static function loginHelper($user, $create = false) {
+ public static function loginHelper(string $user, bool $create = false) {
if ($create) {
$backend = new \Test\Util\User\Dummy();
$backend->createUser($user, $user);
@@ -987,6 +981,11 @@ class VersioningTest extends \Test\TestCase {
}
}
+class DummyHookListener {
+ public function callback() {
+ }
+}
+
// extend the original class to make it possible to test protected methods
class VersionStorageToTest extends Storage {
diff --git a/apps/files_versions/tests/Versions/VersionManagerTest.php b/apps/files_versions/tests/Versions/VersionManagerTest.php
index 8001d9fbf0e..79caa65d5f1 100644
--- a/apps/files_versions/tests/Versions/VersionManagerTest.php
+++ b/apps/files_versions/tests/Versions/VersionManagerTest.php
@@ -6,7 +6,7 @@ declare(strict_types=1);
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\files_versions\tests\Versions;
+namespace OCA\Files_Versions\Tests\Versions;
use OC\Files\Storage\Local;
use OCA\Files_Versions\Events\VersionRestoredEvent;
@@ -15,6 +15,7 @@ use OCA\Files_Versions\Versions\IVersionBackend;
use OCA\Files_Versions\Versions\VersionManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Storage\IStorage;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class VersionManagerTest extends TestCase {
@@ -25,10 +26,10 @@ class VersionManagerTest extends TestCase {
return $backend;
}
- private function getStorage(string $class): IStorage {
+ private function getStorage(string $class): IStorage&MockObject {
return $this->getMockBuilder($class)
->disableOriginalConstructor()
- ->setMethodsExcept(['instanceOfStorage'])
+ ->onlyMethods(array_diff(get_class_methods($class), ['instanceOfStorage']))
->getMock();
}