From 6ca3bb6fec67e4d394911b72526c42980f86446d Mon Sep 17 00:00:00 2001 From: Joe Nahmias Date: Thu, 29 Jun 2023 23:29:04 -0400 Subject: [PATCH] test: replace usage of at() matcher with alternatives The PHPUnit at() matcher, used to determine the order that methods are called on test doubles, has been deprecated in PHPUnit 9 and has been removed in PHPUnit 10. Migrate usage of at() to other constructs following Drupal core examples in: --- tests/units/Helper/HookHelperTest.php | 20 +++--------- tests/units/Model/ProjectFileTest.php | 14 ++++----- tests/units/Model/TaskFileModelTest.php | 26 +++++++--------- tests/units/Model/UserNotificationTest.php | 36 ++++++++-------------- 4 files changed, 35 insertions(+), 61 deletions(-) diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php index 95a1cfde2..ebc85572d 100644 --- a/tests/units/Helper/HookHelperTest.php +++ b/tests/units/Helper/HookHelperTest.php @@ -88,22 +88,12 @@ class HookHelperTest extends Base ->getMock(); $this->container['template'] - ->expects($this->at(0)) + ->expects($this->any()) ->method('render') - ->with( - $this->equalTo('tpl1'), - $this->equalTo(array()) - ) - ->will($this->returnValue('tpl1_content')); - - $this->container['template'] - ->expects($this->at(1)) - ->method('render') - ->with( - $this->equalTo('tpl2'), - $this->equalTo(array()) - ) - ->will($this->returnValue('tpl2_content')); + ->willReturnMap([ + ['tpl1', array(), 'tpl1_content'], + ['tpl2', array(), 'tpl2_content'], + ]); $hookHelper = new HookHelper($this->container); $hookHelper->attach('test', 'tpl1'); diff --git a/tests/units/Model/ProjectFileTest.php b/tests/units/Model/ProjectFileTest.php index e08b13386..d9dfd2952 100644 --- a/tests/units/Model/ProjectFileTest.php +++ b/tests/units/Model/ProjectFileTest.php @@ -148,14 +148,12 @@ class ProjectFileTest extends Base ->method('generateThumbnailFromFile'); $this->container['objectStorage'] - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + ->withConsecutive( + ['/tmp/phpYzdqkD'], + ['/tmp/phpeEwEWG'], + ); $this->assertTrue($fileModel->uploadFiles(1, $files)); @@ -232,7 +230,7 @@ class ProjectFileTest extends Base ); $this->container['objectStorage'] - ->expects($this->at(0)) + ->expects($this->once()) ->method('moveUploadedFile') ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); diff --git a/tests/units/Model/TaskFileModelTest.php b/tests/units/Model/TaskFileModelTest.php index 4fa849025..e14f5336d 100644 --- a/tests/units/Model/TaskFileModelTest.php +++ b/tests/units/Model/TaskFileModelTest.php @@ -175,14 +175,12 @@ class TaskFileModelTest extends Base ->method('generateThumbnailFromFile'); $this->container['objectStorage'] - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('moveUploadedFile') - ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + ->withConsecutive( + ['/tmp/phpYzdqkD'], + ['/tmp/phpeEwEWG'], + ); $this->assertTrue($fileModel->uploadFiles(1, $files)); @@ -259,7 +257,7 @@ class TaskFileModelTest extends Base ); $this->container['objectStorage'] - ->expects($this->at(0)) + ->expects($this->once()) ->method('moveUploadedFile') ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); @@ -411,14 +409,12 @@ class TaskFileModelTest extends Base $this->assertEquals(1, $fileModel->create(1, 'image.gif', 'tmp/image.gif', 10)); $this->container['objectStorage'] - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('remove') - ->with('tmp/image.gif'); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('remove') - ->with('thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'); + ->withConsecutive( + ['tmp/image.gif'], + ['thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'], + ); $this->assertTrue($fileModel->remove(1)); } diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index e568d204d..e6e1f9366 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -51,20 +51,13 @@ class UserNotificationTest extends Base )); $this->container['userNotificationTypeModel'] - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getSelectedTypes') - ->will($this->returnValue(array('email'))); - - $this->container['userNotificationTypeModel'] - ->expects($this->at(1)) - ->method('getSelectedTypes') - ->will($this->returnValue(array('email'))); - - $this->container['userNotificationTypeModel'] - ->expects($this->at(2)) - ->method('getSelectedTypes') - ->with($this->equalTo(1)) - ->will($this->returnValue(array('email', 'web'))); + ->willReturnOnConsecutiveCalls( + array('email'), + array('email'), + array('email','web'), + ); $settings = $n->readSettings(1); $this->assertNotEmpty($settings); @@ -209,21 +202,18 @@ class UserNotificationTest extends Base ->method('notifyUser'); $this->container['userNotificationTypeModel'] - ->expects($this->at(0)) + ->expects($this->once()) ->method('getSelectedTypes') ->will($this->returnValue(array('email', 'web'))); $this->container['userNotificationTypeModel'] - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getType') - ->with($this->equalTo('email')) - ->will($this->returnValue($notifier)); - - $this->container['userNotificationTypeModel'] - ->expects($this->at(2)) - ->method('getType') - ->with($this->equalTo('web')) - ->will($this->returnValue($notifier)); + ->withConsecutive( + ['email'], + ['web'], + ) + ->willReturn($notifier); $userNotificationModel->sendNotifications(TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1))); }