diff options
Diffstat (limited to 'apps/dav/tests/unit/Command')
6 files changed, 105 insertions, 168 deletions
diff --git a/apps/dav/tests/unit/Command/DeleteCalendarTest.php b/apps/dav/tests/unit/Command/DeleteCalendarTest.php index b621e6737d5..2bd269de6dc 100644 --- a/apps/dav/tests/unit/Command/DeleteCalendarTest.php +++ b/apps/dav/tests/unit/Command/DeleteCalendarTest.php @@ -6,7 +6,7 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Command; +namespace OCA\DAV\Tests\unit\Command; use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\CalDavBackend; @@ -28,23 +28,12 @@ class DeleteCalendarTest extends TestCase { public const USER = 'user'; public const NAME = 'calendar'; - /** @var CalDavBackend|MockObject */ - private $calDav; - - /** @var IConfig|MockObject */ - private $config; - - /** @var IL10N|MockObject */ - private $l10n; - - /** @var IUserManager|MockObject */ - private $userManager; - - /** @var DeleteCalendar */ - private $command; - - /** @var MockObject|LoggerInterface */ - private $logger; + private CalDavBackend&MockObject $calDav; + private IConfig&MockObject $config; + private IL10N&MockObject $l10n; + private IUserManager&MockObject $userManager; + private LoggerInterface&MockObject $logger; + private DeleteCalendar $command; protected function setUp(): void { parent::setUp(); diff --git a/apps/dav/tests/unit/Command/ListAddressbooksTest.php b/apps/dav/tests/unit/Command/ListAddressbooksTest.php index 2c6b1579042..624b0050bc5 100644 --- a/apps/dav/tests/unit/Command/ListAddressbooksTest.php +++ b/apps/dav/tests/unit/Command/ListAddressbooksTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Command; +namespace OCA\DAV\Tests\unit\Command; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Command\ListAddressbooks; @@ -20,9 +20,8 @@ use Test\TestCase; * @package OCA\DAV\Tests\Command */ class ListAddressbooksTest extends TestCase { - - private IUserManager|MockObject $userManager; - private CardDavBackend|MockObject $cardDavBackend; + private IUserManager&MockObject $userManager; + private CardDavBackend&MockObject $cardDavBackend; private ListAddressbooks $command; public const USERNAME = 'username'; @@ -72,7 +71,7 @@ class ListAddressbooksTest extends TestCase { $this->assertStringContainsString('User <' . self::USERNAME . "> has no addressbooks\n", $commandTester->getDisplay()); } - public function dataExecute() { + public static function dataExecute(): array { return [ [false, '✓'], [true, 'x'] diff --git a/apps/dav/tests/unit/Command/ListCalendarSharesTest.php b/apps/dav/tests/unit/Command/ListCalendarSharesTest.php index 3b3f3a1519e..e5d4251cbf9 100644 --- a/apps/dav/tests/unit/Command/ListCalendarSharesTest.php +++ b/apps/dav/tests/unit/Command/ListCalendarSharesTest.php @@ -6,7 +6,7 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Command; +namespace OCA\DAV\Tests\unit\Command; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Command\ListCalendarShares; diff --git a/apps/dav/tests/unit/Command/ListCalendarsTest.php b/apps/dav/tests/unit/Command/ListCalendarsTest.php index 1f5f9882ac4..247487433eb 100644 --- a/apps/dav/tests/unit/Command/ListCalendarsTest.php +++ b/apps/dav/tests/unit/Command/ListCalendarsTest.php @@ -1,14 +1,17 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Command; +namespace OCA\DAV\Tests\unit\Command; use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Command\ListCalendars; use OCP\IUserManager; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Tester\CommandTester; use Test\TestCase; @@ -18,15 +21,9 @@ use Test\TestCase; * @package OCA\DAV\Tests\Command */ class ListCalendarsTest extends TestCase { - - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */ - private $userManager; - - /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */ - private $calDav; - - /** @var ListCalendars */ - private $command; + private IUserManager&MockObject $userManager; + private CalDavBackend&MockObject $calDav; + private ListCalendars $command; public const USERNAME = 'username'; @@ -75,7 +72,7 @@ class ListCalendarsTest extends TestCase { $this->assertStringContainsString('User <' . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay()); } - public function dataExecute() { + public static function dataExecute(): array { return [ [false, '✓'], [true, 'x'] diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php index 9b935ca3cdb..c481f5cf15b 100644 --- a/apps/dav/tests/unit/Command/MoveCalendarTest.php +++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php @@ -1,9 +1,11 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Command; +namespace OCA\DAV\Tests\unit\Command; use InvalidArgumentException; use OCA\DAV\CalDAV\CalDavBackend; @@ -24,29 +26,14 @@ use Test\TestCase; * @package OCA\DAV\Tests\Command */ class MoveCalendarTest extends TestCase { - /** @var IUserManager|MockObject $userManager */ - private $userManager; - - /** @var IGroupManager|MockObject $groupManager */ - private $groupManager; - - /** @var \OCP\Share\IManager|MockObject $shareManager */ - private $shareManager; - - /** @var IConfig|MockObject $l10n */ - private $config; - - /** @var IL10N|MockObject $l10n */ - private $l10n; - - /** @var CalDavBackend|MockObject $l10n */ - private $calDav; - - /** @var MoveCalendar */ - private $command; - - /** @var LoggerInterface|MockObject */ - private $logger; + private IUserManager&MockObject $userManager; + private IGroupManager&MockObject $groupManager; + private \OCP\Share\IManager&MockObject $shareManager; + private IConfig&MockObject $config; + private IL10N&MockObject $l10n; + private CalDavBackend&MockObject $calDav; + private LoggerInterface&MockObject $logger; + private MoveCalendar $command; protected function setUp(): void { parent::setUp(); @@ -70,7 +57,7 @@ class MoveCalendarTest extends TestCase { ); } - public function dataExecute() { + public static function dataExecute(): array { return [ [false, true], [true, false] @@ -79,23 +66,16 @@ class MoveCalendarTest extends TestCase { /** * @dataProvider dataExecute - * - * @param $userOriginExists - * @param $userDestinationExists */ - public function testWithBadUserOrigin($userOriginExists, $userDestinationExists): void { + public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void { $this->expectException(\InvalidArgumentException::class); $this->userManager->expects($this->exactly($userOriginExists ? 2 : 1)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturnOnConsecutiveCalls( - $userOriginExists, - $userDestinationExists, - ); + ->willReturnMap([ + ['user', $userOriginExists], + ['user2', $userDestinationExists], + ]); $commandTester = new CommandTester($this->command); $commandTester->execute([ @@ -112,11 +92,10 @@ class MoveCalendarTest extends TestCase { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->once())->method('getCalendarByUri') ->with('principals/users/user', 'personal') @@ -137,20 +116,20 @@ class MoveCalendarTest extends TestCase { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturn([ - 'id' => 1234, + ->willReturnMap([ + ['principals/users/user', 'personal', [ + 'id' => 1234, + ]], + ['principals/users/user2', 'personal', [ + 'id' => 1234, + ]], ]); $commandTester = new CommandTester($this->command); @@ -164,24 +143,19 @@ class MoveCalendarTest extends TestCase { public function testMove(): void { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturnOnConsecutiveCalls( - [ + ->willReturnMap([ + ['principals/users/user', 'personal', [ 'id' => 1234, - ], - null, - ); + ]], + ['principals/users/user2', 'personal', null], + ]); $this->calDav->expects($this->once())->method('getShares') ->with(1234) @@ -197,7 +171,7 @@ class MoveCalendarTest extends TestCase { $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay()); } - public function dataTestMoveWithDestinationNotPartOfGroup(): array { + public static function dataTestMoveWithDestinationNotPartOfGroup(): array { return [ [true], [false] @@ -210,25 +184,20 @@ class MoveCalendarTest extends TestCase { public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturnOnConsecutiveCalls( - [ + ->willReturnMap([ + ['principals/users/user', 'personal', [ 'id' => 1234, 'uri' => 'personal', - ], - null, - ); + ]], + ['principals/users/user2', 'personal', null], + ]); $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') ->willReturn($shareWithGroupMembersOnly); @@ -254,25 +223,20 @@ class MoveCalendarTest extends TestCase { public function testMoveWithDestinationPartOfGroup(): void { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturnOnConsecutiveCalls( - [ + ->willReturnMap([ + ['principals/users/user', 'personal', [ 'id' => 1234, 'uri' => 'personal', - ], - null, - ); + ]], + ['principals/users/user2', 'personal', null], + ]); $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') ->willReturn(true); @@ -300,26 +264,21 @@ class MoveCalendarTest extends TestCase { public function testMoveWithDestinationNotPartOfGroupAndForce(): void { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturnOnConsecutiveCalls( - [ + ->willReturnMap([ + ['principals/users/user', 'personal', [ 'id' => 1234, 'uri' => 'personal', '{DAV:}displayname' => 'Personal' - ], - null, - ); + ]], + ['principals/users/user2', 'personal', null], + ]); $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') ->willReturn(true); @@ -345,7 +304,7 @@ class MoveCalendarTest extends TestCase { $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay()); } - public function dataTestMoveWithCalendarAlreadySharedToDestination(): array { + public static function dataTestMoveWithCalendarAlreadySharedToDestination(): array { return [ [true], [false] @@ -358,26 +317,21 @@ class MoveCalendarTest extends TestCase { public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void { $this->userManager->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive( - ['user'], - ['user2'], - ) - ->willReturn(true); + ->willReturnMap([ + ['user', true], + ['user2', true], + ]); $this->calDav->expects($this->exactly(2)) ->method('getCalendarByUri') - ->withConsecutive( - ['principals/users/user', 'personal'], - ['principals/users/user2', 'personal'], - ) - ->willReturnOnConsecutiveCalls( - [ + ->willReturnMap([ + ['principals/users/user', 'personal', [ 'id' => 1234, 'uri' => 'personal', '{DAV:}displayname' => 'Personal' - ], - null, - ); + ]], + ['principals/users/user2', 'personal', null], + ]); $this->calDav->expects($this->once())->method('getShares') ->with(1234) diff --git a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php index f2346c211ce..ec56aa64eb2 100644 --- a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php +++ b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php @@ -1,16 +1,16 @@ <?php +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2018 ownCloud GmbH * SPDX-License-Identifier: AGPL-3.0-only */ -namespace OCA\DAV\Tests\Unit\Command; +namespace OCA\DAV\Tests\unit\Command; use OCA\DAV\Command\RemoveInvalidShares; use OCA\DAV\Connector\Sabre\Principal; use OCP\IDBConnection; -use OCP\Migration\IOutput; use OCP\Server; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -37,18 +37,16 @@ class RemoveInvalidSharesTest extends TestCase { public function test(): void { $db = Server::get(IDBConnection::class); - /** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */ $principal = $this->createMock(Principal::class); - /** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */ - $output = $this->createMock(IOutput::class); - $repair = new RemoveInvalidShares($db, $principal); $this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]); $query = $db->getQueryBuilder(); - $result = $query->select('*')->from('dav_shares') - ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute(); + $query->select('*') + ->from('dav_shares') + ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown'))); + $result = $query->executeQuery(); $data = $result->fetchAll(); $result->closeCursor(); $this->assertEquals(0, count($data)); |