diff options
author | Daniel Opitz <git@copynpaste.de> | 2018-10-16 22:37:48 +0200 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2018-12-04 17:10:46 +0100 |
commit | e158cc1d3b1fb33de5aaa1aaac0c7828016fb7b9 (patch) | |
tree | 4d3b4da643a428f259ca9fe1c63d97f8cecfb5fc /tests/Unit/Service | |
parent | 5c7fdb08534018ba86ec4a38f45b63cbbf67a72f (diff) |
use magic class constant instead of classname strings
Diffstat (limited to 'tests/Unit/Service')
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 47 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 30 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 29 | ||||
-rw-r--r-- | tests/Unit/Service/ServiceTest.php | 12 | ||||
-rw-r--r-- | tests/Unit/Service/StatusServiceTest.php | 13 |
5 files changed, 56 insertions, 75 deletions
diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index fd3dd1805..8cdc50c88 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -14,13 +14,20 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Config\Config; +use OCA\News\Db\FeedMapper; +use OCA\News\Db\ItemMapper; use OCA\News\Service\FeedService; +use OCA\News\Service\ServiceNotFoundException; +use OCA\News\Utility\Time; use OCP\AppFramework\Db\DoesNotExistException; use OCA\News\Db\Feed; use OCA\News\Db\Item; use OCA\News\Fetcher\Fetcher; use OCA\News\Fetcher\FetcherException; +use OCP\IL10N; +use OCP\ILogger; use PHPUnit\Framework\TestCase; @@ -46,42 +53,38 @@ class FeedServiceTest extends TestCase protected function setUp() { - $this->logger = $this->getMockBuilder( - '\OCP\ILogger' - ) + $this->logger = $this->getMockBuilder(ILogger::class) ->disableOriginalConstructor() ->getMock(); $this->loggerParams = ['hi']; $this->time = 222; $this->autoPurgeMinimumInterval = 10; - $timeFactory = $this->getMockBuilder('\OCA\News\Utility\Time') + $timeFactory = $this->getMockBuilder(Time::class) ->disableOriginalConstructor() ->getMock(); $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->l10n = $this->getMockBuilder('\OCP\IL10N') + $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); $this->feedMapper = $this - ->getMockBuilder('\OCA\News\Db\FeedMapper') + ->getMockBuilder(FeedMapper::class) ->disableOriginalConstructor() ->getMock(); $this->fetcher = $this - ->getMockBuilder('\OCA\News\Fetcher\Fetcher') + ->getMockBuilder(Fetcher::class) ->disableOriginalConstructor() ->getMock(); $this->itemMapper = $this - ->getMockBuilder('\OCA\News\Db\ItemMapper') + ->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); $this->purifier = $this - ->getMockBuilder('\HTMLPurifier') + ->getMockBuilder(\HTMLPurifier::class) ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder( - '\OCA\News\Config\Config' - ) + $config = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) @@ -117,9 +120,7 @@ class FeedServiceTest extends TestCase ->method('fetch') ->with($this->equalTo($url)) ->will($this->throwException($ex)); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->feedService->create($url, 1, $this->user); } @@ -624,9 +625,7 @@ class FeedServiceTest extends TestCase ) ->will($this->throwException($ex)); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->feedService->update($feed->getId(), $this->user); } @@ -661,9 +660,7 @@ class FeedServiceTest extends TestCase ) ->will($this->throwException($ex)); - $this->expectException( - 'OCP\AppFramework\Db\DoesNotExistException' - ); + $this->expectException(DoesNotExistException::class); $this->feedService->update($feed->getId(), $this->user); } @@ -717,9 +714,7 @@ class FeedServiceTest extends TestCase ) ->will($this->throwException($ex)); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->feedService->update($feed->getId(), $this->user); } @@ -1123,9 +1118,7 @@ class FeedServiceTest extends TestCase ) ->will($this->throwException(new DoesNotExistException(''))); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->feedService->patch(3, $this->user, ['fullTextEnabled' => true]); } diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 88d594835..47c1c9a8d 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -13,8 +13,14 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Config\Config; 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\Utility\Time; +use OCP\IL10N; use PHPUnit\Framework\TestCase; @@ -31,25 +37,21 @@ class FolderServiceTest extends TestCase protected function setUp() { - $this->l10n = $this->getMockBuilder('\OCP\IL10N') + $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); $this->time = 222; - $timeFactory = $this->getMockBuilder('\OCA\News\Utility\Time') + $timeFactory = $this->getMockBuilder(Time::class) ->disableOriginalConstructor() ->getMock(); $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->folderMapper = $this->getMockBuilder( - '\OCA\News\Db\FolderMapper' - ) + $this->folderMapper = $this->getMockBuilder(FolderMapper::class) ->disableOriginalConstructor() ->getMock(); $this->autoPurgeMinimumInterval = 10; - $config = $this->getMockBuilder( - '\OCA\News\Config\Config' - ) + $config = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) @@ -113,9 +115,7 @@ class FolderServiceTest extends TestCase ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->expectException( - '\OCA\News\Service\ServiceConflictException' - ); + $this->expectException(ServiceConflictException::class); $this->folderService->create($folderName, 'john', 3); } @@ -192,9 +192,7 @@ class FolderServiceTest extends TestCase ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->expectException( - '\OCA\News\Service\ServiceConflictException' - ); + $this->expectException(ServiceConflictException::class); $this->folderService->rename(3, $folderName, 'john'); } @@ -208,9 +206,7 @@ class FolderServiceTest extends TestCase ->with($this->equalTo($folderName)) ->will($this->returnValue([])); - $this->expectException( - '\OCA\News\Service\ServiceValidationException' - ); + $this->expectException(ServiceValidationException::class); $this->folderService->rename(3, $folderName, 'john'); } diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 0ef5ce366..9a89d2e1a 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -13,11 +13,16 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Config\Config; +use OCA\News\Db\ItemMapper; use OCA\News\Service\ItemService; +use OCA\News\Service\ServiceNotFoundException; +use OCA\News\Utility\Time; use \OCP\AppFramework\Db\DoesNotExistException; use \OCA\News\Db\Item; use \OCA\News\Db\FeedType; +use OCP\IConfig; use PHPUnit\Framework\TestCase; @@ -41,7 +46,7 @@ class ItemServiceTest extends TestCase protected function setUp() { $this->time = 222; - $this->timeFactory = $this->getMockBuilder('\OCA\News\Utility\Time') + $this->timeFactory = $this->getMockBuilder(Time::class) ->disableOriginalConstructor() ->getMock(); $this->timeFactory->expects($this->any()) @@ -50,17 +55,13 @@ class ItemServiceTest extends TestCase $this->timeFactory->expects($this->any()) ->method('getMicroTime') ->will($this->returnValue($this->time)); - $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') + $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config' - ) + $this->config = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); - $this->systemConfig = $this->getMockBuilder( - 'OCP\IConfig' - ) + $this->systemConfig = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = new ItemService( @@ -339,9 +340,7 @@ class ItemServiceTest extends TestCase public function testReadDoesNotExist() { - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->mapper->expects($this->once()) ->method('readItem') ->will($this->throwException(new DoesNotExistException(''))); @@ -352,9 +351,7 @@ class ItemServiceTest extends TestCase public function testStarDoesNotExist() { - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->mapper->expects($this->once()) ->method('findByGuidHash') ->will($this->throwException(new DoesNotExistException(''))); @@ -462,9 +459,7 @@ class ItemServiceTest extends TestCase ) ); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->itemService->getNewestItemId($this->user); } diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index 39f81843c..eb1898290 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -13,7 +13,9 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Db\ItemMapper; use OCA\News\Service\Service; +use OCA\News\Service\ServiceNotFoundException; use \OCP\AppFramework\Db\DoesNotExistException; use \OCP\AppFramework\Db\MultipleObjectsReturnedException; @@ -37,7 +39,7 @@ class ServiceTest extends TestCase protected function setUp() { - $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') + $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); $this->newsService = new TestService($this->mapper); @@ -84,9 +86,7 @@ class ServiceTest extends TestCase ->method('find') ->will($this->throwException($ex)); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->newsService->find(1, ''); } @@ -99,9 +99,7 @@ class ServiceTest extends TestCase ->method('find') ->will($this->throwException($ex)); - $this->expectException( - '\OCA\News\Service\ServiceNotFoundException' - ); + $this->expectException(ServiceNotFoundException::class); $this->newsService->find(1, ''); } diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index 56423a9c6..8c42997a0 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.php @@ -13,8 +13,11 @@ namespace OCA\News\Tests\Unit\Service; +use OCA\News\Config\Config; use \OCA\News\Db\FeedType; use OCA\News\Service\StatusService; +use OCP\IConfig; +use OCP\IDBConnection; use PHPUnit\Framework\TestCase; @@ -29,17 +32,13 @@ class StatusServiceTest extends TestCase public function setUp() { $this->appName = 'news'; - $this->settings = $this->getMockBuilder( - '\OCP\IConfig' - ) + $this->settings = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config' - ) + $this->config = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); - $this->db = $this->getMockBuilder("\OCP\IDBConnection") + $this->db = $this->getMockBuilder(IDBConnection::class) ->disableOriginalConstructor() ->getMock(); $this->service = new StatusService( |