Skip to content

Commit

Permalink
Get rid of deprecated at matcher in dav application tests
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 5, 2023
1 parent adef2b8 commit 574c677
Show file tree
Hide file tree
Showing 32 changed files with 718 additions and 858 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public function testRun() {
->with()
->willReturn($queryBuilder);

$queryBuilder->expects($this->at(0))
$queryBuilder->expects($this->once())
->method('delete')
->with('calendar_invitations')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(3))
$queryBuilder->expects($this->once())
->method('where')
->with($function)
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(4))
$queryBuilder->expects($this->once())
->method('execute')
->with()
->willReturn($stmt);
Expand Down
20 changes: 9 additions & 11 deletions apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Test\TestCase;

class EventReminderJobTest extends TestCase {

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

Expand Down Expand Up @@ -80,17 +79,16 @@ public function data(): array {
* @param bool $expectCall
*/
public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
$this->config->expects($this->at(0))
$this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
->method('getAppValue')
->with('dav', 'sendEventReminders', 'yes')
->willReturn($sendEventReminders ? 'yes' : 'no');

if ($sendEventReminders) {
$this->config->expects($this->at(1))
->method('getAppValue')
->with('dav', 'sendEventRemindersMode', 'backgroundjob')
->willReturn($sendEventRemindersMode ? 'backgroundjob' : 'cron');
}
->withConsecutive(
['dav', 'sendEventReminders', 'yes'],
['dav', 'sendEventRemindersMode', 'backgroundjob'],
)
->willReturnOnConsecutiveCalls(
$sendEventReminders ? 'yes' : 'no',
$sendEventRemindersMode ? 'backgroundjob' : 'cron'
);

if ($expectCall) {
$this->reminderService->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
use OCA\DAV\BackgroundJob\RegisterRegenerateBirthdayCalendars;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use Test\TestCase;

class RegisterRegenerateBirthdayCalendarsTest extends TestCase {

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

Expand Down Expand Up @@ -81,24 +79,22 @@ public function testRun() {
$closure($user3);
});

$this->jobList->expects($this->at(0))
->method('add')
->with(GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid1',
'purgeBeforeGenerating' => true
]);
$this->jobList->expects($this->at(1))
->method('add')
->with(GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid2',
'purgeBeforeGenerating' => true
]);
$this->jobList->expects($this->at(2))
$this->jobList->expects($this->exactly(3))
->method('add')
->with(GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid3',
'purgeBeforeGenerating' => true
]);
->withConsecutive(
[GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid1',
'purgeBeforeGenerating' => true
]],
[GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid2',
'purgeBeforeGenerating' => true
]],
[GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => 'uid3',
'purgeBeforeGenerating' => true
]],
);

$this->backgroundJob->run([]);
}
Expand Down
52 changes: 28 additions & 24 deletions apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testPropPatch() {
$calendar->propPatch($propPatch);
}


public function testGetChild() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
$this->expectExceptionMessage('Calendar object not found');
Expand All @@ -154,17 +154,19 @@ public function testGetChild() {
'uri' => 'cal',
];

$backend->expects($this->at(0))
$backend->expects($this->exactly(2))
->method('getCalendarObject')
->with(666, 'foo1', 1)
->willReturn([
'id' => 99,
'uri' => 'foo1'
]);
$backend->expects($this->at(1))
->method('getCalendarObject')
->with(666, 'foo2', 1)
->willReturn(null);
->withConsecutive(
[666, 'foo1', 1],
[666, 'foo2', 1],
)
->willReturnOnConsecutiveCalls(
[
'id' => 99,
'uri' => 'foo1'
],
null
);

$calendar = new CachedSubscription($backend, $calendarInfo);

Expand All @@ -183,7 +185,7 @@ public function testGetChildren() {
'uri' => 'cal',
];

$backend->expects($this->at(0))
$backend->expects($this->once())
->method('getCalendarObjects')
->with(666, 1)
->willReturn([
Expand Down Expand Up @@ -214,7 +216,7 @@ public function testGetMultipleChildren() {
'uri' => 'cal',
];

$backend->expects($this->at(0))
$backend->expects($this->once())
->method('getMultipleCalendarObjects')
->with(666, ['foo1', 'foo2'], 1)
->willReturn([
Expand All @@ -236,7 +238,7 @@ public function testGetMultipleChildren() {
$this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]);
}


public function testCreateFile() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
$this->expectExceptionMessage('Creating objects in cached subscription is not allowed');
Expand All @@ -262,17 +264,19 @@ public function testChildExists() {
'uri' => 'cal',
];

$backend->expects($this->at(0))
->method('getCalendarObject')
->with(666, 'foo1', 1)
->willReturn([
'id' => 99,
'uri' => 'foo1'
]);
$backend->expects($this->at(1))
$backend->expects($this->exactly(2))
->method('getCalendarObject')
->with(666, 'foo2', 1)
->willReturn(null);
->withConsecutive(
[666, 'foo1', 1],
[666, 'foo2', 1],
)
->willReturnOnConsecutiveCalls(
[
'id' => 99,
'uri' => 'foo1'
],
null
);

$calendar = new CachedSubscription($backend, $calendarInfo);

Expand Down
Loading

0 comments on commit 574c677

Please sign in to comment.