From 407fbebc2da14520942e0a6a9220a5a3cfc4a7ad Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 15 May 2014 03:41:49 +0200 Subject: rename businesslayer to service --- tests/unit/controller/ExportControllerTest.php | 27 +++--- tests/unit/controller/FeedApiControllerTest.php | 86 ++++++++---------- tests/unit/controller/FeedControllerTest.php | 106 +++++++++++----------- tests/unit/controller/FolderApiControllerTest.php | 62 ++++++------- tests/unit/controller/FolderControllerTest.php | 87 +++++++++--------- tests/unit/controller/ItemApiControllerTest.php | 70 +++++++------- tests/unit/controller/ItemControllerTest.php | 72 +++++++-------- 7 files changed, 255 insertions(+), 255 deletions(-) (limited to 'tests/unit/controller') diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index fd3aece97..ded145f2b 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -29,9 +29,9 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { private $request; private $controller; private $user; - private $feedBusinessLayer; - private $folderBusinessLayer; - private $itemBusinessLayer; + private $feedService; + private $folderService; + private $itemService; private $opmlExporter; /** @@ -40,13 +40,16 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { public function setUp(){ $this->appName = 'news'; $this->user = 'john'; - $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); - $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); - $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') + $this->folderService = $this->getMockBuilder( + '\OCA\News\Service\FolderService') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder('\OCP\IRequest') @@ -54,8 +57,8 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { ->getMock(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->appName, $this->request, - $this->feedBusinessLayer, $this->folderBusinessLayer, - $this->itemBusinessLayer, $this->opmlExporter, $this->user); + $this->folderService, $this->feedService, + $this->itemService, $this->opmlExporter, $this->user); } @@ -69,11 +72,11 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { " \n" . "\n"; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue([])); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue([])); @@ -100,11 +103,11 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { $articles = [$item1, $item2]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getUnreadOrStarred') ->with($this->equalTo($this->user)) ->will($this->returnValue($articles)); diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php index 6e18d89da..b5a167588 100644 --- a/tests/unit/controller/FeedApiControllerTest.php +++ b/tests/unit/controller/FeedApiControllerTest.php @@ -15,8 +15,8 @@ namespace OCA\News\Controller; use \OCP\AppFramework\Http; -use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\Service\ServiceNotFoundException; +use \OCA\News\Service\ServiceConflictException; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; use \OCA\News\Db\Item; @@ -26,9 +26,8 @@ require_once(__DIR__ . "/../../classloader.php"); class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { - private $folderBusinessLayer; - private $feedBusinessLayer; - private $itemBusinessLayer; + private $feedService; + private $itemService; private $feedAPI; private $appName; private $user; @@ -49,24 +48,19 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); - $this->folderBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\FolderBusinessLayer') + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); - $this->feedBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\FeedBusinessLayer') - ->disableOriginalConstructor() - ->getMock(); - $this->itemBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); $this->feedAPI = new FeedApiController( $this->appName, $this->request, - $this->folderBusinessLayer, - $this->feedBusinessLayer, - $this->itemBusinessLayer, + $this->feedService, + $this->itemService, $this->logger, $this->user, $this->loggerParams @@ -80,15 +74,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $starredCount = 3; $newestItemId = 2; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue($starredCount)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) ->will($this->returnValue($newestItemId)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); @@ -107,15 +101,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $feeds = [new Feed()]; $starredCount = 3; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue($starredCount)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException(''))); - $this->feedBusinessLayer->expects($this->once()) + ->will($this->throwException(new ServiceNotFoundException(''))); + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); @@ -130,7 +124,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testDelete() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('delete') ->with( $this->equalTo(2), @@ -141,9 +135,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testDeleteDoesNotExist() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('delete') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->feedAPI->delete(2); @@ -156,17 +150,17 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreate() { $feeds = [new Feed()]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->with( $this->equalTo('url'), $this->equalTo(3), $this->equalTo($this->user)) ->will($this->returnValue($feeds[0])); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->returnValue(3)); @@ -182,19 +176,19 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateNoItems() { $feeds = [new Feed()]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->with( $this->equalTo('ho'), $this->equalTo(3), $this->equalTo($this->user)) ->will($this->returnValue($feeds[0])); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') - ->will($this->throwException(new BusinessLayerException(''))); + ->will($this->throwException(new ServiceNotFoundException(''))); $response = $this->feedAPI->create('ho', 3); @@ -206,12 +200,12 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateExists() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') - ->will($this->throwException(new BusinessLayerConflictException($this->msg))); + ->will($this->throwException(new ServiceConflictException($this->msg))); $response = $this->feedAPI->create('ho', 3); @@ -222,9 +216,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateError() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->feedAPI->create('ho', 3); @@ -235,7 +229,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testRead() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readFeed') ->with( $this->equalTo(3), @@ -247,7 +241,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testMove() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('move') ->with( $this->equalTo(3), @@ -259,9 +253,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testMoveDoesNotExist() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('move') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->feedAPI->move(3, 4); @@ -275,7 +269,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $feedId = 3; $feedTitle = 'test'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('rename') ->with( $this->equalTo($feedId), @@ -292,7 +286,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $feed->setId(1); $feed->setUserId('john'); $feeds = [$feed]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAllFromAllUsers') ->will($this->returnValue($feeds)); $response = json_encode($this->feedAPI->fromAllUsers()); @@ -304,7 +298,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $feedId = 3; $userId = 'hi'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('update') ->with($this->equalTo($feedId), $this->equalTo($userId)); @@ -315,7 +309,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUpdateError() { $feedId = 3; $userId = 'hi'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('update') ->will($this->throwException(new \Exception($this->msg))); $this->logger->expects($this->once()) diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index b59175468..a2fc8bc22 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -17,8 +17,8 @@ use \OCP\AppFramework\Http; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; -use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\Service\ServiceNotFoundException; +use \OCA\News\Service\ServiceConflictException; require_once(__DIR__ . "/../../classloader.php"); @@ -26,11 +26,11 @@ require_once(__DIR__ . "/../../classloader.php"); class FeedControllerTest extends \PHPUnit_Framework_TestCase { private $appName; - private $feedBusinessLayer; + private $feedService; private $request; private $controller; - private $folderBusinessLayer; - private $itemBusinessLayer; + private $folderService; + private $itemService; private $settings; private $exampleResult; @@ -45,13 +45,13 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder('\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); - $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') + $this->feedService = $this->getMockBuilder('\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); - $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') + $this->folderService = $this->getMockBuilder('\OCA\News\Service\FolderService') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( @@ -59,9 +59,9 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->controller = new FeedController($this->appName, $this->request, - $this->folderBusinessLayer, - $this->feedBusinessLayer, - $this->itemBusinessLayer, + $this->folderService, + $this->feedService, + $this->itemService, $this->settings, $this->user); $this->exampleResult = [ @@ -80,15 +80,15 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ], 'starred' => 13 ]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException(''))); - $this->itemBusinessLayer->expects($this->once()) + ->will($this->throwException(new ServiceNotFoundException(''))); + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['starred'])); @@ -107,15 +107,15 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { 'starred' => 13, 'newestItemId' => 5 ]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['newestItemId'])); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['starred'])); @@ -164,10 +164,10 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testActiveFeedDoesNotExist(){ $id = 3; $type = FeedType::FEED; - $ex = new BusinessLayerException('hiu'); + $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -183,10 +183,10 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testActiveFolderDoesNotExist(){ $id = 3; $type = FeedType::FOLDER; - $ex = new BusinessLayerException('hiu'); + $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -219,13 +219,13 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { 'newestItemId' => 3 ]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->returnValue($result['newestItemId'])); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->with($this->equalTo('hi'), $this->equalTo(4), @@ -241,15 +241,15 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateNoItems(){ $result = ['feeds' => [new Feed()]]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') - ->will($this->throwException(new BusinessLayerException(''))); + ->will($this->throwException(new ServiceNotFoundException(''))); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->with($this->equalTo('hi'), $this->equalTo(4), @@ -264,11 +264,11 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BusinessLayerException($msg); - $this->feedBusinessLayer->expects($this->once()) + $ex = new ServiceNotFoundException($msg); + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -282,11 +282,11 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateReturnsErrorForDuplicateCreate(){ $msg = 'except'; - $ex = new BusinessLayerConflictException($msg); - $this->feedBusinessLayer->expects($this->once()) + $ex = new ServiceConflictException($msg); + $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -299,7 +299,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testDelete(){ - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('markDeleted') ->with($this->equalTo(4)); @@ -310,9 +310,9 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testDeleteDoesNotExist(){ $msg = 'hehe'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('markDeleted') - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->delete(4); $params = json_decode($response->render(), true); @@ -335,7 +335,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ] ]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('update') ->with($this->equalTo(4), $this->equalTo($this->user)) ->will($this->returnValue($feed)); @@ -347,10 +347,10 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testUpdateReturnsJSONError(){ - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('update') ->with($this->equalTo(4), $this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException('NO!'))); + ->will($this->throwException(new ServiceNotFoundException('NO!'))); $response = $this->controller->update(4); $render = $response->render(); @@ -361,7 +361,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testMove(){ - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('move') ->with($this->equalTo(4), $this->equalTo(3), @@ -375,9 +375,9 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testMoveDoesNotExist(){ $msg = 'john'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('move') - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->move(4, 3); $params = json_decode($response->render(), true); @@ -388,7 +388,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testRename(){ - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('rename') ->with($this->equalTo(4), $this->equalTo('title'), @@ -401,12 +401,12 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testRenameDoesNotExist(){ $msg = 'hi'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('rename') ->with($this->equalTo(4), $this->equalTo('title'), $this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->rename(4, 'title'); @@ -424,7 +424,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { 'feeds' => [$feed] ]; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('importArticles') ->with($this->equalTo('json'), $this->equalTo($this->user)) @@ -437,7 +437,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testImportCreatesNoAdditionalFeed() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('importArticles') ->with($this->equalTo('json'), $this->equalTo($this->user)) @@ -459,7 +459,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ] ]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readFeed') ->with($this->equalTo(4), $this->equalTo(5), $this->user); @@ -469,7 +469,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testRestore() { - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('unmarkDeleted') ->with($this->equalTo(4)); @@ -480,9 +480,9 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testRestoreDoesNotExist(){ $msg = 'hehe'; - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('unmarkDeleted') - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->restore(4); $params = json_decode($response->render(), true); diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php index d3171e397..8ddb9d14f 100644 --- a/tests/unit/controller/FolderApiControllerTest.php +++ b/tests/unit/controller/FolderApiControllerTest.php @@ -16,9 +16,9 @@ namespace OCA\News\Controller; use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\BusinessLayer\BusinessLayerConflictException; -use \OCA\News\BusinessLayer\BusinessLayerValidationException; +use \OCA\News\Service\ServiceNotFoundException; +use \OCA\News\Service\ServiceConflictException; +use \OCA\News\Service\ServiceValidationException; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; @@ -29,8 +29,8 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { - private $folderBusinessLayer; - private $itemBusinessLayer; + private $folderService; + private $itemService; private $folderAPI; private $appName; private $user; @@ -44,19 +44,19 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); - $this->folderBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\FolderBusinessLayer') + $this->folderService = $this->getMockBuilder( + '\OCA\News\Service\FolderService') ->disableOriginalConstructor() ->getMock(); - $this->itemBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); $this->folderAPI = new FolderApiController( $this->appName, $this->request, - $this->folderBusinessLayer, - $this->itemBusinessLayer, + $this->folderService, + $this->itemService, $this->user ); $this->msg = 'test'; @@ -66,7 +66,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testIndex() { $folders = [new Folder()]; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($folders)); @@ -83,10 +83,10 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folder->setName($folderName); $folders = [$folder]; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') ->with($this->equalTo($folderName), $this->equalTo($this->user)) ->will($this->returnValue($folder)); @@ -100,12 +100,12 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateAlreadyExists() { $msg = 'exists'; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') - ->will($this->throwException(new BusinessLayerConflictException($msg))); + ->will($this->throwException(new ServiceConflictException($msg))); $response = $this->folderAPI->create('hi'); @@ -118,12 +118,12 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateInvalidFolderName() { $msg = 'exists'; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') - ->will($this->throwException(new BusinessLayerValidationException($msg))); + ->will($this->throwException(new ServiceValidationException($msg))); $response = $this->folderAPI->create('hi'); @@ -135,7 +135,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testDelete() { $folderId = 23; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('delete') ->with($this->equalTo($folderId), $this->equalTo($this->user)); @@ -146,9 +146,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testDeleteDoesNotExist() { $folderId = 23; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('delete') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->folderAPI->delete($folderId); @@ -162,7 +162,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folderId = 23; $folderName = 'test'; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('rename') ->with($this->equalTo($folderId), $this->equalTo($folderName), @@ -175,9 +175,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folderId = 23; $folderName = 'test'; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->folderAPI->update($folderId, $folderName); @@ -191,9 +191,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folderId = 23; $folderName = 'test'; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new BusinessLayerConflictException($this->msg))); + ->will($this->throwException(new ServiceConflictException($this->msg))); $response = $this->folderAPI->update($folderId, $folderName); @@ -207,9 +207,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folderId = 23; $folderName = ''; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new BusinessLayerValidationException($this->msg))); + ->will($this->throwException(new ServiceValidationException($this->msg))); $response = $this->folderAPI->update($folderId, $folderName); @@ -220,7 +220,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { public function testRead() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readFolder') ->with( $this->equalTo(3), diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index af63aa959..04fa32a54 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -17,9 +17,9 @@ use \OCP\AppFramework\Http; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; -use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\BusinessLayer\BusinessLayerConflictException; -use \OCA\News\BusinessLayer\BusinessLayerValidationException; +use \OCA\News\Service\ServiceNotFoundException; +use \OCA\News\Service\ServiceConflictException; +use \OCA\News\Service\ServiceValidationException; require_once(__DIR__ . "/../../classloader.php"); @@ -27,9 +27,9 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderControllerTest extends \PHPUnit_Framework_TestCase { private $appName; - private $folderBusinessLayer; - private $itemBusinessLayer; - private $feedBusinessLayer; + private $folderService; + private $itemService; + private $feedService; private $request; private $controller; private $msg; @@ -41,13 +41,16 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function setUp(){ $this->appName = 'news'; $this->user = 'jack'; - $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') + $this->folderService = $this->getMockBuilder( + '\OCA\News\Service\FolderService') ->disableOriginalConstructor() ->getMock(); - $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); - $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( @@ -55,9 +58,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->controller = new FolderController($this->appName, $this->request, - $this->folderBusinessLayer, - $this->feedBusinessLayer, - $this->itemBusinessLayer, + $this->folderService, + $this->feedService, + $this->itemService, $this->user); $this->msg = 'ron'; } @@ -66,7 +69,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testIndex(){ $return = [new Folder(), new Folder()]; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('findAll') ->will($this->returnValue($return)); @@ -77,7 +80,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testOpen(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('open') ->with($this->equalTo(3), $this->equalTo(true), $this->equalTo($this->user)); @@ -88,9 +91,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testOpenDoesNotExist(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('open') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->controller->open(5); @@ -102,7 +105,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testCollapse(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('open') ->with($this->equalTo(5), $this->equalTo(false), $this->equalTo($this->user)); @@ -113,9 +116,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testCollapseDoesNotExist(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('open') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->controller->collapse(5); @@ -129,10 +132,10 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testCreate(){ $result = ['folders' => [new Folder()]]; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') ->with($this->equalTo('tech'), $this->equalTo($this->user)) @@ -146,11 +149,11 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BusinessLayerValidationException($msg); - $this->folderBusinessLayer->expects($this->once()) + $ex = new ServiceValidationException($msg); + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -164,11 +167,11 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateReturnsErrorForDuplicateCreate(){ $msg = 'except'; - $ex = new BusinessLayerConflictException($msg); - $this->folderBusinessLayer->expects($this->once()) + $ex = new ServiceConflictException($msg); + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -181,7 +184,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testDelete(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('markDeleted') ->with($this->equalTo(5), $this->equalTo($this->user)); @@ -191,9 +194,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testDeleteDoesNotExist(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('markDeleted') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->controller->delete(5); @@ -207,7 +210,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRename(){ $result = ['folders' => [new Folder()]]; - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('rename') ->with($this->equalTo(4), $this->equalTo('tech'), @@ -222,8 +225,8 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRenameReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BusinessLayerValidationException($msg); - $this->folderBusinessLayer->expects($this->once()) + $ex = new ServiceValidationException($msg); + $this->folderService->expects($this->once()) ->method('rename') ->will($this->throwException($ex)); @@ -237,8 +240,8 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRenameDoesNotExist(){ $msg = 'except'; - $ex = new BusinessLayerException($msg); - $this->folderBusinessLayer->expects($this->once()) + $ex = new ServiceNotFoundException($msg); + $this->folderService->expects($this->once()) ->method('rename') ->will($this->throwException($ex)); @@ -252,8 +255,8 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRenameReturnsErrorForDuplicateCreate(){ $msg = 'except'; - $ex = new BusinessLayerConflictException($msg); - $this->folderBusinessLayer->expects($this->once()) + $ex = new ServiceConflictException($msg); + $this->folderService->expects($this->once()) ->method('rename') ->will($this->throwException($ex)); @@ -270,12 +273,12 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $feed = new Feed(); $expected = ['feeds' => [$feed]]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readFolder') ->with($this->equalTo(4), $this->equalTo(5), $this->equalTo($this->user)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue([$feed])); @@ -286,7 +289,7 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRestore(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('unmarkDeleted') ->with($this->equalTo(5), $this->equalTo($this->user)); @@ -296,9 +299,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRestoreDoesNotExist(){ - $this->folderBusinessLayer->expects($this->once()) + $this->folderService->expects($this->once()) ->method('unmarkDeleted') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->controller->restore(5); diff --git a/tests/unit/controller/ItemApiControllerTest.php b/tests/unit/controller/ItemApiControllerTest.php index f78db838b..d95d67594 100644 --- a/tests/unit/controller/ItemApiControllerTest.php +++ b/tests/unit/controller/ItemApiControllerTest.php @@ -15,7 +15,7 @@ namespace OCA\News\Controller; use \OCP\AppFramework\Http; -use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Db\Item; require_once(__DIR__ . "/../../classloader.php"); @@ -23,7 +23,7 @@ require_once(__DIR__ . "/../../classloader.php"); class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { - private $itemBusinessLayer; + private $itemService; private $itemAPI; private $api; private $user; @@ -37,14 +37,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); - $this->itemBusinessLayer = $this->getMockBuilder( - '\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); $this->itemAPI = new ItemApiController( $this->appName, $this->request, - $this->itemBusinessLayer, + $this->itemService, $this->user ); $this->msg = 'hi'; @@ -54,7 +54,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testIndex() { $items = [new Item()]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAll') ->with( $this->equalTo(2), @@ -75,7 +75,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testIndexDefaultBatchSize() { $items = [new Item()]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAll') ->with( $this->equalTo(2), @@ -96,7 +96,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUpdated() { $items = [new Item()]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAllNew') ->with( $this->equalTo(2), @@ -114,7 +114,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testRead() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->with( $this->equalTo(2), @@ -127,9 +127,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testReadDoesNotExist() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->itemAPI->read(2); @@ -140,7 +140,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnread() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->with( $this->equalTo(2), @@ -153,9 +153,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnreadDoesNotExist() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->itemAPI->unread(2); @@ -166,7 +166,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testStar() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') ->with( $this->equalTo(2), @@ -180,9 +180,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testStarDoesNotExist() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->itemAPI->star(2, 'test'); @@ -193,7 +193,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnstar() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') ->with( $this->equalTo(2), @@ -207,9 +207,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnstarDoesNotExist() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new BusinessLayerException($this->msg))); + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->itemAPI->unstar(2, 'test'); @@ -220,7 +220,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testReadAll() { - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readAll') ->with( $this->equalTo(30), @@ -232,12 +232,12 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testReadMultiple() { - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('read') ->with($this->equalTo(2), $this->equalTo(true), $this->equalTo($this->user)); - $this->itemBusinessLayer->expects($this->at(1)) + $this->itemService->expects($this->at(1)) ->method('read') ->with($this->equalTo(4), $this->equalTo(true), @@ -247,10 +247,10 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testReadMultipleDoesntCareAboutException() { - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('read') - ->will($this->throwException(new BusinessLayerException(''))); - $this->itemBusinessLayer->expects($this->at(1)) + ->will($this->throwException(new ServiceNotFoundException(''))); + $this->itemService->expects($this->at(1)) ->method('read') ->with($this->equalTo(4), $this->equalTo(true), @@ -260,12 +260,12 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnreadMultiple() { - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('read') ->with($this->equalTo(2), $this->equalTo(false), $this->equalTo($this->user)); - $this->itemBusinessLayer->expects($this->at(1)) + $this->itemService->expects($this->at(1)) ->method('read') ->with($this->equalTo(4), $this->equalTo(false), @@ -286,13 +286,13 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { ] ]; - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('star') ->with($this->equalTo(2), $this->equalTo('a'), $this->equalTo(true), $this->equalTo($this->user)); - $this->itemBusinessLayer->expects($this->at(1)) + $this->itemService->expects($this->at(1)) ->method('star') ->with($this->equalTo(4), $this->equalTo('b'), @@ -314,10 +314,10 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { ] ]; - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('star') - ->will($this->throwException(new BusinessLayerException(''))); - $this->itemBusinessLayer->expects($this->at(1)) + ->will($this->throwException(new ServiceNotFoundException(''))); + $this->itemService->expects($this->at(1)) ->method('star') ->with($this->equalTo(4), $this->equalTo('b'), @@ -339,13 +339,13 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { ] ]; - $this->itemBusinessLayer->expects($this->at(0)) + $this->itemService->expects($this->at(0)) ->method('star') ->with($this->equalTo(2), $this->equalTo('a'), $this->equalTo(false), $this->equalTo($this->user)); - $this->itemBusinessLayer->expects($this->at(1)) + $this->itemService->expects($this->at(1)) ->method('star') ->with($this->equalTo(4), $this->equalTo('b'), diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 1ebcdce55..8756c6db0 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -18,7 +18,7 @@ use \OCP\AppFramework\Http; use \OCA\News\Db\Item; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; -use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\Service\ServiceNotFoundException; require_once(__DIR__ . "/../../classloader.php"); @@ -27,8 +27,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { private $appName; private $settings; - private $itemBusinessLayer; - private $feedBusinessLayer; + private $itemService; + private $feedService; private $request; private $controller; private $newestItemId; @@ -44,12 +44,12 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $this->itemBusinessLayer = - $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + $this->itemService = + $this->getMockBuilder('\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); - $this->feedBusinessLayer = - $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') + $this->feedService = + $this->getMockBuilder('\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( @@ -57,14 +57,14 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->controller = new ItemController($this->appName, $this->request, - $this->feedBusinessLayer, $this->itemBusinessLayer, $this->settings, + $this->feedService, $this->itemService, $this->settings, $this->user); $this->newestItemId = 12312; } public function testRead(){ - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->with(4, true, $this->user); @@ -75,9 +75,9 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testReadDoesNotExist(){ $msg = 'hi'; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->read(4); $params = json_decode($response->render(), true); @@ -88,7 +88,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testUnread(){ - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->with(4, false, $this->user); @@ -100,9 +100,9 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testUnreadDoesNotExist(){ $msg = 'hi'; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new BusinessLayerException($msg))); + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->unread(4); @@ -114,7 +114,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testStar(){ - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') ->with( $this->equalTo(4), @@ -129,9 +129,9 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testStarDoesNotExist(){ $msg = 'ho'; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new BusinessLayerException($msg)));; + ->will($this->throwException(new ServiceNotFoundException($msg)));; $response = $this->controller->star(4, 'test'); $params = json_decode($response->render(), true); @@ -142,7 +142,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testUnstar(){ - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') ->with( $this->equalTo(4), @@ -157,9 +157,9 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testUnstarDoesNotExist(){ $msg = 'ho'; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new BusinessLayerException($msg)));; + ->will($this->throwException(new ServiceNotFoundException($msg)));; $response = $this->controller->unstar(4, 'test'); $params = json_decode($response->render(), true); @@ -174,11 +174,11 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $expected = ['feeds' => [$feed]]; - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readAll') ->with($this->equalTo(5), $this->equalTo($this->user)); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue([$feed])); @@ -227,22 +227,22 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->itemsApiExpects(2, FeedType::FEED, '0'); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) ->will($this->returnValue($this->newestItemId)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue(3111)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAll') ->with( $this->equalTo(2), @@ -264,7 +264,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->itemsApiExpects(2, FeedType::FEED); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAll') ->with($this->equalTo(2), $this->equalTo(FeedType::FEED), @@ -275,7 +275,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(true)) ->will($this->returnValue($result['items'])); - $this->feedBusinessLayer->expects($this->never()) + $this->feedService->expects($this->never()) ->method('findAll'); $response = $this->controller->index(FeedType::FEED, 2, 3, 10, true); @@ -286,10 +286,10 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { public function testGetItemsNoNewestItemsId(){ $this->itemsApiExpects(2, FeedType::FEED); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException(''))); + ->will($this->throwException(new ServiceNotFoundException(''))); $response = $this->controller->index(FeedType::FEED, 2, 3); $this->assertEquals([], $response); @@ -312,22 +312,22 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo('showAll')) ->will($this->returnValue('1')); - $this->feedBusinessLayer->expects($this->once()) + $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) ->will($this->returnValue($this->newestItemId)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue(3111)); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('findAllNew') ->with( $this->equalTo(2), @@ -350,10 +350,10 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo('showAll')) ->will($this->returnValue('1')); - $this->itemBusinessLayer->expects($this->once()) + $this->itemService->expects($this->once()) ->method('getNewestItemId') ->with($this->equalTo($this->user)) - ->will($this->throwException(new BusinessLayerException(''))); + ->will($this->throwException(new ServiceNotFoundException(''))); $response = $this->controller->newItems(FeedType::FEED, 2, 3); $this->assertEquals([], $response); -- cgit v1.2.3