diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Command/Config/App/DeleteConfigTest.php | 58 | ||||
-rw-r--r-- | tests/Core/Command/Config/App/GetConfigTest.php | 61 | ||||
-rw-r--r-- | tests/Core/Command/Config/App/SetConfigTest.php | 64 | ||||
-rw-r--r-- | tests/lib/Preview/BackgroundCleanupJobTest.php | 43 | ||||
-rw-r--r-- | tests/lib/Preview/Provider.php | 33 |
5 files changed, 98 insertions, 161 deletions
diff --git a/tests/Core/Command/Config/App/DeleteConfigTest.php b/tests/Core/Command/Config/App/DeleteConfigTest.php index ebbbb15e1b6..1e44c2aafe6 100644 --- a/tests/Core/Command/Config/App/DeleteConfigTest.php +++ b/tests/Core/Command/Config/App/DeleteConfigTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,37 +10,31 @@ namespace Tests\Core\Command\Config\App; use OC\Core\Command\Config\App\DeleteConfig; -use OCP\IConfig; +use OCP\IAppConfig; +use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class DeleteConfigTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ - protected $config; - - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleInput; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; + protected IAppConfig&MockObject $appConfig; + protected InputInterface&MockObject $consoleInput; + protected OutputInterface&MockObject $consoleOutput; + protected Command $command; protected function setUp(): void { parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->consoleInput = $this->createMock(InputInterface::class); + $this->consoleOutput = $this->createMock(OutputInterface::class); - $this->command = new DeleteConfig($this->config); + $this->command = new DeleteConfig($this->appConfig); } - public function deleteData() { + public static function dataDelete(): array { return [ [ 'name', @@ -72,22 +68,16 @@ class DeleteConfigTest extends TestCase { } /** - * @dataProvider deleteData - * - * @param string $configName - * @param bool $configExists - * @param bool $checkIfExists - * @param int $expectedReturn - * @param string $expectedMessage + * @dataProvider dataDelete */ - public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage): void { - $this->config->expects(($checkIfExists) ? $this->once() : $this->never()) - ->method('getAppKeys') + public function testDelete(string $configName, bool $configExists, bool $checkIfExists, int $expectedReturn, string $expectedMessage): void { + $this->appConfig->expects(($checkIfExists) ? $this->once() : $this->never()) + ->method('getKeys') ->with('app-name') ->willReturn($configExists ? [$configName] : []); - $this->config->expects(($expectedReturn === 0) ? $this->once() : $this->never()) - ->method('deleteAppValue') + $this->appConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) + ->method('deleteKey') ->with('app-name', $configName); $this->consoleInput->expects($this->exactly(2)) @@ -96,15 +86,13 @@ class DeleteConfigTest extends TestCase { ['app', 'app-name'], ['name', $configName], ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') + $this->consoleInput->method('hasParameterOption') ->with('--error-if-not-exists') ->willReturn($checkIfExists); - $this->consoleOutput->expects($this->any()) - ->method('writeln') + $this->consoleOutput->method('writeln') ->with($this->stringContains($expectedMessage)); - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); + $this->assertSame($expectedReturn, self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); } } diff --git a/tests/Core/Command/Config/App/GetConfigTest.php b/tests/Core/Command/Config/App/GetConfigTest.php index c1a6265db40..89a75c0b527 100644 --- a/tests/Core/Command/Config/App/GetConfigTest.php +++ b/tests/Core/Command/Config/App/GetConfigTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,40 +9,33 @@ namespace Tests\Core\Command\Config\App; -use OC\AppConfig; use OC\Core\Command\Config\App\GetConfig; use OCP\Exceptions\AppConfigUnknownKeyException; +use OCP\IAppConfig; +use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class GetConfigTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $config; - - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleInput; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; + protected IAppConfig&MockObject $appConfig; + protected InputInterface&MockObject $consoleInput; + protected OutputInterface&MockObject $consoleOutput; + protected Command $command; protected function setUp(): void { parent::setUp(); - $config = $this->config = $this->getMockBuilder(AppConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->consoleInput = $this->createMock(InputInterface::class); + $this->consoleOutput = $this->createMock(OutputInterface::class); - /** @var \OCP\IAppConfig $config */ - $this->command = new GetConfig($config); + $this->command = new GetConfig($this->appConfig); } - public function getData() { + public static function dataGet(): array { return [ // String output as json ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], @@ -83,21 +78,12 @@ class GetConfigTest extends TestCase { } /** - * @dataProvider getData - * - * @param string $configName - * @param mixed $value - * @param bool $configExists - * @param mixed $defaultValue - * @param bool $hasDefault - * @param string $outputFormat - * @param int $expectedReturn - * @param string $expectedMessage + * @dataProvider dataGet */ - public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage): void { + public function testGet(string $configName, mixed $value, bool $configExists, mixed $defaultValue, bool $hasDefault, string $outputFormat, int $expectedReturn, ?string $expectedMessage): void { if (!$expectedReturn) { if ($configExists) { - $this->config->expects($this->once()) + $this->appConfig->expects($this->once()) ->method('getDetails') ->with('app-name', $configName) ->willReturn(['value' => $value]); @@ -105,7 +91,7 @@ class GetConfigTest extends TestCase { } if (!$configExists) { - $this->config->expects($this->once()) + $this->appConfig->expects($this->once()) ->method('getDetails') ->with('app-name', $configName) ->willThrowException(new AppConfigUnknownKeyException()); @@ -117,14 +103,12 @@ class GetConfigTest extends TestCase { ['app', 'app-name'], ['name', $configName], ]); - $this->consoleInput->expects($this->any()) - ->method('getOption') + $this->consoleInput->method('getOption') ->willReturnMap([ ['default-value', $defaultValue], ['output', $outputFormat], ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') + $this->consoleInput->method('hasParameterOption') ->willReturnMap([ ['--output', false, true], ['--default-value', false, $hasDefault], @@ -134,8 +118,7 @@ class GetConfigTest extends TestCase { global $output; $output = ''; - $this->consoleOutput->expects($this->any()) - ->method('writeln') + $this->consoleOutput->method('writeln') ->willReturnCallback(function ($value) { global $output; $output .= $value . "\n"; @@ -143,7 +126,7 @@ class GetConfigTest extends TestCase { }); } - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); + $this->assertSame($expectedReturn, self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); if ($expectedMessage !== null) { global $output; diff --git a/tests/Core/Command/Config/App/SetConfigTest.php b/tests/Core/Command/Config/App/SetConfigTest.php index 1d599bf3234..099471228b4 100644 --- a/tests/Core/Command/Config/App/SetConfigTest.php +++ b/tests/Core/Command/Config/App/SetConfigTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -11,37 +13,30 @@ use OC\AppConfig; use OC\Core\Command\Config\App\SetConfig; use OCP\Exceptions\AppConfigUnknownKeyException; use OCP\IAppConfig; +use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class SetConfigTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $config; - - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleInput; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; + protected IAppConfig&MockObject $appConfig; + protected InputInterface&MockObject $consoleInput; + protected OutputInterface&MockObject $consoleOutput; + protected Command $command; protected function setUp(): void { parent::setUp(); - $config = $this->config = $this->getMockBuilder(AppConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + $this->appConfig = $this->createMock(AppConfig::class); + $this->consoleInput = $this->createMock(InputInterface::class); + $this->consoleOutput = $this->createMock(OutputInterface::class); - /** @var \OCP\IAppConfig $config */ - $this->command = new SetConfig($config); + $this->command = new SetConfig($this->appConfig); } - public function setData() { + public static function dataSet(): array { return [ [ 'name', @@ -63,33 +58,23 @@ class SetConfigTest extends TestCase { } /** - * @dataProvider setData - * - * @param string $configName - * @param mixed $newValue - * @param bool $configExists - * @param bool $updateOnly - * @param bool $updated - * @param string $expectedMessage + * @dataProvider dataSet */ - public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage): void { - $this->config->expects($this->any()) - ->method('hasKey') + public function testSet(string $configName, mixed $newValue, bool $configExists, bool $updateOnly, bool $updated, string $expectedMessage): void { + $this->appConfig->method('hasKey') ->with('app-name', $configName) ->willReturn($configExists); if (!$configExists) { - $this->config->expects($this->any()) - ->method('getValueType') + $this->appConfig->method('getValueType') ->willThrowException(new AppConfigUnknownKeyException()); } else { - $this->config->expects($this->any()) - ->method('getValueType') + $this->appConfig->method('getValueType') ->willReturn(IAppConfig::VALUE_MIXED); } if ($updated) { - $this->config->expects($this->once()) + $this->appConfig->expects($this->once()) ->method('setValueMixed') ->with('app-name', $configName, $newValue); } @@ -100,25 +85,22 @@ class SetConfigTest extends TestCase { ['app', 'app-name'], ['name', $configName], ]); - $this->consoleInput->expects($this->any()) - ->method('getOption') + $this->consoleInput->method('getOption') ->willReturnMap([ ['value', $newValue], ['lazy', null], ['sensitive', null], ['no-interaction', true], ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') + $this->consoleInput->method('hasParameterOption') ->willReturnMap([ ['--type', false, false], ['--value', false, true], ['--update-only', false, $updateOnly] ]); - $this->consoleOutput->expects($this->any()) - ->method('writeln') + $this->consoleOutput->method('writeln') ->with($this->stringContains($expectedMessage)); - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } } diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php index 945366cde9f..cecb4a7a212 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only @@ -9,12 +10,15 @@ namespace Test\Preview; use OC\Preview\BackgroundCleanupJob; use OC\Preview\Storage\Root; use OC\PreviewManager; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\File; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IDBConnection; +use OCP\IPreview; +use OCP\Server; use Test\Traits\MountProviderTrait; use Test\Traits\UserTrait; @@ -28,25 +32,12 @@ use Test\Traits\UserTrait; class BackgroundCleanupJobTest extends \Test\TestCase { use MountProviderTrait; use UserTrait; - - /** @var string */ - private $userId; - - /** @var bool */ - private $trashEnabled; - - /** @var IDBConnection */ - private $connection; - - /** @var PreviewManager */ - private $previewManager; - - /** @var IRootFolder */ - private $rootFolder; - - /** @var IMimeTypeLoader */ - private $mimeTypeLoader; - + private string $userId; + private bool $trashEnabled; + private IDBConnection $connection; + private PreviewManager $previewManager; + private IRootFolder $rootFolder; + private IMimeTypeLoader $mimeTypeLoader; private ITimeFactory $timeFactory; protected function setUp(): void { @@ -62,20 +53,20 @@ class BackgroundCleanupJobTest extends \Test\TestCase { $this->logout(); $this->loginAsUser($this->userId); - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); $appManager->disableApp('files_trashbin'); - $this->connection = \OC::$server->getDatabaseConnection(); - $this->previewManager = \OC::$server->getPreviewManager(); - $this->rootFolder = \OC::$server->get(IRootFolder::class); - $this->mimeTypeLoader = \OC::$server->getMimeTypeLoader(); - $this->timeFactory = \OCP\Server::get(ITimeFactory::class); + $this->connection = Server::get(IDBConnection::class); + $this->previewManager = Server::get(IPreview::class); + $this->rootFolder = Server::get(IRootFolder::class); + $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); + $this->timeFactory = Server::get(ITimeFactory::class); } protected function tearDown(): void { if ($this->trashEnabled) { - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); $appManager->enableApp('files_trashbin'); } diff --git a/tests/lib/Preview/Provider.php b/tests/lib/Preview/Provider.php index 41a2a4ca3c4..a7f55151354 100644 --- a/tests/lib/Preview/Provider.php +++ b/tests/lib/Preview/Provider.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,33 +10,25 @@ namespace Test\Preview; use OC\Files\Node\File; use OCP\Files\IRootFolder; +use OCP\IUserManager; abstract class Provider extends \Test\TestCase { - /** @var string */ - protected $imgPath; - /** @var int */ - protected $width; - /** @var int */ - protected $height; - /** @var \OC\Preview\Provider */ + protected string $imgPath; + protected int $width; + protected int $height; + /** @var \OC\Preview\Provider|mixed $provider */ protected $provider; - /** @var int */ - protected $maxWidth = 1024; - /** @var int */ - protected $maxHeight = 1024; - /** @var bool */ - protected $scalingUp = false; - /** @var int */ - protected $userId; - /** @var \OC\Files\View */ - protected $rootView; - /** @var \OC\Files\Storage\Storage */ - protected $storage; + protected int $maxWidth = 1024; + protected int $maxHeight = 1024; + protected bool $scalingUp = false; + protected string $userId; + protected \OC\Files\View $rootView; + protected \OC\Files\Storage\Storage $storage; protected function setUp(): void { parent::setUp(); - $userManager = \OC::$server->getUserManager(); + $userManager = \OCP\Server::get(IUserManager::class); $userManager->clearBackends(); $backend = new \Test\Util\User\Dummy(); $userManager->registerBackend($backend); |