diff options
Diffstat (limited to 'tests/Core/Command/Preview/RepairTest.php')
-rw-r--r-- | tests/Core/Command/Preview/RepairTest.php | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/tests/Core/Command/Preview/RepairTest.php b/tests/Core/Command/Preview/RepairTest.php index 68f32c1f498..9b9cde6dd95 100644 --- a/tests/Core/Command/Preview/RepairTest.php +++ b/tests/Core/Command/Preview/RepairTest.php @@ -1,5 +1,9 @@ <?php +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ namespace Tests\Core\Command\Preview; use bantu\IniGetWrapper\IniGetWrapper; @@ -8,10 +12,12 @@ use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\IConfig; -use OCP\ILogger; +use OCP\Lock\ILockingProvider; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; @@ -20,7 +26,7 @@ class RepairTest extends TestCase { private $config; /** @var IRootFolder|MockObject */ private $rootFolder; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var IniGetWrapper|MockObject */ private $iniGetWrapper; @@ -39,13 +45,18 @@ class RepairTest extends TestCase { ->getMock(); $this->rootFolder = $this->getMockBuilder(IRootFolder::class) ->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class) + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->getMock(); $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class) ->getMock(); - $this->repair = new Repair($this->config, $this->rootFolder, $this->logger, $this->iniGetWrapper); - $this->input = $this->getMockBuilder(InputInterface::class) - ->getMock(); + $this->repair = new Repair( + $this->config, + $this->rootFolder, + $this->logger, + $this->iniGetWrapper, + $this->createMock(ILockingProvider::class) + ); + $this->input = $this->createMock(InputInterface::class); $this->input->expects($this->any()) ->method('getOption') ->willReturnCallback(function ($parameter) { @@ -54,24 +65,27 @@ class RepairTest extends TestCase { } return null; }); - $this->output = $this->getMockBuilder(OutputInterface::class) - ->setMethods(['section', 'writeln', 'write', 'setVerbosity', 'getVerbosity', 'isQuiet', 'isVerbose', 'isVeryVerbose', 'isDebug', 'setDecorated', 'isDecorated', 'setFormatter', 'getFormatter']) + $this->output = $this->getMockBuilder(ConsoleOutput::class) + ->onlyMethods(['section', 'writeln', 'getFormatter']) ->getMock(); $self = $this; - $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('isDecorated')->willReturn(false); + $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) { + ->willReturnCallback(function ($line) use ($self): void { $self->outputLines .= $line . "\n"; }); } - public function emptyTestDataProvider() { + public static function dataEmptyTest(): array { /** directoryNames, expectedOutput */ return [ [ @@ -97,10 +111,8 @@ class RepairTest extends TestCase { ]; } - /** - * @dataProvider emptyTestDataProvider - */ - public function testEmptyExecute($directoryNames, $expectedOutput) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataEmptyTest')] + public function testEmptyExecute($directoryNames, $expectedOutput): void { $previewFolder = $this->getMockBuilder(Folder::class) ->getMock(); $directories = array_map(function ($element) { @@ -129,9 +141,9 @@ class RepairTest extends TestCase { $previewFolder->expects($this->once()) ->method('getDirectoryListing') ->willReturn($directories); - $this->rootFolder->expects($this->at(0)) + $this->rootFolder->expects($this->once()) ->method('get') - ->with("appdata_/preview") + ->with('appdata_/preview') ->willReturn($previewFolder); $this->repair->run($this->input, $this->output); |