diff options
-rw-r--r-- | lib/Service/ItemService.php | 8 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php index fdf97c27b..f657b3eff 100644 --- a/lib/Service/ItemService.php +++ b/lib/Service/ItemService.php @@ -147,8 +147,12 @@ class ItemService extends Service { * @throws ServiceNotFoundException if the item does not exist */ public function read($itemId, $isRead, $userId){ - $lastModified = $this->timeFactory->getMicroTime(); - $this->itemMapper->readItem($itemId, $isRead, $lastModified, $userId); + try { + $lastModified = $this->timeFactory->getMicroTime(); + $this->itemMapper->readItem($itemId, $isRead, $lastModified, $userId); + } catch(DoesNotExistException $ex) { + throw new ServiceNotFoundException($ex->getMessage()); + } } diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 107b6aef3..3b3197136 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -298,6 +298,18 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { } + public function testReadDoesNotExist(){ + + $this->setExpectedException( + '\OCA\News\Service\ServiceNotFoundException' + ); + $this->mapper->expects($this->once()) + ->method('readItem') + ->will($this->throwException(new DoesNotExistException(''))); + + $this->itemService->read(1, true, $this->user); + } + public function testStarDoesNotExist(){ $this->setExpectedException( |