From 5bdc2df7f484f6618919a63247045027d43b78f7 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 9 Nov 2020 23:29:25 +0100 Subject: Fix unread count and related issues Issue GH-924 Signed-off-by: Sean Molenaar --- tests/Integration/Db/FeedMapperTest.php | 7 ----- tests/Unit/Command/UpdateFeedTest.php | 47 ++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index f07103d10..803e9260b 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -119,9 +119,6 @@ class FeedMapperTest extends IntegrationTest $this->assertEquals($feed->getTitle(), $fetched->getTitle()); } - /** - * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException - */ public function testFindByUrlHashMoreThanOneResult() { $this->expectException('OCP\AppFramework\Db\MultipleObjectsReturnedException'); @@ -143,10 +140,6 @@ class FeedMapperTest extends IntegrationTest $this->feedMapper->findByUrlHash($feed1->getUrlHash(), $this->user); } - - /** - * @expectedException OCP\AppFramework\Db\DoesNotExistException - */ public function testFindByUrlHashNotExisting() { $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); diff --git a/tests/Unit/Command/UpdateFeedTest.php b/tests/Unit/Command/UpdateFeedTest.php index 05d12fa66..bd0cd34e4 100644 --- a/tests/Unit/Command/UpdateFeedTest.php +++ b/tests/Unit/Command/UpdateFeedTest.php @@ -67,6 +67,12 @@ class UpdateFeedTest extends TestCase $feed = $this->createMock(Feed::class); + $feed->expects($this->exactly(1)) + ->method('getUpdateErrorCount') + ->willReturn(0); + $feed->expects($this->exactly(0)) + ->method('getLastUpdateError'); + $this->service->expects($this->exactly(1)) ->method('findForUser') ->with('admin', '1') @@ -74,12 +80,51 @@ class UpdateFeedTest extends TestCase $this->service->expects($this->exactly(1)) ->method('fetch') - ->with($feed); + ->with($feed) + ->willReturn($feed); $result = $this->command->run($this->consoleInput, $this->consoleOutput); $this->assertSame(0, $result); } + /** + * Test a valid call will work + */ + public function testValidFeedError() + { + $this->consoleInput->expects($this->exactly(2)) + ->method('getArgument') + ->will($this->returnValueMap([ + ['feed-id', '1'], + ['user-id', 'admin'], + ])); + + $feed = $this->createMock(Feed::class); + $feed->expects($this->exactly(1)) + ->method('getUpdateErrorCount') + ->willReturn(10); + $feed->expects($this->exactly(1)) + ->method('getLastUpdateError') + ->willReturn('Problem'); + + $this->service->expects($this->exactly(1)) + ->method('findForUser') + ->with('admin', '1') + ->willReturn($feed); + + $this->service->expects($this->exactly(1)) + ->method('fetch') + ->with($feed) + ->willReturn($feed); + + $this->consoleOutput->expects($this->exactly(1)) + ->method('writeln') + ->with('Problem'); + + $result = $this->command->run($this->consoleInput, $this->consoleOutput); + $this->assertSame(255, $result); + } + /** * Test a valid call will work */ -- cgit v1.2.3