diff options
Diffstat (limited to 'apps/files_versions/tests/Command')
-rw-r--r-- | apps/files_versions/tests/Command/CleanupTest.php | 136 | ||||
-rw-r--r-- | apps/files_versions/tests/Command/ExpireTest.php | 30 |
2 files changed, 70 insertions, 96 deletions
diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php index 289c7123c24..dd6665f5aef 100644 --- a/apps/files_versions/tests/Command/CleanupTest.php +++ b/apps/files_versions/tests/Command/CleanupTest.php @@ -1,35 +1,23 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - - namespace OCA\Files_Versions\Tests\Command; - -use OCA\Files_Versions\Command\CleanUp; -use Test\TestCase; 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; /** * Class CleanupTest @@ -39,41 +27,48 @@ use OCP\Files\IRootFolder; * @package OCA\Files_Versions\Tests\Command */ class CleanupTest extends TestCase { + protected Manager&MockObject $userManager; + protected IRootFolder&MockObject $rootFolder; + protected VersionsMapper&MockObject $versionMapper; + protected CleanUp $cleanup; - /** @var CleanUp */ - protected $cleanup; - - /** @var \PHPUnit_Framework_MockObject_MockObject | Manager */ - protected $userManager; - - /** @var \PHPUnit_Framework_MockObject_MockObject | IRootFolder */ - protected $rootFolder; - - public function setUp() { + 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->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->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->versionMapper); } /** - * @dataProvider dataTestDeleteVersions * @param boolean $nodeExists */ - public function testDeleteVersions($nodeExists) { - + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestDeleteVersions')] + public function testDeleteVersions(bool $nodeExists): void { $this->rootFolder->expects($this->once()) ->method('nodeExists') ->with('/testUser/files_versions') ->willReturn($nodeExists); - - if($nodeExists) { + $userFolder = $this->createMock(Folder::class); + $userHomeStorage = $this->createMock(IStorage::class); + $userHomeStorageCache = $this->createMock(ICache::class); + $this->rootFolder->expects($this->once()) + ->method('getUserFolder') + ->willReturn($userFolder); + $userFolder->expects($this->once()) + ->method('getStorage') + ->willReturn($userHomeStorage); + $userHomeStorage->expects($this->once()) + ->method('getCache') + ->willReturn($userHomeStorageCache); + $userHomeStorageCache->expects($this->once()) + ->method('getNumericStorageId') + ->willReturn(1); + + if ($nodeExists) { $this->rootFolder->expects($this->once()) ->method('get') ->with('/testUser/files_versions') @@ -90,41 +85,39 @@ class CleanupTest extends TestCase { $this->invokePrivate($this->cleanup, 'deleteVersions', ['testUser']); } - public function dataTestDeleteVersions() { - return array( - array(true), - array(false) - ); + public static function dataTestDeleteVersions(): array { + return [ + [true], + [false] + ]; } /** * test delete versions from users given as parameter */ - public function testExecuteDeleteListOfUsers() { + public function testExecuteDeleteListOfUsers(): void { $userIds = ['user1', 'user2', 'user3']; - $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp') - ->setMethods(['deleteVersions']) - ->setConstructorArgs([$this->rootFolder, $this->userManager]) + $instance = $this->getMockBuilder(CleanUp::class) + ->onlyMethods(['deleteVersions']) + ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper]) ->getMock(); $instance->expects($this->exactly(count($userIds))) ->method('deleteVersions') - ->willReturnCallback(function ($user) use ($userIds) { + ->willReturnCallback(function ($user) use ($userIds): void { $this->assertTrue(in_array($user, $userIds)); }); $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]); } @@ -132,16 +125,16 @@ class CleanupTest extends TestCase { /** * test delete versions of all users */ - public function testExecuteAllUsers() { + public function testExecuteAllUsers(): void { $userIds = []; $backendUsers = ['user1', 'user2']; - $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp') - ->setMethods(['deleteVersions']) - ->setConstructorArgs([$this->rootFolder, $this->userManager]) + $instance = $this->getMockBuilder(CleanUp::class) + ->onlyMethods(['deleteVersions']) + ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper]) ->getMock(); - $backend = $this->getMockBuilder(\OCP\UserInterface::class) + $backend = $this->getMockBuilder(UserInterface::class) ->disableOriginalConstructor()->getMock(); $backend->expects($this->once())->method('getUsers') ->with('', 500, 0) @@ -149,24 +142,21 @@ class CleanupTest extends TestCase { $instance->expects($this->exactly(count($backendUsers))) ->method('deleteVersions') - ->willReturnCallback(function ($user) use ($backendUsers) { + ->willReturnCallback(function ($user) use ($backendUsers): void { $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') - ->willReturn([$backend]); + ->method('getBackends') + ->willReturn([$backend]); $this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]); } - } diff --git a/apps/files_versions/tests/Command/ExpireTest.php b/apps/files_versions/tests/Command/ExpireTest.php index 3815bc5b75e..b74457a7fd6 100644 --- a/apps/files_versions/tests/Command/ExpireTest.php +++ b/apps/files_versions/tests/Command/ExpireTest.php @@ -1,27 +1,11 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_Versions\Tests\Command; use OCA\Files_Versions\Command\Expire; @@ -35,10 +19,10 @@ use Test\TestCase; * @package OCA\Files_Versions\Tests\Command */ class ExpireTest extends TestCase { - public function testExpireNonExistingUser() { + public function testExpireNonExistingUser(): void { $command = new Expire($this->getUniqueID('test'), ''); $command->handle(); - $this->assertTrue(true); + $this->addToAssertionCount(1); } } |