diff options
Diffstat (limited to 'apps/dav/tests/unit/Migration')
5 files changed, 74 insertions, 95 deletions
diff --git a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php index be2c64c47a4..1852d2709c1 100644 --- a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php +++ b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php @@ -1,15 +1,18 @@ <?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\Unit\DAV\Migration; +namespace OCA\DAV\Tests\unit\DAV\Migration; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Migration\CalDAVRemoveEmptyValue; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Server; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Sabre\VObject\InvalidDataException; use Test\TestCase; @@ -21,18 +24,10 @@ use Test\TestCase; * @group DB */ class CalDAVRemoveEmptyValueTest extends TestCase { - - /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $logger; - - /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */ - private $backend; - - /** @var IOutput|\PHPUnit\Framework\MockObject\MockObject */ - private $output; - - /** @var string */ - private $invalid = 'BEGIN:VCALENDAR + private LoggerInterface&MockObject $logger; + private CalDavBackend&MockObject $backend; + private IOutput&MockObject $output; + private string $invalid = 'BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Apple Inc.//Mac OS X 10.11.2//EN CALSCALE:GREGORIAN @@ -52,8 +47,7 @@ CREATED;VALUE=:20151214T091032Z END:VEVENT END:VCALENDAR'; - /** @var string */ - private $valid = 'BEGIN:VCALENDAR + private string $valid = 'BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Apple Inc.//Mac OS X 10.11.2//EN CALSCALE:GREGORIAN @@ -82,14 +76,14 @@ END:VCALENDAR'; } public function testRunAllValid(): void { - /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ + /** @var CalDAVRemoveEmptyValue&MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ Server::get(IDBConnection::class), $this->backend, $this->logger ]) - ->setMethods(['getInvalidObjects']) + ->onlyMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) @@ -106,14 +100,14 @@ END:VCALENDAR'; } public function testRunInvalid(): void { - /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ + /** @var CalDAVRemoveEmptyValue&MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ Server::get(IDBConnection::class), $this->backend, $this->logger ]) - ->setMethods(['getInvalidObjects']) + ->onlyMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) @@ -149,14 +143,14 @@ END:VCALENDAR'; } public function testRunValid(): void { - /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ + /** @var CalDAVRemoveEmptyValue&MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ Server::get(IDBConnection::class), $this->backend, $this->logger ]) - ->setMethods(['getInvalidObjects']) + ->onlyMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) @@ -191,14 +185,14 @@ END:VCALENDAR'; } public function testRunStillInvalid(): void { - /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ + /** @var CalDAVRemoveEmptyValue&MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ Server::get(IDBConnection::class), $this->backend, $this->logger ]) - ->setMethods(['getInvalidObjects']) + ->onlyMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) diff --git a/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php b/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php index bbecd0607b4..667d2e39d3a 100644 --- a/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php +++ b/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Unit\Migration; +namespace OCA\DAV\Tests\unit\Migration; use OCA\DAV\CardDAV\SyncService; use OCA\DAV\Migration\CreateSystemAddressBookStep; @@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase; class CreateSystemAddressBookStepTest extends TestCase { - private SyncService|MockObject $syncService; + private SyncService&MockObject $syncService; private CreateSystemAddressBookStep $step; protected function setUp(): void { diff --git a/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php b/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php index bf4c60b3cf1..8e7bf366cbf 100644 --- a/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php +++ b/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -12,17 +14,13 @@ use OCP\DB\IResult; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\Migration\IOutput; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RefreshWebcalJobRegistrarTest extends TestCase { - /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */ - private $db; - - /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */ - private $jobList; - - /** @var RefreshWebcalJobRegistrar */ - private $migration; + private IDBConnection&MockObject $db; + private IJobList&MockObject $jobList; + private RefreshWebcalJobRegistrar $migration; protected function setUp(): void { parent::setUp(); @@ -80,35 +78,37 @@ class RefreshWebcalJobRegistrarTest extends TestCase { $this->jobList->expects($this->exactly(3)) ->method('has') - ->withConsecutive( + ->willReturnMap([ [RefreshWebcalJob::class, [ 'principaluri' => 'foo1', 'uri' => 'bar1', - ]], + ], false], [RefreshWebcalJob::class, [ 'principaluri' => 'foo2', 'uri' => 'bar2', - ]], + ], true ], [RefreshWebcalJob::class, [ 'principaluri' => 'foo3', 'uri' => 'bar3', - ]]) - ->willReturnOnConsecutiveCalls( - false, - true, - false, - ); + ], false], + ]); + + $calls = [ + [RefreshWebcalJob::class, [ + 'principaluri' => 'foo1', + 'uri' => 'bar1', + ]], + [RefreshWebcalJob::class, [ + 'principaluri' => 'foo3', + 'uri' => 'bar3', + ]] + ]; $this->jobList->expects($this->exactly(2)) ->method('add') - ->withConsecutive( - [RefreshWebcalJob::class, [ - 'principaluri' => 'foo1', - 'uri' => 'bar1', - ]], - [RefreshWebcalJob::class, [ - 'principaluri' => 'foo3', - 'uri' => 'bar3', - ]]); + ->willReturnCallback(function () use (&$calls): void { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $output->expects($this->once()) ->method('info') diff --git a/apps/dav/tests/unit/Migration/RegenerateBirthdayCalendarsTest.php b/apps/dav/tests/unit/Migration/RegenerateBirthdayCalendarsTest.php index e2ac45526d2..6f681badb8b 100644 --- a/apps/dav/tests/unit/Migration/RegenerateBirthdayCalendarsTest.php +++ b/apps/dav/tests/unit/Migration/RegenerateBirthdayCalendarsTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -10,18 +12,13 @@ use OCA\DAV\Migration\RegenerateBirthdayCalendars; use OCP\BackgroundJob\IJobList; use OCP\IConfig; use OCP\Migration\IOutput; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RegenerateBirthdayCalendarsTest extends TestCase { - - /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */ - private $jobList; - - /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ - private $config; - - /** @var RegenerateBirthdayCalendars */ - private $migration; + private IJobList&MockObject $jobList; + private IConfig&MockObject $config; + private RegenerateBirthdayCalendars $migration; protected function setUp(): void { parent::setUp(); diff --git a/apps/dav/tests/unit/Migration/RemoveDeletedUsersCalendarSubscriptionsTest.php b/apps/dav/tests/unit/Migration/RemoveDeletedUsersCalendarSubscriptionsTest.php index a3daf1c918a..a9758470573 100644 --- a/apps/dav/tests/unit/Migration/RemoveDeletedUsersCalendarSubscriptionsTest.php +++ b/apps/dav/tests/unit/Migration/RemoveDeletedUsersCalendarSubscriptionsTest.php @@ -22,23 +22,10 @@ use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RemoveDeletedUsersCalendarSubscriptionsTest extends TestCase { - /** - * @var IDBConnection|MockObject - */ - private $dbConnection; - /** - * @var IUserManager|MockObject - */ - private $userManager; - - /** - * @var IOutput|MockObject - */ - private $output; - /** - * @var RemoveDeletedUsersCalendarSubscriptions - */ - private $migration; + private IDBConnection&MockObject $dbConnection; + private IUserManager&MockObject $userManager; + private IOutput&MockObject $output; + private RemoveDeletedUsersCalendarSubscriptions $migration; protected function setUp(): void { @@ -58,13 +45,7 @@ class RemoveDeletedUsersCalendarSubscriptionsTest extends TestCase { ); } - /** - * @dataProvider dataTestRun - * @param array $subscriptions - * @param array $userExists - * @param int $deletions - * @throws \Exception - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')] public function testRun(array $subscriptions, array $userExists, int $deletions): void { $qb = $this->createMock(IQueryBuilder::class); @@ -132,21 +113,28 @@ class RemoveDeletedUsersCalendarSubscriptionsTest extends TestCase { $this->migration->run($this->output); } - public function dataTestRun(): array { + public static function dataTestRun(): array { return [ [[], [], 0], - [[[ - 'id' => 1, - 'principaluri' => 'users/principals/foo1', - ], + [ [ - 'id' => 2, - 'principaluri' => 'users/principals/bar1', + [ + 'id' => 1, + 'principaluri' => 'users/principals/foo1', + ], + [ + 'id' => 2, + 'principaluri' => 'users/principals/bar1', + ], + [ + 'id' => 3, + 'principaluri' => 'users/principals/bar1', + ], + [], ], - [ - 'id' => 3, - 'principaluri' => 'users/principals/bar1', - ]], ['foo1' => true, 'bar1' => false], 2] + ['foo1' => true, 'bar1' => false], + 2 + ], ]; } } |