summaryrefslogtreecommitdiffstats
path: root/tests/Unit
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-08-29 23:39:35 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-27 15:35:31 +0200
commitd00d1ab2a28f428223e52b17052c072c64784016 (patch)
treec019f85fb7ac67147dd43ca64b4ac3cda99832f7 /tests/Unit
parent5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff)
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Controller/FeedApiControllerTest.php36
-rw-r--r--tests/Unit/Controller/FeedControllerTest.php16
-rw-r--r--tests/Unit/Controller/FolderApiControllerTest.php23
-rw-r--r--tests/Unit/Controller/FolderControllerTest.php14
-rw-r--r--tests/Unit/Controller/ItemApiControllerTest.php2
-rw-r--r--tests/Unit/Controller/ItemControllerTest.php2
-rw-r--r--tests/Unit/Controller/UtilityApiControllerTest.php57
-rw-r--r--tests/Unit/Db/FeedTest.php25
-rw-r--r--tests/Unit/Db/FolderMapperTest.php6
-rw-r--r--tests/Unit/Db/FolderTest.php9
-rw-r--r--tests/Unit/Db/MapperFactoryTest.php4
-rw-r--r--tests/Unit/Fetcher/FeedFetcherTest.php32
-rw-r--r--tests/Unit/Service/FeedServiceTest.php168
-rw-r--r--tests/Unit/Service/FolderServiceTest.php30
-rw-r--r--tests/Unit/Service/ItemServiceTest.php59
-rw-r--r--tests/Unit/Service/ServiceTest.php39
-rw-r--r--tests/Unit/Service/UpdaterTest.php (renamed from tests/Unit/Utility/UpdaterTest.php)38
17 files changed, 328 insertions, 232 deletions
diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php
index c889a54b3..1dbac6f42 100644
--- a/tests/Unit/Controller/FeedApiControllerTest.php
+++ b/tests/Unit/Controller/FeedApiControllerTest.php
@@ -18,10 +18,11 @@ namespace OCA\News\Tests\Unit\Controller;
use OCA\News\Controller\FeedApiController;
use OCA\News\Service\FeedService;
use OCA\News\Service\ItemService;
+use OCA\News\Utility\PsrLogger;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ServiceNotFoundException;
-use \OCA\News\Service\ServiceConflictException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceConflictException;
use \OCA\News\Db\Feed;
use OCP\ILogger;
use OCP\IRequest;
@@ -29,6 +30,7 @@ use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
class FeedApiControllerTest extends TestCase
{
@@ -36,10 +38,7 @@ class FeedApiControllerTest extends TestCase
private $feedService;
private $itemService;
private $feedAPI;
- private $appName;
- private $userSession;
private $user;
- private $request;
private $msg;
private $logger;
private $loggerParams;
@@ -47,20 +46,20 @@ class FeedApiControllerTest extends TestCase
protected function setUp(): void
{
$this->loggerParams = ['hi'];
- $this->logger = $this->getMockBuilder(ILogger::class)
+ $this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
- $this->appName = 'news';
- $this->request = $this->getMockBuilder(IRequest::class)
+ $appName = 'news';
+ $request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
- $this->userSession = $this->getMockBuilder(IUserSession::class)
+ $userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor()
->getMock();
$this->user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
- $this->userSession->expects($this->any())
+ $userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$this->user->expects($this->any())
@@ -73,9 +72,9 @@ class FeedApiControllerTest extends TestCase
->disableOriginalConstructor()
->getMock();
$this->feedAPI = new FeedApiController(
- $this->appName,
- $this->request,
- $this->userSession,
+ $appName,
+ $request,
+ $userSession,
$this->feedService,
$this->itemService,
$this->logger,
@@ -100,7 +99,7 @@ class FeedApiControllerTest extends TestCase
->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($newestItemId));
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($feeds));
@@ -130,7 +129,7 @@ class FeedApiControllerTest extends TestCase
->with($this->equalTo($this->user->getUID()))
->will($this->throwException(new ServiceNotFoundException('')));
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($feeds));
@@ -377,7 +376,7 @@ class FeedApiControllerTest extends TestCase
$this->feedService->expects($this->once())
->method('update')
- ->with($this->equalTo($feedId), $this->equalTo($userId));
+ ->with($userId, $feedId);
$this->feedAPI->update($userId, $feedId);
}
@@ -392,10 +391,7 @@ class FeedApiControllerTest extends TestCase
->will($this->throwException(new \Exception($this->msg)));
$this->logger->expects($this->once())
->method('debug')
- ->with(
- $this->equalTo('Could not update feed ' . $this->msg),
- $this->equalTo($this->loggerParams)
- );
+ ->with('Could not update feed ' . $this->msg);
$this->feedAPI->update($userId, $feedId);
diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php
index 9a3114da0..7498d0ccb 100644
--- a/tests/Unit/Controller/FeedControllerTest.php
+++ b/tests/Unit/Controller/FeedControllerTest.php
@@ -21,8 +21,8 @@ use OCP\AppFramework\Http;
use OCA\News\Db\Feed;
use OCA\News\Db\FeedType;
-use OCA\News\Service\ServiceNotFoundException;
-use OCA\News\Service\ServiceConflictException;
+use OCA\News\Service\Exceptions\ServiceNotFoundException;
+use OCA\News\Service\Exceptions\ServiceConflictException;
use OCP\IConfig;
use OCP\IRequest;
@@ -93,7 +93,7 @@ class FeedControllerTest extends TestCase
'starred' => 13
];
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue($result['feeds']));
$this->itemService->expects($this->once())
@@ -121,7 +121,7 @@ class FeedControllerTest extends TestCase
'newestItemId' => 5
];
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue($result['feeds']));
$this->itemService->expects($this->once())
@@ -189,7 +189,7 @@ class FeedControllerTest extends TestCase
$this->feedService->expects($this->once())
->method('find')
- ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->with($this->user, $id)
->will($this->throwException($ex));
$this->activeInitMocks($id, $type);
@@ -209,7 +209,7 @@ class FeedControllerTest extends TestCase
$this->folderService->expects($this->once())
->method('find')
- ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->with($this->user, $id)
->will($this->throwException($ex));
$this->activeInitMocks($id, $type);
@@ -374,7 +374,7 @@ class FeedControllerTest extends TestCase
$this->feedService->expects($this->once())
->method('update')
- ->with($this->equalTo(4), $this->equalTo($this->user))
+ ->with($this->equalTo($this->user), $this->equalTo(4))
->will($this->returnValue($feed));
$response = $this->controller->update(4);
@@ -387,7 +387,7 @@ class FeedControllerTest extends TestCase
{
$this->feedService->expects($this->once())
->method('update')
- ->with($this->equalTo(4), $this->equalTo($this->user))
+ ->with($this->equalTo($this->user), $this->equalTo(4))
->will($this->throwException(new ServiceNotFoundException('NO!')));
$response = $this->controller->update(4);
diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php
index 311212169..de62b887a 100644
--- a/tests/Unit/Controller/FolderApiControllerTest.php
+++ b/tests/Unit/Controller/FolderApiControllerTest.php
@@ -20,9 +20,9 @@ use OCA\News\Service\FolderService;
use OCA\News\Service\ItemService;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ServiceNotFoundException;
-use \OCA\News\Service\ServiceConflictException;
-use \OCA\News\Service\ServiceValidationException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceConflictException;
+use \OCA\News\Service\Exceptions\ServiceValidationException;
use \OCA\News\Db\Folder;
use OCP\IRequest;
@@ -38,25 +38,22 @@ class FolderApiControllerTest extends TestCase
private $folderService;
private $itemService;
private $folderAPI;
- private $appName;
- private $userSession;
private $user;
- private $request;
private $msg;
protected function setUp(): void
{
- $this->appName = 'news';
- $this->request = $this->getMockBuilder(IRequest::class)
+ $appName = 'news';
+ $request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
- $this->userSession = $this->getMockBuilder(IUserSession::class)
+ $userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor()
->getMock();
$this->user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
- $this->userSession->expects($this->any())
+ $userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$this->user->expects($this->any())
@@ -69,9 +66,9 @@ class FolderApiControllerTest extends TestCase
->disableOriginalConstructor()
->getMock();
$this->folderAPI = new FolderApiController(
- $this->appName,
- $this->request,
- $this->userSession,
+ $appName,
+ $request,
+ $userSession,
$this->folderService,
$this->itemService
);
diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php
index abe1ebd7a..ea3454656 100644
--- a/tests/Unit/Controller/FolderControllerTest.php
+++ b/tests/Unit/Controller/FolderControllerTest.php
@@ -21,9 +21,9 @@ use \OCP\AppFramework\Http;
use \OCA\News\Db\Folder;
use \OCA\News\Db\Feed;
-use \OCA\News\Service\ServiceNotFoundException;
-use \OCA\News\Service\ServiceConflictException;
-use \OCA\News\Service\ServiceValidationException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceConflictException;
+use \OCA\News\Service\Exceptions\ServiceValidationException;
use OCP\IRequest;
use PHPUnit\Framework\TestCase;
@@ -32,11 +32,9 @@ use PHPUnit\Framework\TestCase;
class FolderControllerTest extends TestCase
{
- private $appName;
private $folderService;
private $itemService;
private $feedService;
- private $request;
private $controller;
private $msg;
@@ -46,7 +44,7 @@ class FolderControllerTest extends TestCase
*/
public function setUp(): void
{
- $this->appName = 'news';
+ $appName = 'news';
$this->user = 'jack';
$this->folderService = $this->getMockBuilder(FolderService::class)
->disableOriginalConstructor()
@@ -57,11 +55,11 @@ class FolderControllerTest extends TestCase
$this->itemService = $this->getMockBuilder(ItemService::class)
->disableOriginalConstructor()
->getMock();
- $this->request = $this->getMockBuilder(IRequest::class)
+ $request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
$this->controller = new FolderController(
- $this->appName, $this->request,
+ $appName, $request,
$this->folderService,
$this->feedService,
$this->itemService,
diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php
index 412b9dd51..1360ad872 100644
--- a/tests/Unit/Controller/ItemApiControllerTest.php
+++ b/tests/Unit/Controller/ItemApiControllerTest.php
@@ -19,7 +19,7 @@ use OCA\News\Controller\ItemApiController;
use OCA\News\Service\ItemService;
use \OCP\AppFramework\Http;
-use \OCA\News\Service\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Db\Item;
use OCP\IRequest;
use OCP\IUser;
diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php
index 9dbcf15ce..a0780cecb 100644
--- a/tests/Unit/Controller/ItemControllerTest.php
+++ b/tests/Unit/Controller/ItemControllerTest.php
@@ -21,7 +21,7 @@ use \OCP\AppFramework\Http;
use \OCA\News\Db\Item;
use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedType;
-use \OCA\News\Service\ServiceNotFoundException;
+use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCP\IConfig;
use OCP\IRequest;
diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php
index 32a66b2e8..127618288 100644
--- a/tests/Unit/Controller/UtilityApiControllerTest.php
+++ b/tests/Unit/Controller/UtilityApiControllerTest.php
@@ -17,7 +17,7 @@ namespace OCA\News\Tests\Unit\Controller;
use OCA\News\Controller\UtilityApiController;
use OCA\News\Service\StatusService;
-use OCA\News\Utility\Updater;
+use OCA\News\Service\UpdaterService;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
@@ -28,21 +28,52 @@ use PHPUnit\Framework\TestCase;
class UtilityApiControllerTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IConfig
+ */
private $settings;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IRequest
+ */
private $request;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IUserSession
+ */
private $userSession;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IUser
+ */
private $user;
+
+ /**
+ * @var UtilityApiController
+ */
private $newsAPI;
- private $updater;
+
+ /**
+ * @var string
+ */
private $appName;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|StatusService
+ */
private $status;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|UpdaterService
+ */
+ private $updateService;
+
protected function setUp(): void
{
$this->appName = 'news';
$this->settings = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
$this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
@@ -55,15 +86,19 @@ class UtilityApiControllerTest extends TestCase
$this->userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $this->updater = $this->getMockBuilder(Updater::class)
+ $this->status = $this->getMockBuilder(StatusService::class)
->disableOriginalConstructor()
->getMock();
- $this->status = $this->getMockBuilder(StatusService::class)
+ $this->updateService = $this->getMockBuilder(UpdaterService::class)
->disableOriginalConstructor()
->getMock();
$this->newsAPI = new UtilityApiController(
- $this->appName, $this->request, $this->userSession,
- $this->updater, $this->settings, $this->status
+ $this->appName,
+ $this->request,
+ $this->userSession,
+ $this->updateService,
+ $this->settings,
+ $this->status
);
}
@@ -87,7 +122,7 @@ class UtilityApiControllerTest extends TestCase
public function testBeforeUpdate()
{
- $this->updater->expects($this->once())
+ $this->updateService->expects($this->once())
->method('beforeUpdate');
$this->newsAPI->beforeUpdate();
}
@@ -95,7 +130,7 @@ class UtilityApiControllerTest extends TestCase
public function testAfterUpdate()
{
- $this->updater->expects($this->once())
+ $this->updateService->expects($this->once())
->method('afterUpdate');
$this->newsAPI->afterUpdate();
}
@@ -103,7 +138,7 @@ class UtilityApiControllerTest extends TestCase
public function testStatus()
{
- $in = 'hi';
+ $in = ['hi'];
$this->status->expects($this->once())
->method('getStatus')
->will($this->returnValue($in));
diff --git a/tests/Unit/Db/FeedTest.php b/tests/Unit/Db/FeedTest.php
index 47595633d..1812b7164 100644
--- a/tests/Unit/Db/FeedTest.php
+++ b/tests/Unit/Db/FeedTest.php
@@ -51,18 +51,19 @@ class FeedTest extends TestCase
$this->assertEquals(
[
- 'id' => 3,
- 'url' => 'http://google.com/some/weird/path',
- 'title' => 'title',
- 'faviconLink' => 'favicon',
- 'added' => 123,
- 'folderId' => 1,
- 'unreadCount' => 321,
- 'ordering' => 2,
- 'pinned' => true,
- 'link' => 'https://www.google.com/some/weird/path',
- 'updateErrorCount' => 2,
- 'lastUpdateError' => 'hi'
+ 'id' => 3,
+ 'url' => 'http://google.com/some/weird/path',
+ 'title' => 'title',
+ 'faviconLink' => 'favicon',
+ 'added' => 123,
+ 'folderId' => 1,
+ 'unreadCount' => 321,
+ 'ordering' => 2,
+ 'pinned' => true,
+ 'link' => 'https://www.google.com/some/weird/path',
+ 'updateErrorCount' => 2,
+ 'lastUpdateError' => 'hi',
+ 'items' => [],
], $feed->toAPI()
);
}
diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php
index f8544da65..deb235ff7 100644
--- a/tests/Unit/Db/FolderMapperTest.php
+++ b/tests/Unit/Db/FolderMapperTest.php
@@ -62,7 +62,7 @@ class FolderMapperTest extends MapperTestUtility
$this->setMapperResult($sql, [$id, $userId], $rows);
- $result = $this->folderMapper->find($id, $userId);
+ $result = $this->folderMapper->find($userId, $id);
$this->assertEquals($this->folders[0], $result);
}
@@ -79,7 +79,7 @@ class FolderMapperTest extends MapperTestUtility
$this->setMapperResult($sql, [$id, $userId]);
$this->expectException(DoesNotExistException::class);
- $this->folderMapper->find($id, $userId);
+ $this->folderMapper->find($userId, $id);
}
@@ -95,7 +95,7 @@ class FolderMapperTest extends MapperTestUtility
$this->setMapperResult($sql, [$id, $userId], $rows);
$this->expectException(MultipleObjectsReturnedException::class);
- $this->folderMapper->find($id, $userId);
+ $this->folderMapper->find($userId, $id);
}
diff --git a/tests/Unit/Db/FolderTest.php b/tests/Unit/Db/FolderTest.php
index a3445ea2e..7fdb1ae07 100644
--- a/tests/Unit/Db/FolderTest.php
+++ b/tests/Unit/Db/FolderTest.php
@@ -20,7 +20,7 @@ class FolderTest extends TestCase
{
- public function testToAPI()
+ public function testToAPI()
{
$folder = new Folder();
$folder->setId(3);
@@ -28,14 +28,15 @@ class FolderTest extends TestCase
$this->assertEquals(
[
- 'id' => 3,
- 'name' => 'name'
+ 'id' => 3,
+ 'name' => 'name',
+ 'feeds' => [],
], $folder->toAPI()
);
}
- public function testSerialize()
+ public function testSerialize()
{
$folder = new Folder();
$folder->setId(3);
diff --git a/tests/Unit/Db/MapperFactoryTest.php b/tests/Unit/Db/MapperFactoryTest.php
index 97680e20b..1c4e2f4b6 100644
--- a/tests/Unit/Db/MapperFactoryTest.php
+++ b/tests/Unit/Db/MapperFactoryTest.php
@@ -26,8 +26,10 @@ use OCA\News\Db\Mysql\ItemMapper as MysqlMapper;
class MapperFactoryTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection
+ */
private $db;
- private $settings;
public function setUp(): void
{
diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php
index 6360973de..38a7c2f61 100644
--- a/tests/Unit/Fetcher/FeedFetcherTest.php
+++ b/tests/Unit/Fetcher/FeedFetcherTest.php
@@ -14,18 +14,22 @@
namespace OCA\News\Tests\Unit\Fetcher;
use DateTime;
+use Favicon\Favicon;
+use FeedIo\Adapter\ResponseInterface;
use FeedIo\Feed\Item\Author;
use FeedIo\Feed\Item\MediaInterface;
use FeedIo\Feed\ItemInterface;
use FeedIo\FeedInterface;
+use FeedIo\FeedIo;
+use FeedIo\Reader\Result;
use OC\L10N\L10N;
use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
use OCA\News\Scraper\Scraper;
use OCA\News\Fetcher\FeedFetcher;
-use OCA\News\Utility\PsrLogger;
-use OCP\ILogger;
+use OCA\News\Utility\Time;
+use OCP\IL10N;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -46,26 +50,26 @@ class FeedFetcherTest extends TestCase
/**
* Feed reader
*
- * @var \FeedIo\FeedIo
+ * @var FeedIo
*/
private $reader;
/**
* Feed reader result
*
- * @var \FeedIo\Reader\Result
+ * @var Result
*/
private $result;
/**
* Feed reader result object
*
- * @var \FeedIo\Adapter\ResponseInterface
+ * @var ResponseInterface
*/
private $response;
/**
- * @var \Favicon\Favicon
+ * @var Favicon
*/
private $favicon;
@@ -132,32 +136,32 @@ class FeedFetcherTest extends TestCase
protected function setUp(): void
{
- $this->l10n = $this->getMockBuilder(\OCP\IL10N::class)
+ $this->l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()
->getMock();
- $this->reader = $this->getMockBuilder(\FeedIo\FeedIo::class)
+ $this->reader = $this->getMockBuilder(FeedIo::class)
->disableOriginalConstructor()
->getMock();
- $this->favicon = $this->getMockBuilder(\Favicon\Favicon::class)
+ $this->favicon = $this->getMockBuilder(Favicon::class)
->disableOriginalConstructor()
->getMock();
- $this->result = $this->getMockBuilder(\FeedIo\Reader\Result::class)
+ $this->result = $this->getMockBuilder(Result::class)
->disableOriginalConstructor()
->getMock();
- $this->response = $this->getMockBuilder(\FeedIo\Adapter\ResponseInterface::class)
+ $this->response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
- $this->item_mock = $this->getMockBuilder(\FeedIo\Feed\ItemInterface::class)
+ $this->item_mock = $this->getMockBuilder(ItemInterface::class)
->disableOriginalConstructor()
->getMock();
- $this->feed_mock = $this->getMockBuilder(\FeedIo\FeedInterface::class)
+ $this->feed_mock = $this->getMockBuilder(FeedInterface::class)
->disableOriginalConstructor()
->getMock();
$this->time = 2323;
- $timeFactory = $this->getMockBuilder(\OCA\News\Utility\Time::class)
+ $timeFactory = $this->getMockBuilder(Time::class)
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php
index 84c2121ed..f93a1e286 100644
--- a/tests/Unit/Service/FeedServiceTest.php
+++ b/tests/Unit/Service/FeedServiceTest.php
@@ -20,7 +20,7 @@ use OC\L10N\L10N;
use OCA\News\Db\FeedMapper;
use OCA\News\Db\ItemMapper;
use OCA\News\Service\FeedService;
-use OCA\News\Service\ServiceNotFoundException;
+use OCA\News\Service\Exceptions\ServiceNotFoundException;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -30,9 +30,9 @@ use OCA\News\Fetcher\Fetcher;
use OCA\News\Fetcher\FetcherException;
use OCP\IConfig;
use OCP\IL10N;
-use OCP\ILogger;
use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
class FeedServiceTest extends TestCase
@@ -82,16 +82,15 @@ class FeedServiceTest extends TestCase
private $l10n;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|ILogger
+ * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface
*/
private $logger;
protected function setUp(): void
{
- $this->logger = $this->getMockBuilder(ILogger::class)
+ $this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
- $loggerParams = ['hi'];
$this->time = 222;
$this->autoPurgeMinimumInterval = 10;
$timeFactory = $this->getMockBuilder(Time::class)
@@ -130,7 +129,7 @@ class FeedServiceTest extends TestCase
$this->feedService = new FeedService(
$this->feedMapper,
$this->fetcher, $this->itemMapper, $this->logger, $this->l10n,
- $timeFactory, $config, $this->purifier, $loggerParams
+ $timeFactory, $config, $this->purifier
);
$this->user = 'jack';
}
@@ -140,12 +139,13 @@ class FeedServiceTest extends TestCase
*/
public function testFindAll()
{
+ $this->response = [];
$this->feedMapper->expects($this->once())
->method('findAllFromUser')
->with($this->user)
->will($this->returnValue([]));
- $result = $this->feedService->findAll($this->user);
+ $result = $this->feedService->findAllForUser($this->user);
$this->assertEquals([], $result);
}
@@ -199,10 +199,14 @@ class FeedServiceTest extends TestCase
$this->feedMapper->expects($this->once())
->method('insert')
->with($this->equalTo($createdFeed))
- ->will($this->returnCallback(function() use ($createdFeed) {
- $createdFeed->setId(4);
- return $createdFeed;
- }));
+ ->will(
+ $this->returnCallback(
+ function () use ($createdFeed) {
+ $createdFeed->setId(4);
+ return $createdFeed;
+ }
+ )
+ );
$this->itemMapper->expects($this->at(0))
->method('findByGuidHash')
->with(
@@ -281,10 +285,14 @@ class FeedServiceTest extends TestCase
$this->feedMapper->expects($this->once())
->method('insert')
->with($this->equalTo($createdFeed))
- ->will($this->returnCallback(function() use ($createdFeed) {
- $createdFeed->setId(5);
- return $createdFeed;
- }));
+ ->will(
+ $this->returnCallback(
+ function () use ($createdFeed) {
+ $createdFeed->setId(5);
+ return $createdFeed;
+ }
+ )
+ );
$this->itemMapper->expects($this->at(0))
->method('findByGuidHash')
->with(
@@ -358,10 +366,7 @@ class FeedServiceTest extends TestCase
$this->feedMapper->expects($this->at(0))
->method('find')
- ->with(
- $this->equalTo($feed->getId()),
- $this->equalTo($this->user)
- )
+ ->with($this->user, $feed->getId())
->will($this->returnValue($feed));
$this->fetcher->expects($this->once())
->method('fetch')
@@ -394,11 +399,11 @@ class FeedServiceTest extends TestCase
$this->feedMapper->expects($this->at(2))
->method('find')
<