diff options
Diffstat (limited to 'tests/Unit/Controller')
-rw-r--r-- | tests/Unit/Controller/FeedApiControllerTest.php | 36 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedControllerTest.php | 16 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderApiControllerTest.php | 23 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderControllerTest.php | 14 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/UtilityApiControllerTest.php | 57 |
7 files changed, 88 insertions, 62 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)); |