From 66c73a96ac2dda076bcfe0dc0a1ca2a7e169149d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 21 Oct 2014 18:19:23 +0200 Subject: first try to set indention limit at 80 characters in php --- tests/classloader.php | 11 ++- .../articleenhancer/GlobalArticleEnhancerTest.php | 18 +++- .../articleenhancer/XPathArticleEnhancerTest.php | 18 +++- tests/unit/config/ConfigTest.php | 60 ++++++------ tests/unit/controller/ExportControllerTest.php | 5 +- tests/unit/controller/FeedApiControllerTest.php | 16 +++- tests/unit/controller/FeedControllerTest.php | 21 ++-- tests/unit/controller/FolderApiControllerTest.php | 32 +++++-- tests/unit/controller/FolderControllerTest.php | 14 ++- tests/unit/controller/ItemApiControllerTest.php | 16 +++- tests/unit/controller/ItemControllerTest.php | 2 +- tests/unit/controller/PageControllerTest.php | 8 +- tests/unit/controller/UtilityApiControllerTest.php | 5 +- tests/unit/db/FeedMapperTest.php | 79 ++++++++------- tests/unit/db/FolderMapperTest.php | 12 ++- tests/unit/db/ItemMapperTest.php | 106 +++++++++++---------- tests/unit/db/MapperFactoryTest.php | 3 +- tests/unit/db/postgres/ItemMapperTest.php | 2 +- tests/unit/fetcher/FeedFetcherTest.php | 6 +- tests/unit/http/TextDownloadResponseTest.php | 4 +- tests/unit/service/FeedServiceTest.php | 35 +++++-- tests/unit/service/FolderServiceTest.php | 16 +++- tests/unit/service/ItemServiceTest.php | 12 ++- tests/unit/service/ServiceTest.php | 8 +- tests/unit/utility/FaviconFetcherTest.php | 6 +- tests/unit/utility/OPMLExporterTest.php | 37 ++++--- 26 files changed, 355 insertions(+), 197 deletions(-) (limited to 'tests') diff --git a/tests/classloader.php b/tests/classloader.php index c660057df..7992b1b23 100644 --- a/tests/classloader.php +++ b/tests/classloader.php @@ -14,20 +14,25 @@ require_once __DIR__ . '/../3rdparty/ZendXml/vendor/autoload.php'; require_once __DIR__ . '/../3rdparty/simplepie/autoloader.php'; require_once __DIR__ . '/../3rdparty/Net_URL2/Net/URL2.php'; -require_once __DIR__ . '/../../../tests/lib/appframework/db/mappertestutility.php'; +require_once + __DIR__ . '/../../../tests/lib/appframework/db/mappertestutility.php'; // to execute without owncloud, we need to create our own classloader spl_autoload_register(function ($className){ if (strpos($className, 'OCA\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + $path = strtolower( + str_replace('\\', '/', substr($className, 3)) . '.php' + ); $relPath = __DIR__ . '/../..' . $path; if(file_exists($relPath)){ require_once $relPath; } } else if(strpos($className, 'OCP\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + $path = strtolower( + str_replace('\\', '/', substr($className, 3)) . '.php' + ); $relPath = __DIR__ . '/../../../lib/public' . $path; if(file_exists($relPath)){ diff --git a/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php index 3add03eb5..79647a882 100644 --- a/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php @@ -26,8 +26,12 @@ class GlobalArticleEnhancerTest extends \PHPUnit_Framework_TestCase { public function testNoReplaceYoutubeAutoplay() { - $body = ''; - $expected = '
'; + $body = ''; + $expected = '
'; $item = new Item(); $item->setBody($body); @@ -37,8 +41,14 @@ class GlobalArticleEnhancerTest extends \PHPUnit_Framework_TestCase { public function testReplaceYoutubeAutoplay() { - $body = 'test '; - $expected = '
test
'; + $body = 'test '; + $expected = '
test
'; $item = new Item(); $item->setBody($body); diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index 0d4130e9e..00c4e7cb0 100644 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php @@ -30,7 +30,8 @@ class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->timeout = 30; - $this->fileFactory = $this->getMockBuilder('\OCA\News\Utility\SimplePieAPIFactory') + $this->fileFactory = $this + ->getMockBuilder('\OCA\News\Utility\SimplePieAPIFactory') ->disableOriginalConstructor() ->getMock(); $this->proxyHost = 'test'; @@ -56,7 +57,8 @@ class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { $this->testEnhancer = new XPathArticleEnhancer( $this->fileFactory, [ - '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/span', + '/explosm.net\/comics/' => + '//*[@id=\'maincontent\']/div[2]/div/span', '/explosm.net\/shorts/' => '//*[@id=\'maincontent\']/div/div', '/explosm.net\/all/' => '//body/*', '/themerepublic.net/' => '//*[@class=\'post hentry\']' @@ -259,8 +261,12 @@ class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { $result = $this->testEnhancer->enhance($item); $this->assertEquals('
' . - 'link' . - 'link2' . + '' . + 'link' . + '' . + 'link2' . '' . '
', $result->getBody()); } @@ -288,7 +294,9 @@ class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { $result = $this->testEnhancer->enhance($item); $this->assertEquals( - '
', + '
', $result->getBody()); } diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php index 6a2b07c71..2032c2169 100644 --- a/tests/unit/config/ConfigTest.php +++ b/tests/unit/config/ConfigTest.php @@ -32,7 +32,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { 'file_exists' ]); $this->loggerParams = ['hi']; - $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams); + $this->config = new Config( + $this->fileSystem, $this->logger, $this->loggerParams + ); $this->configPath = 'config.json'; } @@ -55,7 +57,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); + ->will($this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true') + ); $this->config->read($this->configPath); @@ -68,7 +72,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeMinimumInterval = 59")); + ->will($this->returnValue('autoPurgeMinimumInterval = 59')); $this->config->read($this->configPath); @@ -81,7 +85,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->fileSystem->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = false")); + ->will($this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false') + ); $this->config->read($this->configPath); @@ -120,20 +126,20 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { public function testWrite () { - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 3\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = true\n" . - "proxyHost = yo man\n" . - "proxyPort = 12\n" . - "proxyUser = this is a test\n". - "proxyPassword = se"; + $json = 'autoPurgeMinimumInterval = 60' . "\n" . + 'autoPurgeCount = 3' . "\n" . + 'simplePieCacheDuration = 1800' . "\n" . + 'feedFetcherTimeout = 60' . "\n" . + 'useCronUpdates = true' . "\n" . + 'proxyHost = yo man' . "\n" . + 'proxyPort = 12' . "\n" . + 'proxyUser = this is a test' . "\n". + 'proxyPassword = se'; $this->config->setAutoPurgeCount(3); - $this->config->setProxyHost("yo man"); + $this->config->setProxyHost('yo man'); $this->config->setProxyPort(12); - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + $this->config->setProxyUser('this is a test'); + $this->config->setProxyPassword('se'); $this->fileSystem->expects($this->once()) ->method('file_put_contents') @@ -157,15 +163,15 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->config->setUseCronUpdates(false); - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 200\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = false\n" . - "proxyHost = \n" . - "proxyPort = 8080\n" . - "proxyUser = \n" . - "proxyPassword = "; + $json = 'autoPurgeMinimumInterval = 60' . "\n" . + 'autoPurgeCount = 200' . "\n" . + 'simplePieCacheDuration = 1800' . "\n" . + 'feedFetcherTimeout = 60' . "\n" . + 'useCronUpdates = false' . "\n" . + 'proxyHost = ' . "\n" . + 'proxyPort = 8080' . "\n" . + 'proxyUser = ' . "\n" . + 'proxyPassword = '; $this->fileSystem->expects($this->once()) ->method('file_put_contents') @@ -177,8 +183,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { public function testEncodesUserAndPasswordInHTTPBasicAuth() { - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + $this->config->setProxyUser('this is a test'); + $this->config->setProxyPassword('se'); $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); } diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 29760e6f4..635209041 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -113,7 +113,10 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { $return = $this->controller->articles(); $headers = $return->getHeaders(); - $this->assertEquals('attachment; filename="articles.json"', $headers ['Content-Disposition']); + $this->assertEquals( + 'attachment; filename="articles.json"', + $headers ['Content-Disposition'] + ); $this->assertEquals('[{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php index d14782856..c73f49288 100644 --- a/tests/unit/controller/FeedApiControllerTest.php +++ b/tests/unit/controller/FeedApiControllerTest.php @@ -135,7 +135,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testDeleteDoesNotExist() { $this->feedService->expects($this->once()) ->method('delete') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->feedAPI->delete(2); @@ -203,7 +205,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') - ->will($this->throwException(new ServiceConflictException($this->msg))); + ->will( + $this->throwException(new ServiceConflictException($this->msg)) + ); $response = $this->feedAPI->create('ho', 3); @@ -216,7 +220,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testCreateError() { $this->feedService->expects($this->once()) ->method('create') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will( + $this->throwException(new ServiceNotFoundException($this->msg)) + ); $response = $this->feedAPI->create('ho', 3); @@ -253,7 +259,9 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { public function testMoveDoesNotExist() { $this->feedService->expects($this->once()) ->method('move') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will( + $this->throwException(new ServiceNotFoundException($this->msg)) + ); $response = $this->feedAPI->move(3, 4); diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 34b0a847b..e7f19a2b8 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -43,13 +43,16 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { '\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $this->itemService = $this->getMockBuilder('\OCA\News\Service\ItemService') + $this->itemService = $this + ->getMockBuilder('\OCA\News\Service\ItemService') ->disableOriginalConstructor() ->getMock(); - $this->feedService = $this->getMockBuilder('\OCA\News\Service\FeedService') + $this->feedService = $this + ->getMockBuilder('\OCA\News\Service\FeedService') ->disableOriginalConstructor() ->getMock(); - $this->folderService = $this->getMockBuilder('\OCA\News\Service\FolderService') + $this->folderService = $this + ->getMockBuilder('\OCA\News\Service\FolderService') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( @@ -276,7 +279,9 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); - $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals( + $response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY + ); } @@ -427,7 +432,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $this->feedService->expects($this->once()) ->method('importArticles') - ->with($this->equalTo(array('json')), + ->with($this->equalTo(['json']), $this->equalTo($this->user)) ->will($this->returnValue($feed)); @@ -436,7 +441,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->user)) ->will($this->returnValue(3)); - $response = $this->controller->import(array('json')); + $response = $this->controller->import(['json']); $this->assertEquals($expected, $response); } @@ -445,7 +450,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { public function testImportCreatesNoAdditionalFeed() { $this->feedService->expects($this->once()) ->method('importArticles') - ->with($this->equalTo(array('json')), + ->with($this->equalTo(['json']), $this->equalTo($this->user)) ->will($this->returnValue(null)); @@ -454,7 +459,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->user)) ->will($this->returnValue(3)); - $response = $this->controller->import(array('json')); + $response = $this->controller->import(['json']); $this->assertEquals(['starred' => 3], $response); } diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php index c0371661a..550cd298c 100644 --- a/tests/unit/controller/FolderApiControllerTest.php +++ b/tests/unit/controller/FolderApiControllerTest.php @@ -130,7 +130,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $data = $response->getData(); $this->assertEquals($msg, $data['message']); - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); + $this->assertEquals( + Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus() + ); } @@ -149,7 +151,11 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $this->folderService->expects($this->once()) ->method('delete') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) + ); $response = $this->folderAPI->delete($folderId); @@ -178,7 +184,11 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) + ); $response = $this->folderAPI->update($folderId, $folderName); @@ -194,7 +204,11 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new ServiceConflictException($this->msg))); + ->will( + $this->throwException( + new ServiceConflictException($this->msg) + ) + ); $response = $this->folderAPI->update($folderId, $folderName); @@ -210,13 +224,19 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $this->folderService->expects($this->once()) ->method('rename') - ->will($this->throwException(new ServiceValidationException($this->msg))); + ->will( + $this->throwException( + new ServiceValidationException($this->msg) + ) + ); $response = $this->folderAPI->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); - $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); + $this->assertEquals( + Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus() + ); } diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index b06c97c79..5a5daff3d 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -91,7 +91,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testOpenDoesNotExist(){ $this->folderService->expects($this->once()) ->method('open') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->controller->open(5, true); @@ -144,7 +146,8 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->controller->create('tech'); $params = json_decode($response->render(), true); - $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($response->getStatus(), + Http::STATUS_UNPROCESSABLE_ENTITY); $this->assertEquals($msg, $params['message']); } @@ -217,7 +220,8 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->controller->rename('tech', 4); $params = json_decode($response->render(), true); - $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($response->getStatus(), + Http::STATUS_UNPROCESSABLE_ENTITY); $this->assertEquals($msg, $params['message']); } @@ -285,7 +289,9 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { public function testRestoreDoesNotExist(){ $this->folderService->expects($this->once()) ->method('unmarkDeleted') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will( + $this->throwException(new ServiceNotFoundException($this->msg)) + ); $response = $this->controller->restore(5); diff --git a/tests/unit/controller/ItemApiControllerTest.php b/tests/unit/controller/ItemApiControllerTest.php index 12b9d3225..8ab35010a 100644 --- a/tests/unit/controller/ItemApiControllerTest.php +++ b/tests/unit/controller/ItemApiControllerTest.php @@ -135,7 +135,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testReadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->itemAPI->read(2); @@ -161,7 +163,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnreadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->itemAPI->unread(2); @@ -188,7 +192,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testStarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->itemAPI->star(2, 'test'); @@ -215,7 +221,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { public function testUnstarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + ->will($this->throwException( + new ServiceNotFoundException($this->msg)) + ); $response = $this->itemAPI->unstar(2, 'test'); diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index fd0904ef7..88e49c690 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -134,7 +134,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException(new ServiceNotFoundException($msg)));; + ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->star(4, 'test', false); $params = json_decode($response->render(), true); diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index 60ae8c66b..48af6860f 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -159,9 +159,13 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { $result = $this->controller->manifest(); $this->assertEquals($this->configData['name'], $result['name']); $this->assertEquals('web', $result['type']); - $this->assertEquals($this->configData['description'], $result['description']); + $this->assertEquals( + $this->configData['description'], $result['description'] + ); $this->assertEquals('de-DE', $result['default_locale']); - $this->assertEquals($this->configData['homepage'], $result['developer']['url']); + $this->assertEquals( + $this->configData['homepage'], $result['developer']['url'] + ); $this->assertEquals('john, test', $result['developer']['name']); } diff --git a/tests/unit/controller/UtilityApiControllerTest.php b/tests/unit/controller/UtilityApiControllerTest.php index efff559d8..f4219fddf 100644 --- a/tests/unit/controller/UtilityApiControllerTest.php +++ b/tests/unit/controller/UtilityApiControllerTest.php @@ -36,8 +36,9 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { '\OCA\News\Utility\Updater') ->disableOriginalConstructor() ->getMock(); - $this->newsAPI = new UtilityApiController($this->appName, $this->request, - $this->updater, $this->settings); + $this->newsAPI = new UtilityApiController( + $this->appName, $this->request, $this->updater, $this->settings + ); } diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php index a1a570b87..9bbce1ab0 100644 --- a/tests/unit/db/FeedMapperTest.php +++ b/tests/unit/db/FeedMapperTest.php @@ -47,10 +47,12 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { StatusFlag::UNREAD . ' ' . 'WHERE `feeds`.`id` = ? ' . 'AND `feeds`.`user_id` = ? ' . - 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. - '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, ' . + '`feeds`.`url_hash`, '. + '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`, '. + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $params = [$id, $userId]; $this->setMapperResult($sql, $params, $rows); @@ -71,14 +73,18 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { StatusFlag::UNREAD . ' ' . 'WHERE `feeds`.`id` = ? ' . 'AND `feeds`.`user_id` = ? ' . - 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. - '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, ' . + '`feeds`.`url_hash`, '. + '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`, '. + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $params = [$id, $userId]; $this->setMapperResult($sql, $params); - $this->setExpectedException('\OCP\AppFramework\Db\DoesNotExistException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\DoesNotExistException' + ); $this->mapper->find($id, $userId); } @@ -98,14 +104,18 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { StatusFlag::UNREAD . ' ' . 'WHERE `feeds`.`id` = ? ' . 'AND `feeds`.`user_id` = ? ' . - 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. - '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, ' . + '`feeds`.`url_hash`, '. + '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`, '. + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $params = [$id, $userId]; $this->setMapperResult($sql, $params, $rows); - $this->setExpectedException('\OCP\AppFramework\Db\MultipleObjectsReturnedException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\MultipleObjectsReturnedException' + ); $this->mapper->find($id, $userId); } @@ -121,10 +131,6 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'ON `feeds`.`folder_id` = `folders`.`id` ' . 'LEFT JOIN `*PREFIX*news_items` `items` ' . 'ON `feeds`.`id` = `items`.`feed_id` ' . - // WARNING: this is a desperate attempt at making this query work - // because prepared statements dont work. This is a possible - // SQL INJECTION RISK WHEN MODIFIED WITHOUT THOUGHT. - // think twice when changing this 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' . StatusFlag::UNREAD . ' ' . 'WHERE (`feeds`.`folder_id` = 0 ' . @@ -133,8 +139,9 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `feeds`.`deleted_at` = 0 ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $this->setMapperResult($sql, [], $rows); @@ -155,10 +162,6 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'ON `feeds`.`folder_id` = `folders`.`id` ' . 'LEFT JOIN `*PREFIX*news_items` `items` ' . 'ON `feeds`.`id` = `items`.`feed_id` ' . - // WARNING: this is a desperate attempt at making this query work - // because prepared statements dont work. This is a possible - // SQL INJECTION RISK WHEN MODIFIED WITHOUT THOUGHT. - // think twice when changing this 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' . StatusFlag::UNREAD . ' ' . 'WHERE `feeds`.`user_id` = ? ' . @@ -168,8 +171,9 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `feeds`.`deleted_at` = 0 ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $this->setMapperResult($sql, [$userId], $rows); $result = $this->mapper->findAllFromUser($userId); @@ -190,8 +194,9 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `feeds`.`user_id` = ? ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $this->setMapperResult($sql, [$urlHash, $this->user], $row); $result = $this->mapper->findByUrlHash($urlHash, $this->user); @@ -211,11 +216,14 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `feeds`.`user_id` = ? ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $this->setMapperResult($sql, [$urlHash, $this->user]); - $this->setExpectedException('\OCP\AppFramework\Db\DoesNotExistException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\DoesNotExistException' + ); $this->mapper->findByUrlHash($urlHash, $this->user); } @@ -236,11 +244,14 @@ class FeedMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `feeds`.`user_id` = ? ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,'. '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,'. - '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,'. - '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`'; + '`feeds`.`favicon_link`, `feeds`.`added`, ' . + '`feeds`.`articles_per_update`, `feeds`.`folder_id`, ' . + '`feeds`.`prevent_update`, `feeds`.`deleted_at`'; $this->setMapperResult($sql, [$urlHash, $this->user], $rows); - $this->setExpectedException('\OCP\AppFramework\Db\MultipleObjectsReturnedException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\MultipleObjectsReturnedException' + ); $this->mapper->findByUrlHash($urlHash, $this->user); } diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php index 1078d205f..87f9e617c 100644 --- a/tests/unit/db/FolderMapperTest.php +++ b/tests/unit/db/FolderMapperTest.php @@ -63,7 +63,9 @@ class FolderMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $this->setMapperResult($sql, [$id, $userId]); - $this->setExpectedException('\OCP\AppFramework\Db\DoesNotExistException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\DoesNotExistException' + ); $this->folderMapper->find($id, $userId); } @@ -78,7 +80,9 @@ class FolderMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $this->setMapperResult($sql, [$id, $userId], $rows); - $this->setExpectedException('\OCP\AppFramework\Db\MultipleObjectsReturnedException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\MultipleObjectsReturnedException' + ); $this->folderMapper->find($id, $userId); } @@ -156,7 +160,9 @@ class FolderMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `deleted_at` < ? ' . 'AND `user_id` = ?'; $this->setMapperResult($sql, [$deleteOlderThan, $this->user], $rows); - $result = $this->folderMapper->getToDelete($deleteOlderThan, $this->user); + $result = $this->folderMapper->getToDelete( + $deleteOlderThan, $this->user + ); $this->assertEquals($this->folders, $result); } diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index 46ab2165a..2f6b68c1c 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -35,23 +35,23 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $item1 = new Item(); $item2 = new Item(); - $this->items = array( + $this->items = [ $item1, $item2 - ); + ]; $this->userId = 'john'; $this->id = 3; $this->folderId = 2; - $this->row = array( - array('id' => $this->items[0]->getId()), - ); + $this->row = [ + ['id' => $this->items[0]->getId()], + ]; - $this->rows = array( - array('id' => $this->items[0]->getId()), - array('id' => $this->items[1]->getId()) - ); + $this->rows = [ + ['id' => $this->items[0]->getId()], + ['id' => $this->items[1]->getId()] + ]; $this->user = 'john'; $this->limit = 10; @@ -98,7 +98,9 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFind(){ $sql = $this->makeSelectQuery('AND `items`.`id` = ? '); - $this->setMapperResult($sql, array($this->userId, $this->id), $this->row); + $this->setMapperResult( + $sql, [$this->userId, $this->id], $this->row + ); $result = $this->mapper->find($this->id, $this->userId); $this->assertEquals($this->items[0], $result); @@ -107,9 +109,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testGetStarredCount(){ $userId = 'john'; - $row = array( - array('size' => 9) - ); + $row = [['size' => 9]]; $sql = 'SELECT COUNT(*) AS size FROM `*PREFIX*news_items` `items` '. 'JOIN `*PREFIX*news_feeds` `feeds` ' . 'ON `feeds`.`id` = `items`.`feed_id` '. @@ -122,7 +122,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'WHERE `feeds`.`folder_id` = 0 ' . 'OR `folders`.`deleted_at` = 0'; - $this->setMapperResult($sql, array($userId), $row); + $this->setMapperResult($sql, [$userId], $row); $result = $this->mapper->starredCount($userId); $this->assertEquals($row[0]['size'], $result); @@ -138,7 +138,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'WHERE `user_id` = ? ' . ') '. 'AND `id` <= ?'; - $params = array(~StatusFlag::UNREAD, $this->updatedSince, $this->user, 3); + $params = [~StatusFlag::UNREAD, $this->updatedSince, $this->user, 3]; $this->setMapperResult($sql, $params); $this->mapper->readAll(3, $this->updatedSince, $this->user); } @@ -154,7 +154,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `user_id` = ? ' . ') '. 'AND `id` <= ?'; - $params = array(~StatusFlag::UNREAD, $this->updatedSince, 3, $this->user, 6); + $params = [~StatusFlag::UNREAD, $this->updatedSince, 3, $this->user, 6]; $this->setMapperResult($sql, $params); $this->mapper->readFolder(3, 6, $this->updatedSince, $this->user); } @@ -170,8 +170,9 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'SELECT * FROM `*PREFIX*news_feeds` ' . 'WHERE `user_id` = ? ' . 'AND `id` = ? ) '; - $params = array(~StatusFlag::UNREAD, $this->updatedSince, 3, 6, - $this->user, 3); + $params = [ + ~StatusFlag::UNREAD, $this->updatedSince, 3, 6, $this->user, 3 + ]; $this->setMapperResult($sql, $params); $this->mapper->readFeed(3, 6, $this->updatedSince, $this->user); } @@ -180,7 +181,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAllNew(){ $sql = 'AND `items`.`last_modified` >= ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->updatedSince); + $params = [$this->user, $this->updatedSince]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllNew($this->updatedSince, @@ -195,10 +196,10 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `items`.`last_modified` >= ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, $this->updatedSince); + $params = [$this->user, $this->id, $this->updatedSince]; $this->setMapperResult($sql, $params, $this->rows); - $result = $this->mapper->findAllNewFolder($this->id, $this->updatedSince, - $this->status, $this->user); + $result = $this->mapper->findAllNewFolder($this->id, + $this->updatedSince, $this->status, $this->user); $this->assertEquals($this->items, $result); } @@ -208,7 +209,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $sql = 'AND `items`.`feed_id` = ? ' . 'AND `items`.`last_modified` >= ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, $this->updatedSince); + $params = [$this->user, $this->id, $this->updatedSince]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince, @@ -222,7 +223,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $status = StatusFlag::UNREAD | StatusFlag::STARRED; $sql = 'AND ((`items`.`status` & ' . $status . ') > 0) '; $sql = $this->makeSelectQuery($sql); - $params = array($this->user); + $params = [$this->user]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllUnreadOrStarred($this->user); @@ -234,7 +235,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $sql = 'AND `items`.`feed_id` = ? ' . 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, $this->offset); + $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFeed($this->id, $this->limit, $this->offset, $this->status, false, $this->user); @@ -247,7 +248,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $sql = 'AND `items`.`feed_id` = ? ' . 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); - $params = array($this->user, $this->id, $this->offset); + $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFeed($this->id, $this->limit, $this->offset, $this->status, true, $this->user); @@ -259,7 +260,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAllFeedOffsetZero(){ $sql = 'AND `items`.`feed_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id); + $params = [$this->user, $this->id]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFeed($this->id, $this->limit, 0, $this->status, false, $this->user); @@ -272,8 +273,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $sql = 'AND `feeds`.`folder_id` = ? ' . 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id, - $this->offset); + $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFolder($this->id, $this->limit, $this->offset, $this->status, false, $this->user); @@ -286,8 +286,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { $sql = 'AND `feeds`.`folder_id` = ? ' . 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); - $params = array($this->user, $this->id, - $this->offset); + $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFolder($this->id, $this->limit, $this->offset, $this->status, true, $this->user); @@ -299,7 +298,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAllFolderOffsetZero(){ $sql = 'AND `feeds`.`folder_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->id); + $params = [$this->user, $this->id]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAllFolder($this->id, $this->limit, 0, $this->status, false, $this->user); @@ -311,7 +310,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAll(){ $sql = 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = array($this->user, $this->offset); + $params = [$this->user, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAll($this->limit, $this->offset, $this->status, false, $this->user); @@ -323,7 +322,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAllOldestFirst(){ $sql = 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); - $params = array($this->user, $this->offset); + $params = [$this->user, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAll($this->limit, $this->offset, $this->status, true, $this->user); @@ -334,7 +333,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testFindAllOffsetZero(){ $sql = $this->makeSelectQueryStatus('', $this->status); - $params = array($this->user); + $params = [$this->user]; $this->setMapperResult($sql, $params, $this->rows); $result = $this->mapper->findAll($this->limit, 0, $this->status, false, $this->user); @@ -352,14 +351,15 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'AND `items`.`guid_hash` = ? ' . 'AND `feeds`.`id` = ? '); - $this->setMapperResult($sql, array($this->userId, $hash, $feedId), $this->row); + $this->setMapperResult( + $sql, [$this->userId, $hash, $feedId], $this->row); $result = $this->mapper->findByGuidHash($hash, $feedId, $this->userId); $this->assertEquals($this->items[0], $result); } - public function testDeleteReadOlderThanThresholdDoesNotDeleteBelowThreshold(){ + public function testDeleteReadOlderThanThresholdDoesNotDelete(){ $status = StatusFlag::STARRED | StatusFlag::UNREAD; $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . '`items`.`feed_id` AS `feed_id` ' . @@ -371,8 +371,8 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'HAVING COUNT(*) > ?'; $threshold = 10; - $rows = array(array('feed_id' => 30, 'size' => 9)); - $params = array($status, $threshold); + $rows = [['feed_id' => 30, 'size' => 9]]; + $params = [$status, $threshold]; $this->setMapperResult($sql, $params, $rows); $this->mapper->deleteReadOlderThanThreshold($threshold); @@ -393,18 +393,18 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'WHERE NOT ((`items`.`status` & ?) > 0) ' . 'GROUP BY `items`.`feed_id`, `feeds`.`articles_per_update` ' . 'HAVING COUNT(*) > ?'; - $params1 = array($status, $threshold); + $params1 = [$status, $threshold]; - $row = array('feed_id' => 30, 'size' => 11); + $row = ['feed_id' => 30, 'size' => 11]; $sql2 = 'DELETE FROM `*PREFIX*news_items` ' . 'WHERE NOT ((`status` & ?) > 0) ' . 'AND `feed_id` = ? ' . 'ORDER BY `id` ASC'; - $params2 = array($status, 30); + $params2 = [$status, 30]; - $this->setMapperResult($sql1, $params1, array($row)); + $this->setMapperResult($sql1, $params1, [$row]); $this->setMapperResult($sql2, $params2); $this->mapper->deleteReadOlderThanThreshold($threshold); @@ -412,12 +412,13 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testGetNewestItem() { - $sql = 'SELECT MAX(`items`.`id`) AS `max_id` FROM `*PREFIX*news_items` `items` '. + $sql = 'SELECT MAX(`items`.`id`) AS `max_id` ' . + 'FROM `*PREFIX*news_items` `items` '. 'JOIN `*PREFIX*news_feeds` `feeds` ' . 'ON `feeds`.`id` = `items`.`feed_id` '. 'AND `feeds`.`user_id` = ?'; - $params = array($this->user); - $rows = array(array('max_id' => 3)); + $params = [$this->user]; + $rows = [['max_id' => 3]]; $this->setMapperResult($sql, $params, $rows); @@ -427,15 +428,18 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { public function testGetNewestItemIdNotFound() { - $sql = 'SELECT MAX(`items`.`id`) AS `max_id` FROM `*PREFIX*news_items` `items` '. + $sql = 'SELECT MAX(`items`.`id`) AS `max_id` ' . + 'FROM `*PREFIX*news_items` `items` '. 'JOIN `*PREFIX*news_feeds` `feeds` ' . 'ON `feeds`.`id` = `items`.`feed_id` '. 'AND `feeds`.`user_id` = ?'; - $params = array($this->user); - $rows = array(); + $params = [$this->user]; + $rows = []; $this->setMapperResult($sql, $params, $rows); - $this->setExpectedException('\OCP\AppFramework\Db\DoesNotExistException'); + $this->setExpectedException( + '\OCP\AppFramework\Db\DoesNotExistException' + ); $this->mapper->getNewestItemId($this->user); } @@ -449,7 +453,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { 'WHERE `feeds`.`user_id` = ?' . ')'; - $this->setMapperResult($sql, array($userId)); + $this->setMapperResult($sql, [$userId]); $this->mapper->deleteUser($userId); } diff --git a/tests/unit/db/MapperFactoryTest.php b/tests/unit/db/MapperFactoryTest.php index 3ebc0ce17..b5aa76dc0 100644 --- a/tests/unit/db/MapperFactoryTest.php +++ b/tests/unit/db/MapperFactoryTest.php @@ -43,7 +43,8 @@ class MapperFactoryTest extends \PHPUnit_Framework_TestCase { public function testGetItemMapperPostgres() { $factory = new MapperFactory('pgsql', $this->db); - $this->assertTrue($factory->getItemMapper() instanceof \OCA\News\Db\Postgres\ItemMapper); + $this->assertTrue($factory->getItemMapper() + instanceof \OCA\News\Db\Postgres\ItemMapper); } diff --git a/tests/unit/db/postgres/ItemMapperTest.php b/tests/unit/db/postgres/ItemMapperTest.php index 04550695d..473641522 100644 --- a/tests/unit/db/postgres/ItemMapperTest.php +++ b/tests/unit/db/postgres/ItemMapperTest.php @@ -62,7 +62,7 @@ class ItemMapperTest extends \Test\AppFramework\Db\MapperTestUtility { } - public function testDeleteReadOlderThanThresholdDoesNotDeleteBelowThreshold(){ + public function testDeleteReadOlderThanThresholdDoesntDelete(){ $status = StatusFlag::STARRED | StatusFlag::UNREAD; $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . '`items`.`feed_id` AS `feed_id` ' . diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php index 6a0cec4dc..2d31fb18a 100644 --- a/tests/unit/fetcher/FeedFetcherTest.php +++ b/tests/unit/fetcher/FeedFetcherTest.php @@ -136,7 +136,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $this->title = 'my&lt;' title'; $this->guid = 'hey guid here'; $this->body = 'let the bodies hit the floor test'; - $this->body2 = 'let the bodies hit the floor test'; + $this->body2 = 'let the bodies hit the floor ' . + 'test'; $this->pub = 23111; $this->author = '<boogieman'; $this->enclosureLink = 'http://enclosure.you'; @@ -232,7 +233,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - private function createItem($author=false, $enclosureType=null, $noPubDate=false) { + private function createItem($author=false, $enclosureType=null, + $noPubDate=false) { $this->expectItem('get_permalink', $this->permalink); $this->expectItem('get_title', $this->title); $this->expectItem('get_id', $this->guid); diff --git a/tests/unit/http/TextDownloadResponseTest.php b/tests/unit/http/TextDownloadResponseTest.php index d78464e68..73622291a 100644 --- a/tests/unit/http/TextDownloadResponseTest.php +++ b/tests/unit/http/TextDownloadResponseTest.php @@ -19,7 +19,9 @@ class TextDownloadResponseTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->response = new TextDownloadResponse('sometext', 'file', 'content'); + $this->response = new TextDownloadResponse( + 'sometext', 'file', 'content' + ); } diff --git a/tests/unit/service/FeedServiceTest.php b/tests/unit/service/FeedServiceTest.php index f7c804ec5..104413788 100644 --- a/tests/unit/service/FeedServiceTest.php +++ b/tests/unit/service/FeedServiceTest.php @@ -55,16 +55,20 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->l10n = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() ->getMock(); - $this->feedMapper = $this->getMockBuilder('\OCA\News\Db\FeedMapper') + $this->feedMapper = $this + ->getMockBuilder('\OCA\News\Db\FeedMapper') ->disableOriginalConstructor() ->getMock(); - $this->fetcher = $this->getMockBuilder('\OCA\News\Fetcher\Fetcher') + $this->fetcher = $this + ->getMockBuilder('\OCA\News\Fetcher\Fetcher') ->disableOriginalConstructor() ->getMock(); - $this->itemMapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') + $this->itemMapper = $this + ->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $this->enhancer = $this->getMockBuilder('\OCA\News\ArticleEnhancer\Enhancer') + $this->enhancer = $this + ->getMockBuilder('\OCA\News\ArticleEnhancer\Enhancer') ->disableOriginalConstructor() ->getMock(); $this->purifier = $this->getMock('purifier', ['purify']); @@ -78,7 +82,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedService = new FeedService($this->feedMapper, $this->fetcher, $this->itemMapper, $this->logger, $this->l10n, - $timeFactory, $config, $this->enhancer, $this->purifier, $this->loggerParams); + $timeFactory, $config, $this->enhancer, $this->purifier, + $this->loggerParams); $this->user = 'jack'; } @@ -103,7 +108,9 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->method('fetch') ->with($this->equalTo($url)) ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Service\ServiceNotFoundException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceNotFoundException' + ); $this->feedService->create($url, 1, $this->user); } @@ -127,7 +134,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->once()) ->method('findByUrlHash') - ->with($this->equalTo($createdFeed->getUrlHash()), $this->equalTo($this->user)) + ->with( + $this->equalTo($createdFeed->getUrlHash()), + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -369,7 +379,9 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->equalTo($this->user)) ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Service\ServiceNotFoundException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceNotFoundException' + ); $this->feedService->update($feed->getId(), $this->user); } @@ -412,7 +424,9 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->equalTo($this->user)) ->will($this->throwException($ex)); - $this->setExpectedException('\OCA\News\Service\ServiceNotFoundException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceNotFoundException' + ); $this->feedService->update($feed->getId(), $this->user); } @@ -565,7 +579,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $json = $item->toExport(['feed3' => $feed]); $json2 = $json; - $json2['feedLink'] = 'http://test.com'; // believe it or not this copies stuff :D + // believe it or not this copies stuff :D + $json2['feedLink'] = 'http://test.com'; $items = [$json, $json2]; diff --git a/tests/unit/service/FolderServiceTest.php b/tests/unit/service/FolderServiceTest.php index 53fb737b7..927cd1229 100644 --- a/tests/unit/service/FolderServiceTest.php +++ b/tests/unit/service/FolderServiceTest.php @@ -95,7 +95,9 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->setExpectedException('\OCA\News\Service\ServiceConflictException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceConflictException' + ); $this->folderService->create($folderName, 'john', 3); } @@ -108,7 +110,9 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($folderName)) ->will($this->returnValue([])); - $this->setExpectedException('\OCA\News\Service\ServiceValidationException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceValidationException' + ); $this->folderService->create($folderName, 'john', 3); } @@ -162,7 +166,9 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($folderName)) ->will($this->returnValue($rows)); - $this->setExpectedException('\OCA\News\Service\ServiceConflictException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceConflictException' + ); $this->folderService->rename(3, $folderName, 'john'); } @@ -175,7 +181,9 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($folderName)) ->will($this->returnValue([])); - $this->setExpectedException('\OCA\News\Service\ServiceValidationException'); + $this->setExpectedException( + '\OCA\News\Service\ServiceValidationException' + ); $this->folderService->rename(3, $folderName, 'john'); } diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php index b9f23fee6..4f5672e20 100644 --- a/tests/unit/service/ItemServiceTest.php +++ b/tests/unit/serv