Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/dav/tests/unit/AppInfo/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/tests/unit/AppInfo/PluginManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
* SPDX-License-Identifier: AGPL-3.0-only
Expand Down
18 changes: 8 additions & 10 deletions apps/dav/tests/unit/Avatars/AvatarHomeTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
Expand All @@ -11,17 +12,14 @@
use OCA\DAV\Avatars\AvatarNode;
use OCP\IAvatar;
use OCP\IAvatarManager;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
use Test\TestCase;

class AvatarHomeTest extends TestCase {

/** @var AvatarHome */
private $home;

/** @var IAvatarManager | \PHPUnit\Framework\MockObject\MockObject */
private $avatarManager;
private AvatarHome $home;
private IAvatarManager&MockObject $avatarManager;

protected function setUp(): void {
parent::setUp();
Expand All @@ -38,7 +36,7 @@ public function testForbiddenMethods($method): void {
$this->home->$method('');
}

public function providesForbiddenMethods() {
public static function providesForbiddenMethods(): array {
return [
['createFile'],
['createDirectory'],
Expand All @@ -52,7 +50,7 @@ public function testGetName(): void {
self::assertEquals('admin', $n);
}

public function providesTestGetChild() {
public static function providesTestGetChild(): array {
return [
[MethodNotAllowed::class, false, ''],
[MethodNotAllowed::class, false, 'bla.foo'],
Expand All @@ -65,7 +63,7 @@ public function providesTestGetChild() {
/**
* @dataProvider providesTestGetChild
*/
public function testGetChild($expectedException, $hasAvatar, $path): void {
public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void {
if ($expectedException !== null) {
$this->expectException($expectedException);
}
Expand All @@ -92,7 +90,7 @@ public function testGetChildren(): void {
/**
* @dataProvider providesTestGetChild
*/
public function testChildExists($expectedException, $hasAvatar, $path): void {
public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void {
$avatar = $this->createMock(IAvatar::class);
$avatar->method('exists')->willReturn($hasAvatar);

Expand Down
6 changes: 4 additions & 2 deletions apps/dav/tests/unit/Avatars/AvatarNodeTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
Expand All @@ -9,18 +10,19 @@

use OCA\DAV\Avatars\AvatarNode;
use OCP\IAvatar;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class AvatarNodeTest extends TestCase {
public function testGetName(): void {
/** @var IAvatar | \PHPUnit\Framework\MockObject\MockObject $a */
/** @var IAvatar&MockObject $a */
$a = $this->createMock(IAvatar::class);
$n = new AvatarNode(1024, 'png', $a);
$this->assertEquals('1024.png', $n->getName());
}

public function testGetContentType(): void {
/** @var IAvatar | \PHPUnit\Framework\MockObject\MockObject $a */
/** @var IAvatar&MockObject $a */
$a = $this->createMock(IAvatar::class);
$n = new AvatarNode(1024, 'png', $a);
$this->assertEquals('image/png', $n->getContentType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class CleanupInvitationTokenJobTest extends TestCase {
/** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
private $dbConnection;

/** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;

/** @var CleanupInvitationTokenJob */
private $backgroundJob;
private IDBConnection&MockObject $dbConnection;
private ITimeFactory&MockObject $timeFactory;
private CleanupInvitationTokenJob $backgroundJob;

protected function setUp(): void {
parent::setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ public function testRunWithPartialBatch(): void {
$deleteQb = $this->getMockQueryBuilder();
$result = $this->createMock(IResult::class);

$qbInvocationCount = self::exactly(2);
$this->connection->expects($qbInvocationCount)
->method('getQueryBuilder')
->willReturnCallback(function () use ($qbInvocationCount, $selectQb, $deleteQb) {
return match ($qbInvocationCount->getInvocationCount()) {
1 => $selectQb,
2 => $deleteQb,
};
$calls = [
$selectQb,
$deleteQb,
];
$this->connection->method('getQueryBuilder')
->willReturnCallback(function () use (&$calls) {
return array_shift($calls);
});
$selectQb->expects(self::once())
->method('executeQuery')
Expand Down Expand Up @@ -140,15 +139,15 @@ public function testRunWithFullBatch(): void {
$deleteQb = $this->getMockQueryBuilder();
$result = $this->createMock(IResult::class);

$qbInvocationCount = self::exactly(2);
$this->connection->expects($qbInvocationCount)
->method('getQueryBuilder')
->willReturnCallback(function () use ($qbInvocationCount, $selectQb, $deleteQb) {
return match ($qbInvocationCount->getInvocationCount()) {
1 => $selectQb,
2 => $deleteQb,
};
$calls = [
$selectQb,
$deleteQb,
];
$this->connection->method('getQueryBuilder')
->willReturnCallback(function () use (&$calls) {
return array_shift($calls);
});

$selectQb->expects(self::once())
->method('executeQuery')
->willReturn($result);
Expand Down
29 changes: 9 additions & 20 deletions apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
use Test\TestCase;

class EventReminderJobTest extends TestCase {
/** @var ITimeFactory|MockObject */
private $time;

/** @var ReminderService|MockObject */
private $reminderService;

/** @var IConfig|MockObject */
private $config;

/** @var EventReminderJob|MockObject */
private $backgroundJob;
private ITimeFactory&MockObject $time;
private ReminderService&MockObject $reminderService;
private IConfig&MockObject $config;
private EventReminderJob $backgroundJob;

protected function setUp(): void {
parent::setUp();
Expand All @@ -42,7 +35,7 @@ protected function setUp(): void {
);
}

public function data(): array {
public static function data(): array {
return [
[true, true, true],
[true, false, false],
Expand All @@ -61,14 +54,10 @@ public function data(): array {
public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
$this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
->method('getAppValue')
->withConsecutive(
['dav', 'sendEventReminders', 'yes'],
['dav', 'sendEventRemindersMode', 'backgroundjob'],
)
->willReturnOnConsecutiveCalls(
$sendEventReminders ? 'yes' : 'no',
$sendEventRemindersMode ? 'backgroundjob' : 'cron'
);
->willReturnMap([
['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')],
['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')],
]);

if ($expectCall) {
$this->reminderService->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@
use Test\TestCase;

class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {

/** @var ITimeFactory|MockObject */
private $time;

/** @var BirthdayService | MockObject */
private $birthdayService;

/** @var IConfig | MockObject */
private $config;

/** @var GenerateBirthdayCalendarBackgroundJob */
private $backgroundJob;
private ITimeFactory&MockObject $time;
private BirthdayService&MockObject $birthdayService;
private IConfig&MockObject $config;
private GenerateBirthdayCalendarBackgroundJob $backgroundJob;

protected function setUp(): void {
parent::setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,11 @@

class OutOfOfficeEventDispatcherJobTest extends TestCase {
private OutOfOfficeEventDispatcherJob $job;

/** @var MockObject|ITimeFactory */
private $timeFactory;

/** @var MockObject|AbsenceMapper */
private $absenceMapper;

/** @var MockObject|LoggerInterface */
private $logger;

/** @var MockObject|IEventDispatcher */
private $eventDispatcher;

/** @var MockObject|IUserManager */
private $userManager;
private ITimeFactory&MockObject $timeFactory;
private AbsenceMapper&MockObject $absenceMapper;
private LoggerInterface&MockObject $logger;
private IEventDispatcher&MockObject $eventDispatcher;
private IUserManager&MockObject $userManager;
private MockObject|TimezoneService $timezoneService;

protected function setUp(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,11 @@
use Test\TestCase;

class PruneOutdatedSyncTokensJobTest extends TestCase {
/** @var ITimeFactory | MockObject */
private $timeFactory;

/** @var CalDavBackend | MockObject */
private $calDavBackend;

/** @var CardDavBackend | MockObject */
private $cardDavBackend;

/** @var IConfig|MockObject */
private $config;

/** @var LoggerInterface|MockObject */
private $logger;

private ITimeFactory&MockObject $timeFactory;
private CalDavBackend&MockObject $calDavBackend;
private CardDavBackend&MockObject $cardDavBackend;
private IConfig&MockObject $config;
private LoggerInterface&MockObject $logger;
private PruneOutdatedSyncTokensJob $backgroundJob;

protected function setUp(): void {
Expand Down Expand Up @@ -84,7 +74,7 @@ public function testRun(string $configToKeep, string $configRetentionDays, int $
$this->backgroundJob->run(null);
}

public function dataForTestRun(): array {
public static function dataForTestRun(): array {
return [
['100', '2', 100, 7 * 24 * 3600, 2, 3],
['100', '14', 100, 14 * 24 * 3600, 2, 3],
Expand Down
22 changes: 5 additions & 17 deletions apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@
use Test\TestCase;

class RefreshWebcalJobTest extends TestCase {

/** @var RefreshWebcalService | MockObject */
private $refreshWebcalService;

/** @var IConfig | MockObject */
private $config;

private RefreshWebcalService&MockObject $refreshWebcalService;
private IConfig&MockObject $config;
private LoggerInterface $logger;

/** @var ITimeFactory | MockObject */
private $timeFactory;

/** @var IJobList | MockObject */
private $jobList;
private ITimeFactory&MockObject $timeFactory;
private IJobList&MockObject $jobList;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -97,10 +88,7 @@ public function testRun(int $lastRun, int $time, bool $process): void {
$backgroundJob->start($this->jobList);
}

/**
* @return array
*/
public function runDataProvider():array {
public static function runDataProvider():array {
return [
[0, 100000, true],
[100000, 100000, false]
Expand Down
Loading
Loading