From af2fd96825d6ae2c7802e9f3bac9054e85093396 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 3 Nov 2020 21:56:37 +0100 Subject: Controllers: Use v2 services Signed-off-by: Sean Molenaar --- CHANGELOG.md | 1 + composer.lock | 157 +++++++++++++++++++++- docs/externalapi/Legacy.md | 60 +++++---- lib/Controller/AdminController.php | 20 +-- lib/Controller/ApiController.php | 2 +- lib/Controller/FeedApiController.php | 66 ++++----- lib/Controller/FeedController.php | 3 + lib/Controller/FolderApiController.php | 26 ++-- lib/Controller/FolderController.php | 3 + lib/Controller/ItemApiController.php | 75 ++++++----- lib/Service/FeedServiceV2.php | 4 +- lib/Service/FolderServiceV2.php | 8 ++ tests/Unit/Controller/FeedApiControllerTest.php | 119 +++++++++------- tests/Unit/Controller/FolderApiControllerTest.php | 26 ++-- tests/Unit/Controller/ItemApiControllerTest.php | 85 ++++++------ 15 files changed, 420 insertions(+), 235 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f2afb57..ce1a8b881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Upload codecoverage to codecov.io - Use foreign keys in db - Fix delete api not working +- Move controllers to use V2 services ## 15.0.6 diff --git a/composer.lock b/composer.lock index 7c9837f5e..b480d54b7 100644 --- a/composer.lock +++ b/composer.lock @@ -57,6 +57,10 @@ "html", "readability" ], + "support": { + "issues": "https://github.com/andreskrey/readability.php/issues", + "source": "https://github.com/andreskrey/readability.php/tree/v2.1.0" + }, "time": "2019-07-22T21:42:25+00:00" }, { @@ -110,6 +114,11 @@ "finder", "icon" ], + "support": { + "issues": "https://github.com/ArthurHoaro/favicon/issues", + "source": "https://github.com/ArthurHoaro/favicon/tree/v1.3.1", + "sources": "https://github.com/ArthurHoaro/favicon" + }, "time": "2020-10-14T09:32:44+00:00" }, { @@ -173,6 +182,10 @@ "news", "rss" ], + "support": { + "issues": "https://github.com/alexdebril/feed-io/issues", + "source": "https://github.com/alexdebril/feed-io/tree/v4.7.10" + }, "funding": [ { "url": "https://github.com/alexdebril", @@ -229,6 +242,10 @@ "keywords": [ "html" ], + "support": { + "issues": "https://github.com/ezyang/htmlpurifier/issues", + "source": "https://github.com/ezyang/htmlpurifier/tree/master" + }, "time": "2020-06-29T00:56:53+00:00" }, { @@ -293,6 +310,10 @@ "uri", "url" ], + "support": { + "issues": "https://pear.php.net/bugs/search.php?cmd=display&package_name[]=Net_URL2", + "source": "https://github.com/pear/Net_URL2" + }, "time": "2017-08-25T06:16:11+00:00" }, { @@ -340,6 +361,9 @@ "psr", "psr-3" ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.3" + }, "time": "2020-03-23T09:12:05+00:00" }, { @@ -390,6 +414,10 @@ "path", "system" ], + "support": { + "issues": "https://github.com/Riimu/Kit-PathJoin/issues", + "source": "https://github.com/Riimu/Kit-PathJoin/tree/master" + }, "time": "2017-07-09T14:41:04+00:00" }, { @@ -504,6 +532,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.3.x" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -566,6 +598,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", @@ -627,6 +663,10 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, "time": "2018-07-08T19:23:20+00:00" }, { @@ -674,6 +714,10 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/master" + }, "time": "2018-07-08T19:19:57+00:00" }, { @@ -723,6 +767,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, "time": "2020-06-27T09:03:43+00:00" }, { @@ -775,6 +823,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, "time": "2020-09-03T19:13:55+00:00" }, { @@ -820,6 +872,10 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + }, "time": "2020-09-17T18:55:26+00:00" }, { @@ -883,6 +939,10 @@ "spy", "stub" ], + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/1.12.1" + }, "time": "2020-09-29T09:10:42+00:00" }, { @@ -925,6 +985,10 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.53" + }, "funding": [ { "url": "https://github.com/ondrejmirtes", @@ -1003,6 +1067,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/8.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1059,6 +1127,10 @@ "filesystem", "iterator" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1118,6 +1190,10 @@ "keywords": [ "process" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1173,6 +1249,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1228,6 +1308,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1283,6 +1367,10 @@ "keywords": [ "tokenizer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/master" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1378,6 +1466,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.2.6" + }, "funding": [ { "url": "https://phpunit.de/donate.html", @@ -1434,6 +1526,10 @@ ], "description": "Collection of value objects that represent the PHP code units", "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1485,6 +1581,10 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1555,6 +1655,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1617,6 +1721,10 @@ "unidiff", "unified diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1676,6 +1784,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1749,6 +1861,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1809,6 +1925,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/master" + }, "time": "2020-02-07T06:11:37+00:00" }, { @@ -1856,6 +1976,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1907,6 +2031,10 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1966,6 +2094,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2017,6 +2149,10 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2069,6 +2205,10 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2118,6 +2258,10 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2186,6 +2330,9 @@ "polyfill", "portable" ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -2240,6 +2387,10 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, "funding": [ { "url": "https://github.com/theseer", @@ -2295,6 +2446,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozart/assert/issues", + "source": "https://github.com/webmozart/assert/tree/master" + }, "time": "2020-07-08T17:02:28+00:00" } ], @@ -2312,5 +2467,5 @@ "ext-curl": "*" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/docs/externalapi/Legacy.md b/docs/externalapi/Legacy.md index f8ec4fb61..e5df7a8e1 100644 --- a/docs/externalapi/Legacy.md +++ b/docs/externalapi/Legacy.md @@ -132,7 +132,7 @@ angular.module('YourApp', []) In general the input parameters can be in the URL or request body, the App Framework doesnt differentiate between them. So JSON in the request body like: -```js +```json { "id": 3 } @@ -159,7 +159,7 @@ The output is JSON. * **Route**: /folders * **Parameters**: none * **Returns**: -```js +```json { "folders": [ { @@ -177,7 +177,7 @@ Creates a new folder and returns a new folder object * **Method**: POST * **Route**: /folders * **Parameters**: -```js +```json { "name": "folder name" } @@ -186,7 +186,7 @@ Creates a new folder and returns a new folder object * **HTTP 409**: If the folder exists already * **HTTP 422**: If the folder name is invalid (for instance empty) * **Returns**: -```js +```json { "folders": [ { @@ -215,7 +215,7 @@ Only the name can be updated * **Method**: PUT * **Route**: /folders/{folderId} * **Parameters**: -```js +```json { "name": "folder name" } @@ -232,7 +232,7 @@ Only the name can be updated * **Method**: PUT * **Route**: /folders/{folderId}/read * **Parameters**: -```js +```json { // mark all items read lower than equal that id // this is mean to prevent marking items as read which the client/user does not yet know of @@ -259,7 +259,7 @@ The following attributes are **not sanitized** meaning: including them in your w * **Route**: /feeds * **Parameters**: none * **Returns**: -```js +```json { "feeds": [ { @@ -294,7 +294,7 @@ Creates a new feed and returns the feed * **Method**: POST * **Route**: /feeds * **Parameters**: -```js +```json { "url": "http:\/\/www.cyanogenmod.org\/wp-content\/themes\/cyanogenmod\/images\/favicon.ico", "folderId": 81 // id of the parent folder, 0 for root @@ -304,7 +304,7 @@ Creates a new feed and returns the feed * **HTTP 409**: If the feed exists already * **HTTP 422**: If the feed cant be read (most likely contains errors) * **Returns**: -```js +```json { "feeds": [ { @@ -341,7 +341,7 @@ Deletes a feed with the id feedId and all of its items * **Method**: PUT * **Route**: /feeds/{feedId}/move * **Parameters**: -```js +```json { "folderId": 0 // id of the parent folder, 0 for root } @@ -356,7 +356,7 @@ Deletes a feed with the id feedId and all of its items * **Method**: PUT * **Route**: /feeds/{feedId}/rename * **Parameters**: -```js +```json { "feedTitle": 'New Title' } @@ -371,7 +371,7 @@ Deletes a feed with the id feedId and all of its items * **Method**: PUT * **Route**: /feeds/{feedId}/read * **Parameters**: -```js +```json { // mark all items read lower than equal that id // this is mean to prevent marking items as read which the client/user does not yet know of @@ -402,7 +402,7 @@ The following attributes are **not sanitized** meaning: including them in your w * **Method**: GET * **Route**: /items * **Parameters**: -```js +```json { "batchSize": 10, // the number of items that should be returned, defaults to -1, new in 5.2.3: -1 returns all items "offset": 30, // only return older (lower than equal that id) items than the one with id 30 @@ -413,7 +413,7 @@ The following attributes are **not sanitized** meaning: including them in your w } ``` * **Returns**: -```js +```json { "items": [ { @@ -446,7 +446,7 @@ Autopaging would work like this: * Get the **first 20** items from a feed with **id 12** **GET /items**: -```js +```json { "batchSize": 20, "offset": 0, @@ -460,7 +460,7 @@ The item with the lowest item id is 43. * Get the next **20** items: **GET /items**: -```js +```json { "batchSize": 20, "offset": 43, @@ -478,7 +478,7 @@ This is used to stay up to date. * **Method**: GET * **Route**: /items/updated * **Parameters**: -```js +```json { "lastModified": 123231, // returns only items with a lastModified timestamp >= than this one // this may also return already existing items whose read or starred status @@ -488,7 +488,7 @@ This is used to stay up to date. } ``` * **Returns**: -```js +```json { "items": [ { @@ -526,7 +526,7 @@ This is used to stay up to date. * **Method**: PUT * **Route**: /items/read/multiple * **Parameters**: -```js +```json { "items": [2, 3] // ids of the items } @@ -547,7 +547,7 @@ This is used to stay up to date. * **Method**: PUT * **Route**: /items/unread/multiple * **Parameters**: -```js +```json { "items": [2, 3] // ids of the items } @@ -568,7 +568,7 @@ This is used to stay up to date. * **Method**: PUT * **Route**: /items/star/multiple * **Parameters**: -```js +```json { "items": [ { @@ -594,7 +594,7 @@ This is used to stay up to date. * **Method**: PUT * **Route**: /items/unstar/multiple * **Parameters**: -```js +```json { "items": [ { @@ -612,7 +612,7 @@ This is used to stay up to date. * **Method**: PUT * **Route**: /items/read * **Parameters**: -```js +```json { // mark all items read lower than equal that id // this is mean to prevent marking items as read which the client/user does not yet know of @@ -657,7 +657,7 @@ This is used to clean up the database. It deletes folders and feeds that are mar * **Route**: /feeds/all * **Parameters**: none * **Returns**: -```js +```json { "feeds": [ { @@ -680,7 +680,7 @@ This is used to clean up the database. It deletes folders and feeds that are mar * **Method**: GET * **Route**: /feeds/update * **Parameters**: -```js +```json { "userId": "john", "feedId": 3 @@ -716,7 +716,7 @@ This is used to clean up the database. It removes old read articles which are no * **Route**: /version * **Parameters**: none * **Returns**: -```js +```json { "version": "5.2.3" } @@ -733,7 +733,7 @@ This API can be used to display warnings and errors in your client if the web ap * **Route**: /status * **Parameters**: none * **Returns**: -```js +```json { "version": "5.2.4", "warnings": { @@ -756,7 +756,9 @@ If **incorrectDbCharset** is true you should display a warning that database cha # User -This API can be used to retrieve metadata about the current user +This API can be used to retrieve metadata about the current user. + +DEPRECATED: This API is deprecated, use the Nextcloud APIs instead. ## Get the status @@ -765,7 +767,7 @@ This API can be used to retrieve metadata about the current user * **Route**: /user * **Parameters**: none * **Returns**: -```js +```json { "userId": "john", "displayName": "John Doe", diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index e3551a2a1..059a0c4a7 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -20,8 +20,6 @@ use OCP\IConfig; use OCP\IRequest; use OCP\AppFramework\Controller; -use OCA\News\Service\ItemService; - /** * Class AdminController * @@ -35,28 +33,18 @@ class AdminController extends Controller */ private $config; - /** - * @var ItemService - */ - private $itemService; - /** * AdminController constructor. * * @param string $appName The name of the app * @param IRequest $request The request * @param IConfig $config Config for nextcloud - * @param ItemService $itemService Service for items */ - public function __construct( - string $appName, - IRequest $request, - IConfig $config, - ItemService $itemService - ) { + public function __construct(string $appName, IRequest $request, IConfig $config) + { parent::__construct($appName, $request); - $this->config = $config; - $this->itemService = $itemService; + + $this->config = $config; } /** diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 544b2c23b..de7a0919c 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -41,7 +41,7 @@ class ApiController extends BaseApiController * @param IRequest $request The request * @param IUserSession $userSession The user session */ - public function __construct($appName, IRequest $request, IUserSession $userSession) + public function __construct(string $appName, IRequest $request, IUserSession $userSession) { parent::__construct($appName, $request); $this->userSession = $userSession; diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index 400c1a4b2..ae2f8cdaf 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -15,12 +15,12 @@ namespace OCA\News\Controller; +use Exception; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; -use OCA\News\Utility\PsrLogger; +use OCA\News\Service\FeedServiceV2; use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; -use \OCP\ILogger; use \OCP\IUserSession; use \OCP\AppFramework\Http; @@ -31,18 +31,25 @@ use function GuzzleHttp\Psr7\uri_for; class FeedApiController extends ApiController { - use JSONHttpErrorTrait; + use JSONHttpErrorTrait, ApiPayloadTrait; /** + * TODO: Remove * @var ItemService */ - private $itemService; + private $oldItemService; /** - * @var FeedService + * @var FeedServiceV2 */ private $feedService; + /** + * TODO: Remove + * @var FeedService + */ + private $oldFeedService; + /** * @var LoggerInterface */ @@ -57,15 +64,16 @@ class FeedApiController extends ApiController string $appName, IRequest $request, IUserSession $userSession, - FeedService $feedService, - ItemService $itemService, + FeedService $oldFeedService, + FeedServiceV2 $feedService, + ItemService $oldItemService, LoggerInterface $logger ) { parent::__construct($appName, $request, $userSession); $this->feedService = $feedService; - $this->itemService = $itemService; + $this->oldFeedService = $oldFeedService; + $this->oldItemService = $oldItemService; $this->logger = $logger; - $this->serializer = new EntityApiSerializer('feeds'); } @@ -78,20 +86,17 @@ class FeedApiController extends ApiController { $result = [ - 'starredCount' => $this->itemService->starredCount($this->getUserId()), - 'feeds' => $this->feedService->findAllForUser($this->getUserId()) + 'starredCount' => $this->oldItemService->starredCount($this->getUserId()), + 'feeds' => $this->serialize($this->feedService->findAllForUser($this->getUserId())) ]; - try { - $result['newestItemId'] = - $this->itemService->getNewestItemId($this->getUserId()); - - // in case there are no items, ignore + $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId()); } catch (ServiceNotFoundException $ex) { + // in case there are no items, ignore } - return $this->serializer->serialize($result); + return $result; } @@ -112,20 +117,18 @@ class FeedApiController extends ApiController } try { - $this->feedService->purgeDeleted($this->getUserId(), false); + $this->feedService->purgeDeleted(); - $feed = $this->feedService->create($url, $folderId, $this->getUserId()); - $result = ['feeds' => [$feed]]; + $feed = $this->feedService->create($this->getUserId(), $url, $folderId); + $result = ['feeds' => $this->serialize($feed)]; try { - $result['newestItemId'] = - $this->itemService->getNewestItemId($this->getUserId()); - - // in case there are no items, ignore + $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId()); } catch (ServiceNotFoundException $ex) { + // in case there are no items, ignore } - return $this->serializer->serialize($result); + return $result; } catch (ServiceConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); } catch (ServiceNotFoundException $ex) { @@ -165,7 +168,7 @@ class FeedApiController extends ApiController */ public function read(int $feedId, int $newestItemId): void { - $this->itemService->readFeed($feedId, $newestItemId, $this->getUserId()); + $this->oldItemService->readFeed($feedId, $newestItemId, $this->getUserId()); } @@ -186,7 +189,7 @@ class FeedApiController extends ApiController } try { - $this->feedService->patch( + $this->oldFeedService->patch( $feedId, $this->getUserId(), ['folderId' => $folderId] @@ -212,7 +215,7 @@ class FeedApiController extends ApiController public function rename(int $feedId, string $feedTitle) { try { - $this->feedService->patch( + $this->oldFeedService->patch( $feedId, $this->getUserId(), ['title' => $feedTitle] @@ -231,7 +234,7 @@ class FeedApiController extends ApiController */ public function fromAllUsers(): array { - $feeds = $this->feedService->findAllFromAllUsers(); + $feeds = $this->feedService->findAll(); $result = ['feeds' => []]; foreach ($feeds as $feed) { @@ -254,9 +257,10 @@ class FeedApiController extends ApiController public function update(string $userId, int $feedId): void { try { - $this->feedService->update($userId, $feedId); + $feed = $this->feedService->find($userId, $feedId); + $this->feedService->fetch($feed); // ignore update failure - } catch (\Exception $ex) { + } catch (Exception $ex) { $this->logger->debug('Could not update feed ' . $ex->getMessage()); } } diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 78df7be0c..5e2ba8a96 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -30,8 +30,11 @@ class FeedController extends Controller { use JSONHttpErrorTrait; + //TODO: Remove private $feedService; + //TODO: Remove private $folderService; + //TODO: Remove private $itemService; private $userId; private $settings; diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php index 691c67139..c9a6b67b7 100644 --- a/lib/Controller/FolderApiController.php +++ b/lib/Controller/FolderApiController.php @@ -20,31 +20,31 @@ use \OCP\IRequest; use \OCP\IUserSession; use \OCP\AppFramework\Http; -use \OCA\News\Service\FolderService; use \OCA\News\Service\ItemService; +use \OCA\News\Service\FolderServiceV2; use \OCA\News\Service\Exceptions\ServiceNotFoundException; use \OCA\News\Service\Exceptions\ServiceConflictException; use \OCA\News\Service\Exceptions\ServiceValidationException; class FolderApiController extends ApiController { - use JSONHttpErrorTrait; + use JSONHttpErrorTrait, ApiPayloadTrait; private $folderService; + //TODO: Remove private $itemService; - private $serializer; public function __construct( string $appName, IRequest $request, IUserSession $userSession, - FolderService $folderService, + FolderServiceV2 $folderService, ItemService $itemService ) { parent::__construct($appName, $request, $userSession); + $this->folderService = $folderService; $this->itemService = $itemService; - $this->serializer = new EntityApiSerializer('folders'); } @@ -55,9 +55,8 @@ class FolderApiController extends ApiController */ public function index() { - return $this->serializer->serialize( - $this->folderService->findAllForUser($this->getUserId()) - ); + $folders = $this->folderService->findAllForUser($this->getUserId()); + return ['folders' => $this->serialize($folders)]; } @@ -73,10 +72,9 @@ class FolderApiController extends ApiController public function create(string $name) { try { - $this->folderService->purgeDeleted($this->getUserId(), false); - return $this->serializer->serialize( - $this->folderService->create($name, $this->getUserId()) - ); + $this->folderService->purgeDeleted(); + $folder = $this->folderService->create($this->getUserId(), $name); + return ['folders' => $this->serialize($folder)]; } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch (ServiceConflictException $ex) { @@ -101,7 +99,7 @@ class FolderApiController extends ApiController } try { - $this->folderService->delete($folderId, $this->getUserId()); + $this->folderService->delete($this->getUserId(), $folderId); } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -127,7 +125,7 @@ class FolderApiController extends ApiController } try { - $this->folderService->rename($folderId, $name, $this->getUserId()); + $this->folderService->rename($this->getUserId(), $folderId, $name); } catch (ServiceValidationException $ex) { return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch (ServiceConflictException $ex) { diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 09900f5b2..e67299c6d 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -30,8 +30,11 @@ class FolderController extends Controller { use JSONHttpErrorTrait; + //TODO: Remove private $folderService; + //TODO: Remove private $feedService; + //TODO: Remove private $itemService; private $userId; diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index 0ac0a890a..3e31d2fdd 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -15,30 +15,33 @@ namespace OCA\News\Controller; +use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\IUserSession; use \OCP\AppFramework\Http; -use \OCA\News\Service\ItemService; use \OCA\News\Service\Exceptions\ServiceNotFoundException; class ItemApiController extends ApiController { - use JSONHttpErrorTrait; + use JSONHttpErrorTrait, ApiPayloadTrait; + private $oldItemService; private $itemService; - private $serializer; public function __construct( string $appName, IRequest $request, IUserSession $userSession, - ItemService $itemService + ItemService $oldItemService, + ItemServiceV2 $itemService ) { parent::__construct($appName, $request, $userSession); + + $this->oldItemService = $oldItemService; $this->itemService = $itemService; - $this->serializer = new EntityApiSerializer('items'); } @@ -63,17 +66,17 @@ class ItemApiController extends ApiController int $offset = 0, bool $oldestFirst = false ) { - return $this->serializer->serialize( - $this->itemService->findAllItems( - $id, - $type, - $batchSize, - $offset, - $getRead, - $oldestFirst, - $this->getUserId() - ) + $items = $this->oldItemService->findAllItems( + $id, + $type, + $batchSize, + $offset, + $getRead, + $oldestFirst, + $this->getUserId() ); + + return ['items' => $this->serialize($items)]; } @@ -87,7 +90,7 @@ class ItemApiController extends ApiController * @param int $lastModified * @return array|mixed */ - public function updated($type = 3, $id = 0, $lastModified = 0) + public function updated(int $type = 3, int $id = 0, int $lastModified = 0) { // needs to be turned into a millisecond timestamp to work properly if (strlen((string) $lastModified) <= 10) { @@ -95,22 +98,22 @@ class ItemApiController extends ApiController } else { $paddedLastModified = $lastModified; } - return $this->serializer->serialize( - $this->itemService->findAllNew( - $id, - $type, - $paddedLastModified, - true, - $this->getUserId() - ) + $items = $this->oldItemService->findAllNew( + $id, + $type, + $paddedLastModified, + true, + $this->getUserId() ); + + return ['items' => $this->serialize($items)]; } - private function setRead($isRead, $itemId) + private function setRead(bool $isRead, int $itemId) { try { - $this->itemService->read($itemId, $isRead, $this->getUserId()); + $this->oldItemService->read($itemId, $isRead, $this->getUserId()); } catch (ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -149,10 +152,10 @@ class ItemApiController extends ApiController } - private function setStarred($isStarred, $feedId, $guidHash) + private function setStarred(bool $isStarred, int $feedId, string $guidHash) { try { - $this->itemService->star( + $this->oldItemService->star( $feedId, $guidHash, $isStarred, @@ -207,15 +210,15 @@ class ItemApiController extends ApiController */ public function readAll(int $newestItemId) { - $this->itemService->readAll($newestItemId, $this->getUserId()); + $this->oldItemService->readAll($newestItemId, $this->getUserId()); } - private function setMultipleRead($isRead, $items) + private function setMultipleRead(bool $isRead, array $items) { foreach ($items as $id) { try { - $this->itemService->read($id, $isRead, $this->getUserId()); + $this->oldItemService->read($id, $isRead, $this->getUserId()); } catch (ServiceNotFoundException $ex) { continue; } @@ -249,11 +252,15 @@ class ItemApiController extends ApiController } - private function setMultipleStarred($isStarred, $items) + /** + * @param bool $isStarred + * @param array $items + */ + private function setMultipleStarred(bool $isStarred, array $items) { foreach ($items as $item) { try { - $this->itemService->star( + $this->oldItemService->star( $item['feedId'], $item['guidHash'], $isStarred, @@ -284,7 +291,7 @@ class ItemApiController extends ApiController * @NoCSRFRequired * @CORS * - * @param int[] $items item ids + * @param array $items item ids */ public function unstarMultiple(array $items) { diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index 4be96ebf8..0d1b45600 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -246,11 +246,11 @@ class FeedServiceV2 extends Service /** * Update a feed * - * @param Feed $feed Feed item + * @param Feed|Entity $feed Feed item * * @return Feed|Entity Database feed entity */ - public function fetch(Feed $feed): Entity + public function fetch(Entity $feed): Entity { if ($feed->getPreventUpdate() === true) { return $feed; diff --git a/lib/Service/FolderServiceV2.php b/lib/Service/FolderServiceV2.php index 784d82f8c..ee24addfd 100644 --- a/lib/Service/FolderServiceV2.php +++ b/lib/Service/FolderServiceV2.php @@ -101,4 +101,12 @@ class FolderServiceV2 extends Service { $this->mapper->purgeDeleted(); } + + public function rename(string $userId, int $folderId, string $newName) + { + /** @var Folder $folder */ + $folder = $this->mapper->find($userId, $folderId); + $folder->setName($newName); + $this->mapper->update($folder); + } } diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index c87a9ff6c..ace481a66 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -17,7 +17,9 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\FeedApiController; use OCA\News\Service\FeedService; +use OCA\News\Service\FeedServiceV2; use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use OCA\News\Utility\PsrLogger; use \OCP\AppFramework\Http; @@ -34,18 +36,32 @@ use Psr\Log\LoggerInterface; class FeedApiControllerTest extends TestCase { - + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FeedService + */ + private $oldFeedService; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FeedServiceV2 + */ private $feedService; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + */ private $itemService; - private $feedAPI; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + */ + private $logger; + + private $class; private $user; private $msg; - private $logger; - private $loggerParams; protected function setUp(): void { - $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -65,20 +81,23 @@ class FeedApiControllerTest extends TestCase $this->user->expects($this->any()) ->method('getUID') ->will($this->returnValue('123')); - $this->feedService = $this->getMockBuilder(FeedService::class) + $this->oldFeedService = $this->getMockBuilder(FeedService::class) + ->disableOriginalConstructor() + ->getMock(); + $this->feedService = $this->getMockBuilder(FeedServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->feedAPI = new FeedApiController( + $this->class = new FeedApiController( $appName, $request, $userSession, + $this->oldFeedService, $this->feedService, $this->itemService, - $this->logger, - $this->loggerParams + $this->logger ); $this->msg = 'hohoho'; } @@ -103,7 +122,7 @@ class FeedApiControllerTest extends TestCase ->with($this->equalTo($this->user->getUID())) ->will($this->returnValue($feeds)); - $response = $this->feedAPI->index(); + $response = $this->class->index(); $this->assertEquals( [ @@ -133,7 +152,7 @@ class FeedApiControllerTest extends TestCase ->with($this->equalTo($this->user->getUID())) ->will($this->returnValue($feeds)); - $response = $this->feedAPI->index(); + $response = $this->class->index(); $this->assertEquals( [ @@ -153,7 +172,7 @@ class FeedApiControllerTest extends TestCase $this->equalTo(2) ); - $this->feedAPI->delete(2); + $this->class->delete(2); } @@ -167,7 +186,7 @@ class FeedApiControllerTest extends TestCase ) ); - $response = $this->feedAPI->delete(2); + $response = $this->class->delete(2); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -180,21 +199,17 @@ class FeedApiControllerTest extends TestCase $feeds = [new Feed()]; $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->feedService->expects($this->once()) ->method('create') - ->with( - $this->equalTo('url'), - $this->equalTo(3), - $this->equalTo($this->user->getUID()) - ) + ->with($this->user->getUID(), 'url', 3) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->returnValue(3)); - $response = $this->feedAPI->create('url', 3); + $response = $this->class->create('url', 3); $this->assertEquals( [ @@ -210,21 +225,17 @@ class FeedApiControllerTest extends TestCase $feeds = [new Feed()]; $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->feedService->expects($this->once()) ->method('create') - ->with( - $this->equalTo('ho'), - $this->equalTo(3), - $this->equalTo($this->user->getUID()) - ) + ->with($this->user->getUID(), 'ho', 3) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->throwException(new ServiceNotFoundException(''))); - $response = $this->feedAPI->create('ho', 3); + $response = $this->class->create('ho', 3); $this->assertEquals( [ @@ -238,15 +249,15 @@ class FeedApiControllerTest extends TestCase public function testCreateExists() { $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->feedService->expects($this->once()) ->method('create') ->will( $this->throwException(new ServiceConflictException($this->msg)) ); - $response = $this->feedAPI->create('ho', 3); + $response = $this->class->create('ho', 3); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -262,7 +273,7 @@ class FeedApiControllerTest extends TestCase $this->throwException(new ServiceNotFoundException($this->msg)) ); - $response = $this->feedAPI->create('ho', 3); + $response = $this->class->create('ho', 3); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -280,13 +291,13 @@ class FeedApiControllerTest extends TestCase $this->equalTo($this->user->getUID()) ); - $this->feedAPI->read(3, 30); + $this->class->read(3, 30); } public function testMove() { - $this->feedService->expects($this->once()) + $this->oldFeedService->expects($this->once()) ->method('patch') ->with( $this->equalTo(3), @@ -294,19 +305,19 @@ class FeedApiControllerTest extends TestCase $this->equalTo(['folderId' => 30]) ); - $this->feedAPI->move(3, 30); + $this->class->move(3, 30); } public function testMoveDoesNotExist() { - $this->feedService->expects($this->once()) + $this->oldFeedService->expects($this->once()) ->method('patch') ->will( $this->throwException(new ServiceNotFoundException($this->msg)) ); - $response = $this->feedAPI->move(3, 4); + $response = $this->class->move(3, 4); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -319,7 +330,7 @@ class FeedApiControllerTest extends TestCase $feedId = 3; $feedTitle = 'test'; - $this->feedService->expects($this->once()) + $this->oldFeedService->expects($this->once()) ->method('patch') ->with( $this->equalTo($feedId), @@ -327,7 +338,7 @@ class FeedApiControllerTest extends TestCase $this->equalTo(['title' => $feedTitle]) ); - $this->feedAPI->rename($feedId, $feedTitle); + $this->class->rename($feedId, $feedTitle); } @@ -336,7 +347,7 @@ class FeedApiControllerTest extends TestCase $feedId = 3; $feedTitle = 'test'; - $this->feedService->expects($this->once()) + $this->oldFeedService->expects($this->once()) ->method('patch') ->with( $this->equalTo($feedId), @@ -345,7 +356,7 @@ class FeedApiControllerTest extends TestCase ) ->will($this->throwException(new ServiceNotFoundException('hi'))); - $result = $this->feedAPI->rename($feedId, $feedTitle); + $result = $this->class->rename($feedId, $feedTitle); $data = $result->getData(); $code = $result->getStatus(); @@ -362,9 +373,9 @@ class FeedApiControllerTest extends TestCase $feed->setUserId('john'); $feeds = [$feed]; $this->feedService->expects($this->once()) - ->method('findAllFromAllUsers') + ->method('findAll') ->will($this->returnValue($feeds)); - $response = json_encode($this->feedAPI->fromAllUsers()); + $response = json_encode($this->class->fromAllUsers()); $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response); } @@ -373,12 +384,18 @@ class FeedApiControllerTest extends TestCase { $feedId = 3; $userId = 'hi'; + $feed = new Feed(); + + $this->feedService->expects($this->once()) + ->method('find') + ->with($userId, $feedId) + ->willReturn($feed); $this->feedService->expects($this->once()) - ->method('update') - ->with($userId, $feedId); + ->method('fetch') + ->with($feed); - $this->feedAPI->update($userId, $feedId); + $this->class->update($userId, $feedId); } @@ -387,16 +404,14 @@ class FeedApiControllerTest extends TestCase $feedId = 3; $userId = 'hi'; $this->feedService->expects($this->once()) - ->method('update') + ->method('find') ->will($this->throwException(new \Exception($this->msg))); + $this->logger->expects($this->once()) ->method('debug') ->with('Could not update feed ' . $this->msg); - $this->feedAPI->update($userId, $feedId); - - + $this->class->update($userId, $feedId); } - } diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 3c5650e5c..fdf494037 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -17,6 +17,7 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\FolderApiController; use OCA\News\Service\FolderService; +use OCA\News\Service\FolderServiceV2; use OCA\News\Service\ItemService; use \OCP\AppFramework\Http; @@ -59,7 +60,7 @@ class FolderApiControllerTest extends TestCase $this->user->expects($this->any()) ->method('getUID') ->will($this->returnValue('123')); - $this->folderService = $this->getMockBuilder(FolderService::class) + $this->folderService = $this->getMockBuilder(FolderServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder(ItemService::class) @@ -102,11 +103,11 @@ class FolderApiControllerTest extends TestCase $folder->setName($folderName); $this->folderService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->folderService->expects($this->once()) ->method('create') - ->with($this->equalTo($folderName), $this->equalTo($this->user->getUID())) + ->with($this->user->getUID(), $folderName) ->will($this->returnValue($folder)); $response = $this->folderAPI->create($folderName); @@ -124,8 +125,8 @@ class FolderApiControllerTest extends TestCase $msg = 'exists'; $this->folderService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->folderService->expects($this->once()) ->method('create') ->will($this->throwException(new ServiceConflictException($msg))); @@ -143,8 +144,8 @@ class FolderApiControllerTest extends TestCase $msg = 'exists'; $this->folderService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user->getUID()), $this->equalTo(false)); + ->method('purgeDeleted'); + $this->folderService->expects($this->once()) ->method('create') ->will($this->throwException(new ServiceValidationException($msg))); @@ -161,10 +162,9 @@ class FolderApiControllerTest extends TestCase public function testDelete() { - $folderId = 23; $this->folderService->expects($this->once()) ->method('delete') - ->with($this->equalTo($folderId), $this->equalTo($this->user->getUID())); + ->with($this->user->getUID(), 23); $this->folderAPI->delete(23); } @@ -197,11 +197,7 @@ class FolderApiControllerTest extends TestCase $this->folderService->expects($this->once()) ->method('rename') - ->with( - $this->equalTo($folderId), - $this->equalTo($folderName), - $this->equalTo($this->user->getUID()) - ); + ->with($this->user->getUID(), $folderId, $folderName); $this->folderAPI->update($folderId, $folderName); } diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 75fd6bbef..06b60f78c 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -17,6 +17,7 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\ItemApiController; use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; use \OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -32,8 +33,8 @@ class ItemApiControllerTest extends TestCase { private $itemService; - private $itemAPI; - private $api; + private $oldItemService; + private $class; private $userSession; private $user; private $request; @@ -58,13 +59,17 @@ class ItemApiControllerTest extends TestCase $this->user->expects($this->any()) ->method('getUID') ->will($this->returnValue('123')); - $this->itemService = $this->getMockBuilder(ItemService::class) + $this->oldItemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->itemAPI = new ItemApiController( + $this->itemService = $this->getMockBuilder(ItemServiceV2::class) + ->disableOriginalConstructor() + ->getMock(); + $this->class = new ItemApiController( $this->appName, $this->request, $this->userSession, + $this->oldItemService, $this->itemService ); $this->msg = 'hi'; @@ -79,7 +84,7 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('findAllItems') ->with( $this->equalTo(2), @@ -92,7 +97,7 @@ class ItemApiControllerTest extends TestCase ) ->will($this->returnValue([$item])); - $response = $this->itemAPI->index(1, 2, true, 30, 20, true); + $response = $this->class->index(1, 2, true, 30, 20, true); $this->assertEquals( [ @@ -110,7 +115,7 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('findAllItems') ->with( $this->equalTo(2), @@ -123,7 +128,7 @@ class ItemApiControllerTest extends TestCase ) ->will($this->returnValue([$item])); - $response = $this->itemAPI->index(1, 2, false); + $response = $this->class->index(1, 2, false); $this->assertEquals( [ @@ -141,7 +146,7 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('findAllNew') ->with( $this->equalTo(2), @@ -152,7 +157,7 @@ class ItemApiControllerTest extends TestCase ) ->will($this->returnValue([$item])); - $response = $this->itemAPI->updated(1, 2, 30); + $response = $this->class->updated(1, 2, 30); $this->assertEquals( [ @@ -164,7 +169,7 @@ class ItemApiControllerTest extends TestCase public function testRead() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('read') ->with( $this->equalTo(2), @@ -172,13 +177,13 @@ class ItemApiControllerTest extends TestCase $this->equalTo($this->user->getUID()) ); - $this->itemAPI->read(2); + $this->class->read(2); } public function testReadDoesNotExist() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('read') ->will( $this->throwException( @@ -186,7 +191,7 @@ class ItemApiControllerTest extends TestCase ) ); - $response = $this->itemAPI->read(2); + $response = $this->class->read(2); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -196,7 +201,7 @@ class ItemApiControllerTest extends TestCase public function testUnread() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('read') ->with( $this->equalTo(2), @@ -204,13 +209,13 @@ class ItemApiControllerTest extends TestCase $this->equalTo($this->user->getUID()) ); - $this->itemAPI->unread(2); + $this->class->unread(2); } public function testUnreadDoesNotExist() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('read') ->will( $this->throwException( @@ -218,7 +223,7 @@ class ItemApiControllerTest extends TestCase ) ); - $response = $this->itemAPI->unread(2); + $response = $this->class->unread(2); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -228,7 +233,7 @@ class ItemApiControllerTest extends TestCase public function testStar() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('star') ->with( $this->equalTo(2), @@ -237,13 +242,13 @@ class ItemApiControllerTest extends TestCase $this->equalTo($this->user->getUID()) ); - $this->itemAPI->star(2, 'hash'); + $this->class->star(2, 'hash'); } public function testStarDoesNotExist() { - $this->itemService->expects($this->once()) + $this->oldItemService->expects($this->once()) ->method('star') ->will( $this->throwException( @@ -251,7 +256,7 @@ class ItemApiControllerTest extends TestCase ) ); - $response = $this->itemAPI->star(2, 'test'); + $response = $this->class->star(2, 'test'); $data = $re