diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-08-29 23:39:35 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-27 15:35:31 +0200 |
commit | d00d1ab2a28f428223e52b17052c072c64784016 (patch) | |
tree | c019f85fb7ac67147dd43ca64b4ac3cda99832f7 /tests/Unit/Service | |
parent | 5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff) |
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Service')
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 168 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 30 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 59 | ||||
-rw-r--r-- | tests/Unit/Service/ServiceTest.php | 39 | ||||
-rw-r--r-- | tests/Unit/Service/UpdaterTest.php | 86 |
5 files changed, 258 insertions, 124 deletions
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') - ->with($feed->getId(), $this->user) + ->with($this->user, $feed->getId()) ->will($this->returnValue($feed)); - $return = $this->feedService->update($feed->getId(), $this->user); + $return = $this->feedService->update($this->user, $feed->getId()); $this->assertEquals($return, $feed); } @@ -425,10 +430,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') @@ -461,11 +463,11 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->at(2)) ->method('find') - ->with($feed->getId(), $this->user) + ->with($this->user, $feed->getId()) ->will($this->returnValue($feed)); - $return = $this->feedService->update($feed->getId(), $this->user, true); + $return = $this->feedService->update($this->user, $feed->getId(), true); $this->assertEquals($return, $feed); } @@ -543,7 +545,7 @@ class FeedServiceTest extends TestCase ->will($this->returnValue($feed)); - $return = $this->feedService->update($feed->getId(), $this->user); + $return = $this->feedService->update($this->user, $feed->getId()); $this->assertEquals($return, $feed); } @@ -583,7 +585,7 @@ class FeedServiceTest extends TestCase ->method('find') ->will($this->returnValue($feed)); - $return = $this->feedService->update($feed->getId(), $this->user); + $return = $this->feedService->update($this->user, $feed->getId()); $this->assertEquals($return, $feed); @@ -622,7 +624,7 @@ class FeedServiceTest extends TestCase ->method('findByGuidHash') ->will($this->returnValue($item)); - $this->feedService->update($feed->getId(), $this->user); + $this->feedService->update($this->user, $feed->getId()); } public function testUpdateFails() @@ -643,10 +645,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') @@ -661,10 +660,10 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->at(2)) ->method('find') - ->with($feed->getId(), $this->user) + ->with($this->user, $feed->getId()) ->will($this->returnValue($exptectedFeed)); - $return = $this->feedService->update($feed->getId(), $this->user); + $return = $this->feedService->update($this->user, $feed->getId()); $this->assertEquals($return, $exptectedFeed); } @@ -679,14 +678,11 @@ 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->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->feedService->update($feed->getId(), $this->user); + $this->feedService->update($this->user, $feed->getId()); } @@ -702,10 +698,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()) @@ -719,7 +712,7 @@ class FeedServiceTest extends TestCase ->will($this->throwException($ex)); $this->expectException(DoesNotExistException::class); - $this->feedService->update($feed->getId(), $this->user); + $this->feedService->update($this->user, $feed->getId()); } @@ -744,10 +737,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->feedMapper->expects($this->at(1)) ->method('update') @@ -766,14 +756,11 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->at(2)) ->method('find') - ->with( - $this->equalTo($feed->getId()), - $this->equalTo($this->user) - ) + ->with($this->user, $feed->getId()) ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->feedService->update($feed->getId(), $this->user); + $this->feedService->update($this->user, $feed->getId()); } @@ -787,15 +774,12 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with( - $this->equalTo($feedId), - $this->equalTo($this->user) - ) + ->with($this->user, $feed->getId()) ->will($this->returnValue($feed)); $this->fetcher->expects($this->never()) ->method('fetch'); - $this->feedService->update($feedId, $this->user); + $this->feedService->update($this->user, $feedId); } @@ -809,16 +793,13 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with( - $this->equalTo($feedId), - $this->equalTo($this->user) - ) + ->with($this->user, $feed->getId()) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') ->will($this->returnValue([null, null])); - $return = $this->feedService->update($feedId, $this->user); + $return = $this->feedService->update($this->user, $feedId); $this->assertEquals($feed, $return); } @@ -833,14 +814,16 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feedId), $this->equalTo($this->user)) + ->with($this->user, $feedId) ->will($this->returnValue($feed)); $this->feedMapper->expects($this->once()) ->method('update') ->with($this->equalTo($feed)); - $this->feedService->patch($feedId, $this->user, ['folderId' => $folderId]); + $this->feedService->patch( + $feedId, $this->user, ['folderId' => $folderId] + ); $this->assertEquals($folderId, $feed->getFolderId()); } @@ -856,14 +839,16 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feedId), $this->equalTo($this->user)) + ->with($this->equalTo($this->user), $this->equalTo($feedId)) ->will($this->returnValue($feed)); $this->feedMapper->expects($this->once()) ->method('update') ->with($this->equalTo($feed)); - $this->feedService->patch($feedId, $this->user, ['title' => $feedTitle]); + $this->feedService->patch( + $feedId, $this->user, ['title' => $feedTitle] + ); $this->assertEquals($feedTitle, $feed->getTitle()); } @@ -982,10 +967,14 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('insert') ->with($this->equalTo($insertFeed)) - ->will($this->returnCallback(function() use ($insertFeed) { - $insertFeed->setId(3); - return $insertFeed; - })); + ->will( + $this->returnCallback( + function () use ($insertFeed) { + $insertFeed->setId(3); + return $insertFeed; + } + ) + ); $this->itemMapper->expects($this->at(0)) @@ -1025,7 +1014,7 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($this->user)) + ->with($this->equalTo($this->user), $this->equalTo($id)) ->will($this->returnValue($feed)); $this->feedMapper->expects($this->once()) ->method('update') @@ -1044,7 +1033,7 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($this->user)) + ->with($this->equalTo($this->user), $this->equalTo($id)) ->will($this->returnValue($feed)); $this->feedMapper->expects($this->once()) ->method('update') @@ -1103,7 +1092,7 @@ class FeedServiceTest extends TestCase public function testfindAllFromAllUsers() { - $expected = 'hi'; + $expected = ['hi']; $this->feedMapper->expects($this->once()) ->method('findAll') ->will($this->returnValue($expected)); @@ -1128,8 +1117,8 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->once()) ->method('find') ->with( - $this->equalTo($feed->getId()), - $this->equalTo($this->user) + $this->equalTo($this->user), + $this->equalTo($feed->getId()) ) ->will($this->returnValue($feed)); @@ -1146,18 +1135,18 @@ class FeedServiceTest extends TestCase { $feed = Feed::fromRow( [ - 'id' => 3, - 'http_etag' => 'a', - 'http_last_modified' => 1, - 'full_text_enabled' => false + 'id' => 3, + 'http_etag' => 'a', + 'http_last_modified' => 1, + 'full_text_enabled' => false ] ); $feed2 = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->at(0)) ->method('find') ->with( - $this->equalTo($feed->getId()), - $this->equalTo($this->user) + $this->equalTo($this->user), + $this->equalTo($feed->getId()) ) ->will($this->returnValue($feed)); @@ -1171,8 +1160,8 @@ class FeedServiceTest extends TestCase $this->feedMapper->expects($this->at(2)) ->method('find') ->with( - $this->equalTo($feed->getId()), - $this->equalTo($this->user) + $this->equalTo($this->user), + $this->equalTo($feed->getId()) ) ->will($this->throwException(new DoesNotExistException(''))); @@ -1183,7 +1172,7 @@ class FeedServiceTest extends TestCase public function testPatchDoesNotExist() { - $this->expectException('OCA\News\Service\ServiceNotFoundException'); + $this->expectException('OCA\News\Service\Exceptions\ServiceNotFoundException'); $feed = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->once()) ->method('find') @@ -1198,10 +1187,7 @@ class FeedServiceTest extends TestCase $feed = Feed::fromRow(['id' => 3, 'pinned' => false]); $this->feedMapper->expects($this->once()) ->method('find') - ->with( - $this->equalTo($feed->getId()), - $this->equalTo($this->user) - ) + ->with($this->user, $feed->getId()) ->will($this->returnValue($feed)); $feed->setPinned(true); diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 4086f55e1..deca27f08 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -17,13 +17,14 @@ use OC\L10N\L10N; use \OCA\News\Db\Folder; use OCA\News\Db\FolderMapper; use OCA\News\Service\FolderService; -use OCA\News\Service\ServiceConflictException; -use OCA\News\Service\ServiceValidationException; +use OCA\News\Service\Exceptions\ServiceConflictException; +use OCA\News\Service\Exceptions\ServiceValidationException; use OCA\News\Utility\Time; use OCP\IConfig; use OCP\IL10N; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; class FolderServiceTest extends TestCase @@ -50,6 +51,11 @@ class FolderServiceTest extends TestCase private $user; /** + * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + */ + private $logger; + + /** * @var int */ private $autoPurgeMinimumInterval; @@ -78,12 +84,15 @@ class FolderServiceTest extends TestCase $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); $config->expects($this->any()) ->method('getAppValue') ->with('news', 'autoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->folderService = new FolderService( - $this->folderMapper, $this->l10n, $timeFactory, $config + $this->folderMapper, $this->l10n, $timeFactory, $config, $this->logger ); $this->user = 'hi'; } @@ -92,13 +101,13 @@ class FolderServiceTest extends TestCase public function testFindAll() { $userId = 'jack'; - $return = 'hi'; + $return = []; $this->folderMapper->expects($this->once()) ->method('findAllFromUser') ->with($this->equalTo($userId)) ->will($this->returnValue($return)); - $result = $this->folderService->findAll($userId); + $result = $this->folderService->findAllForUser($userId); $this->assertEquals($return, $result); } @@ -146,8 +155,7 @@ class FolderServiceTest extends TestCase public function testCreateThrowsExWhenFolderNameEmpty() { - $this->expectException('OCA\News\Service\ServiceValidationException'); - + $this->expectException('\OCA\News\Service\Exceptions\ServiceValidationException'); $folderName = ''; $this->folderMapper->expects($this->once()) @@ -165,7 +173,7 @@ class FolderServiceTest extends TestCase $this->folderMapper->expects($this->once()) ->method('find') - ->with($this->equalTo(3)) + ->with('', 3) ->will($this->returnValue($folder)); $this->folderMapper->expects($this->once()) @@ -186,7 +194,7 @@ class FolderServiceTest extends TestCase $this->folderMapper->expects($this->once()) ->method('find') - ->with($this->equalTo(3)) + ->with('', 3) ->will($this->returnValue($folder)); $this->folderMapper->expects($this->once()) @@ -244,7 +252,7 @@ class FolderServiceTest extends TestCase $this->folderMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($this->user)) + ->with($this->equalTo($this->user), $this->equalTo($id)) ->will($this->returnValue($folder)); $this->folderMapper->expects($this->once()) ->method('update') @@ -263,7 +271,7 @@ class FolderServiceTest extends TestCase $this->folderMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($this->user)) + ->with($this->equalTo($this->user), $this->equalTo($id)) ->will($this->returnValue($folder)); $this->folderMapper->expects($this->once()) ->method('update') diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index e56add152..c98ac2c33 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -13,9 +13,11 @@ namespace OCA\News\Tests\Unit\Service; +use OC\Log; use OCA\News\Db\ItemMapper; use OCA\News\Service\ItemService; -use OCA\News\Service\ServiceNotFoundException; +use OCA\News\Service\Exceptions\ServiceNotFoundException; +use OCA\News\Utility\PsrLogger; use OCA\News\Utility\Time; use \OCP\AppFramework\Db\DoesNotExistException; @@ -24,6 +26,7 @@ use \OCA\News\Db\FeedType; use OCP\IConfig; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; class ItemServiceTest extends TestCase @@ -39,14 +42,30 @@ class ItemServiceTest extends TestCase private $itemService; /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ + private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + */ + private $logger; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|Time + */ + private $timeFactory; + + /** * @var int */ - private $time; + private $newestItemId; /** - * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + * @var int */ - private $config; + private $time; + protected function setUp(): void { @@ -66,7 +85,24 @@ class ItemServiceTest extends TestCase $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->itemService = new ItemService($this->mapper, $this->timeFactory, $this->config); + + $this->logger = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->itemService = new ItemService( + $this->mapper, + $this->timeFactory, + $this->config, + $this->logger + ); + $this->user = 'jack'; + $this->id = 3; + $this->updatedSince = 20333; + $this->showAll = true; + $this->offset = 5; + $this->limit = 20; + $this->newestItemId = 4; } @@ -143,7 +179,7 @@ class ItemServiceTest extends TestCase ) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAll( + $result = $this->itemService->findAllItems( 3, $type, 20, 5, true, false, 'jack' ); @@ -167,7 +203,7 @@ class ItemServiceTest extends TestCase ) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAll( + $result = $this->itemService->findAllItems( 3, $type, 20, 5, true, true, 'jack' ); @@ -179,7 +215,7 @@ class ItemServiceTest extends TestCase { $type = FeedType::STARRED; $this->mapper->expects($this->once()) - ->method('findAll') + ->method('findAllItems') ->with( $this->equalTo(20), $this->equalTo(5), @@ -191,7 +227,7 @@ class ItemServiceTest extends TestCase ) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAll( + $result = $this->itemService->findAllItems( 3, $type, 20, 5, true, true, 'jack' ); @@ -203,8 +239,9 @@ class ItemServiceTest extends TestCase { $type = FeedType::STARRED; $search = ['test']; + $this->mapper->expects($this->once()) - ->method('findAll') + ->method('findAllItems') ->with( $this->equalTo(20), $this->equalTo(5), @@ -216,7 +253,7 @@ class ItemServiceTest extends TestCase ) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAll( + $result = $this->itemService->findAllItems( 3, $type, 20, 5, true, true, 'jack', $search ); diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index 8f601be46..e243efb3f 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -13,21 +13,33 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Db\Feed; use OCA\News\Db\ItemMapper; +use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\Service; -use OCA\News\Service\ServiceNotFoundException; use \OCP\AppFramework\Db\DoesNotExistException; use \OCP\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; -class TestService extends Service +class TestLegacyService extends Service { - public function __construct($mapper) + public function __construct($mapper, $logger) { - parent::__construct($mapper); + parent::__construct($mapper, $logger); + } + + public function findAllForUser(string $userId): array + { + // TODO: Implement findAllForUser() method. + } + + public function findAll(): array + { + // TODO: Implement findAll() method. } } @@ -35,6 +47,7 @@ class ServiceTest extends TestCase { protected $mapper; + protected $logger; protected $newsService; protected function setUp(): void @@ -42,7 +55,10 @@ class ServiceTest extends TestCase $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); - $this->newsService = new TestService($this->mapper); + $this->logger = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->newsService = new TestLegacyService($this->mapper, $this->logger); } @@ -58,10 +74,10 @@ class ServiceTest extends TestCase ->with($this->equalTo($folder)); $this->mapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($user)) + ->with($this->equalTo($user), $this->equalTo($id)) ->will($this->returnValue($folder)); - $this->newsService->delete($id, $user); + $this->newsService->delete($user, $id); } @@ -72,9 +88,10 @@ class ServiceTest extends TestCase $this->mapper->expects($this->once()) ->method('find') - ->with($this->equalTo($id), $this->equalTo($user)); + ->with($this->equalTo($user), $this->equalTo($id)) + ->will($this->returnValue(new Feed())); - $this->newsService->find($id, $user); + $this->newsService->find($user, $id); } @@ -87,7 +104,7 @@ class ServiceTest extends TestCase ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->newsService->find(1, ''); + $this->newsService->find('', 1); } @@ -100,7 +117,7 @@ class ServiceTest extends TestCase ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->newsService->find(1, ''); + $this->newsService->find('', 1); } } diff --git a/tests/Unit/Service/UpdaterTest.php b/tests/Unit/Service/UpdaterTest.php new file mode 100644 index 000000000..b4be0a7cc --- /dev/null +++ b/tests/Unit/Service/UpdaterTest.php @@ -0,0 +1,86 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt + */ + +namespace OCA\News\Tests\Unit\Service; + +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +use OCA\News\Service\ItemServiceV2; +use OCA\News\Service\UpdaterService; +use PHPUnit\Framework\TestCase; + +class UpdaterTest extends TestCase +{ + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FolderServiceV2 + */ + private $folderService; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FeedServiceV2 + */ + private $feedService; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemServiceV2 + */ + private $itemService; + + /** + * @var UpdaterService + */ + private $updater; + + protected function setUp(): void + { + $this->folderService = $this->getMockBuilder(FolderServiceV2::class) + ->disableOriginalConstructor() + ->getMock(); + $this->feedService = $this->getMockBuilder(Fe |