Skip to content

Commit

Permalink
Rewrite birthday calendar tests without $this->at()
Browse files Browse the repository at this point in the history
Removes warnings:

```
The at() matcher has been deprecated. It will be removed in PHPUnit 10.
Please refactor your test to not rely on the order in which methods are
invoked.
```
  • Loading branch information
francoisfreitag committed May 31, 2021
1 parent 4fc002a commit 3d046d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
10 changes: 5 additions & 5 deletions apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testInitialize() {

$plugin = new EnablePlugin($this->config, $this->birthdayService);

$server->expects($this->at(0))
$server->expects($this->once())
->method('on')
->with('method:POST', [$plugin, 'httpPost']);

Expand Down Expand Up @@ -120,11 +120,11 @@ public function testHttpPostWrongRequest() {
->with('/bar/foo')
->willReturn($calendarHome);

$this->request->expects($this->at(0))
$this->request->expects($this->once())
->method('getBodyAsString')
->willReturn('<nc:disable-birthday-calendar xmlns:nc="http://nextcloud.com/ns"/>');

$this->request->expects($this->at(1))
$this->request->expects($this->once())
->method('getUrl')
->willReturn('url_abc');

Expand Down Expand Up @@ -158,11 +158,11 @@ public function testHttpPost() {
->method('getOwner')
->willReturn('principals/users/BlaBlub');

$this->request->expects($this->at(0))
$this->request->expects($this->once())
->method('getBodyAsString')
->willReturn('<nc:enable-birthday-calendar xmlns:nc="http://nextcloud.com/ns"/>');

$this->request->expects($this->at(1))
$this->request->expects($this->once())
->method('getUrl')
->willReturn('url_abc');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ public function testEnable() {
$closure($user3);
});

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

$response = $this->controller->enable();
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGetName() {
}

public function testRun() {
$this->config->expects($this->at(0))
$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
->willReturn(null);
Expand All @@ -72,11 +72,11 @@ public function testRun() {
->method('info')
->with('Adding background jobs to regenerate birthday calendar');

$this->jobList->expects($this->at(0))
$this->jobList->expects($this->once())
->method('add')
->with(RegisterRegenerateBirthdayCalendars::class);

$this->config->expects($this->at(1))
$this->config->expects($this->once())
->method('setAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');

Expand Down

0 comments on commit 3d046d0

Please sign in to comment.