From 6181d9edf73c05ebf03ae27a1561bc94d98d7704 Mon Sep 17 00:00:00 2001 From: Raul Ferreira Fuentes Date: Tue, 5 Apr 2022 18:07:06 +0200 Subject: [PATCH] Fix NotifierTest to mock the new `StackMapper::findStackFromCardId()` method correctly. Signed-off-by: Raul Ferreira Fuentes --- tests/unit/Notification/NotifierTest.php | 32 +++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/unit/Notification/NotifierTest.php b/tests/unit/Notification/NotifierTest.php index a26d8db92..da6e3348d 100644 --- a/tests/unit/Notification/NotifierTest.php +++ b/tests/unit/Notification/NotifierTest.php @@ -25,6 +25,7 @@ namespace OCA\Deck\Notification; use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\CardMapper; +use OCA\Deck\Db\Stack; use OCA\Deck\Db\StackMapper; use OCP\IL10N; use OCP\IURLGenerator; @@ -103,9 +104,9 @@ class NotifierTest extends \Test\TestCase { $notification->expects($this->once()) ->method('getObjectId') ->willReturn('123'); - $this->cardMapper->expects($this->once()) - ->method('findBoardId') - ->willReturn(999); + $this->stackMapper->expects($this->once()) + ->method('findStackFromCardId') + ->willReturn($this->buildMockStack()); $expectedMessage = 'The card "Card title" on "Board title" has reached its due date.'; $notification->expects($this->once()) ->method('setParsedSubject') @@ -146,9 +147,9 @@ class NotifierTest extends \Test\TestCase { $notification->expects($this->once()) ->method('getObjectId') ->willReturn('123'); - $this->cardMapper->expects($this->once()) - ->method('findBoardId') - ->willReturn(999); + $this->stackMapper->expects($this->once()) + ->method('findStackFromCardId') + ->willReturn($this->buildMockStack()); $expectedMessage = 'admin has mentioned you in a comment on "Card title".'; $notification->expects($this->once()) ->method('setParsedSubject') @@ -183,9 +184,9 @@ class NotifierTest extends \Test\TestCase { /** @dataProvider dataPrepareCardAssigned */ public function testPrepareCardAssigned($withUserFound = true) { - $this->cardMapper->expects($this->once()) - ->method('findBoardId') - ->willReturn(123); + $this->stackMapper->expects($this->once()) + ->method('findStackFromCardId') + ->willReturn($this->buildMockStack(123)); /** @var INotification $notification */ $notification = $this->createMock(INotification::class); @@ -338,4 +339,17 @@ class NotifierTest extends \Test\TestCase { $this->assertEquals($notification, $actualNotification); } + + /** + * @param int $boardId + * @return Stack|MockObject + */ + private function buildMockStack(int $boardId = 999) { + $mock_stack = $this->getMockBuilder(Stack::class) + ->addMethods(['getBoardId']) + ->getMock(); + + $mock_stack->method('getBoardId')->willReturn($boardId); + return $mock_stack; + } }