From 5b94705cf3918dc7986c6043b1fbe776bf22958f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 27 Mar 2018 15:35:06 +0200 Subject: Core: Fix compatibility with nextcloud codestyle (#280) --- tests/Integration/Db/FeedMapperTest.php | 99 +++++--- tests/Integration/Db/FolderMapperTest.php | 8 +- tests/Integration/Db/ItemMapperTest.php | 59 +++-- tests/Integration/Fixtures/FeedFixture.php | 14 +- tests/Integration/Fixtures/Fixture.php | 8 +- tests/Integration/Fixtures/FolderFixture.php | 14 +- tests/Integration/Fixtures/ItemFixture.php | 14 +- tests/Integration/Fixtures/data/default.php | 2 +- tests/Integration/Fixtures/data/readitem.php | 2 +- tests/Integration/IntegrationTest.php | 90 ++++--- tests/Unit/Config/ConfigTest.php | 83 ++++--- tests/Unit/Controller/AdminControllerTest.php | 36 +-- tests/Unit/Controller/EntityApiSerializerTest.php | 32 ++- tests/Unit/Controller/ExportControllerTest.php | 41 ++-- tests/Unit/Controller/FeedApiControllerTest.php | 131 ++++++---- tests/Unit/Controller/FeedControllerTest.php | 144 +++++++---- tests/Unit/Controller/FolderApiControllerTest.php | 77 +++--- tests/Unit/Controller/FolderControllerTest.php | 50 ++-- tests/Unit/Controller/ItemApiControllerTest.php | 179 +++++++++----- tests/Unit/Controller/ItemControllerTest.php | 160 ++++++++----- tests/Unit/Controller/JSONHttpErrorTest.php | 17 +- tests/Unit/Controller/PageControllerTest.php | 194 ++++++++++----- tests/Unit/Controller/UserApiControllerTest.php | 56 +++-- tests/Unit/Controller/UtilityApiControllerTest.php | 44 ++-- tests/Unit/Db/FeedTest.php | 41 ++-- tests/Unit/Db/FolderMapperTest.php | 38 +-- tests/Unit/Db/FolderTest.php | 29 ++- tests/Unit/Db/ItemTest.php | 99 +++++--- tests/Unit/Db/MapperFactoryTest.php | 63 ++--- tests/Unit/Db/MapperTestUtility.php | 120 ++++++---- tests/Unit/Fetcher/FeedFetcherTest.php | 132 ++++++---- tests/Unit/Fetcher/FetcherTest.php | 71 +++--- tests/Unit/Fetcher/YoutubeFetcherTest.php | 20 +- tests/Unit/Http/TextDownloadResponseTest.php | 17 +- tests/Unit/Http/TextResponseTest.php | 23 +- tests/Unit/Migration/MigrateStatusFlagsTest.php | 29 ++- tests/Unit/Service/FeedServiceTest.php | 266 ++++++++++++++------- tests/Unit/Service/FolderServiceTest.php | 68 ++++-- tests/Unit/Service/ItemServiceTest.php | 239 +++++++++++------- tests/Unit/Service/ServiceTest.php | 32 ++- tests/Unit/Service/StatusServiceTest.php | 50 ++-- tests/Unit/Utility/OPMLExporterTest.php | 98 +++++--- tests/Unit/Utility/ProxyConfigParserTest.php | 32 ++- tests/Unit/Utility/UpdaterTest.php | 38 +-- tests/bootstrap.php | 2 +- 45 files changed, 1958 insertions(+), 1103 deletions(-) (limited to 'tests') diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index bcf1cb895..3d1ea71f4 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -5,8 +5,8 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt - * @author Daniel Opitz + * @author Bernhard Posselt + * @author Daniel Opitz * @copyright Bernhard Posselt 2015 * @copyright Daniel Opitz 2017 */ @@ -17,9 +17,11 @@ use OCA\News\Db\Feed; use OCA\News\Tests\Integration\IntegrationTest; use OCA\News\Tests\Integration\Fixtures\FeedFixture; -class FeedMapperTest extends IntegrationTest { +class FeedMapperTest extends IntegrationTest +{ - public function testFind () { + public function testFind() + { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -32,12 +34,14 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotExisting () { + public function testFindNotExisting() + { $this->feedMapper->find(0, $this->user); } - public function testFindAll () { + public function testFindAll() + { $feeds = [ [ 'userId' => $this->user, @@ -59,7 +63,8 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testFindAllEmpty () { + public function testFindAllEmpty() + { $feeds = $this->feedMapper->findAll(); $this->assertInternalType('array', $feeds); @@ -67,7 +72,8 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindAllFromUser () { + public function testFindAllFromUser() + { $feeds = [ [ 'userId' => $this->user, @@ -90,7 +96,8 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindAllFromUserNotExisting () { + public function testFindAllFromUserNotExisting() + { $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); $this->assertInternalType('array', $fetched); @@ -98,11 +105,14 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindByUrlHash () { - $feed = new FeedFixture([ + public function testFindByUrlHash() + { + $feed = new FeedFixture( + [ 'urlHash' => 'someTestHash', 'title' => 'Some Test Title' - ]); + ] + ); $feed = $this->feedMapper->insert($feed); $fetched = $this->feedMapper->findByUrlHash($feed->getUrlHash(), $this->user); @@ -114,13 +124,22 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException */ - public function testFindByUrlHashMoreThanOneResult () { - $feed1 = $this->feedMapper->insert(new FeedFixture([ - 'urlHash' => 'someTestHash' - ])); - $feed2 = $this->feedMapper->insert(new FeedFixture([ - 'urlHash' => 'someTestHash' - ])); + public function testFindByUrlHashMoreThanOneResult() + { + $feed1 = $this->feedMapper->insert( + new FeedFixture( + [ + 'urlHash' => 'someTestHash' + ] + ) + ); + $feed2 = $this->feedMapper->insert( + new FeedFixture( + [ + 'urlHash' => 'someTestHash' + ] + ) + ); $this->feedMapper->findByUrlHash($feed1->getUrlHash(), $this->user); } @@ -129,12 +148,14 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindByUrlHashNotExisting () { + public function testFindByUrlHashNotExisting() + { $this->feedMapper->findByUrlHash('some random hash', $this->user); } - public function testDelete () { + public function testDelete() + { $this->loadFixtures('default'); $feeds = $this->feedMapper->findAllFromUser($this->user); @@ -157,13 +178,16 @@ class FeedMapperTest extends IntegrationTest { $this->assertCount(0, $items); } - public function testGetToDelete () { - $this->loadFeedFixtures([ + public function testGetToDelete() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(); @@ -174,13 +198,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteOlderThan () { - $this->loadFeedFixtures([ + public function testGetToDeleteOlderThan() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(1000); @@ -191,13 +218,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteUser () { - $this->loadFeedFixtures([ + public function testGetToDeleteUser() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(2000, $this->user); @@ -208,14 +238,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteEmpty () { + public function testGetToDeleteEmpty() + { $fetched = $this->feedMapper->getToDelete(); $this->assertInternalType('array', $fetched); $this->assertCount(0, $fetched); } - public function testDeleteUser () { + public function testDeleteUser() + { $this->loadFixtures('default'); $this->assertCount(4, $this->feedMapper->findAllFromUser($this->user)); @@ -231,7 +263,8 @@ class FeedMapperTest extends IntegrationTest { $this->assertCount(0, $items); } - public function testDeleteUserNotExisting () { + public function testDeleteUserNotExisting() + { $this->feedMapper->deleteUser('notexistinguser'); } } diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php index 4be407566..889ac3e7c 100644 --- a/tests/Integration/Db/FolderMapperTest.php +++ b/tests/Integration/Db/FolderMapperTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -13,10 +13,12 @@ namespace OCA\News\Tests\Integration\Db; use OCA\News\Tests\Integration\IntegrationTest; -class FolderMapperTest extends IntegrationTest { +class FolderMapperTest extends IntegrationTest +{ - public function testFind () { + public function testFind() + { } diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index 546c43d85..c87a4139f 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -15,9 +15,11 @@ use OCA\News\Tests\Integration\IntegrationTest; use OCA\News\Tests\Integration\Fixtures\FeedFixture; use OCA\News\Tests\Integration\Fixtures\ItemFixture; -class ItemMapperTest extends IntegrationTest { +class ItemMapperTest extends IntegrationTest +{ - public function testFind() { + public function testFind() + { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -32,17 +34,20 @@ class ItemMapperTest extends IntegrationTest { /** * Same as whereId with easier title search - * @param $title + * + * @param $title * @return mixed */ - private function whereTitleId($title) { + private function whereTitleId($title) + { return $this->findItemByTitle($title)->getId(); } /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFeed() { + public function testFindNotFoundWhenDeletedFeed() + { $this->loadFixtures('default'); $id = $this->whereTitleId('not found feed'); @@ -53,7 +58,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFolder() { + public function testFindNotFoundWhenDeletedFolder() + { $this->loadFixtures('default'); @@ -62,7 +68,8 @@ class ItemMapperTest extends IntegrationTest { } - private function deleteReadOlderThanThreshold() { + private function deleteReadOlderThanThreshold() + { $this->loadFixtures('default'); $this->itemMapper->deleteReadOlderThanThreshold(1); @@ -77,7 +84,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdOne() { + public function testDeleteOlderThanThresholdOne() + { $this->loadFixtures('default'); $id = $this->whereTitleId('del1'); @@ -89,7 +97,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdTwo() { + public function testDeleteOlderThanThresholdTwo() + { $this->loadFixtures('default'); $id = $this->whereTitleId('del2'); @@ -99,7 +108,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testStarredCount () { + public function testStarredCount() + { $this->loadFixtures('default'); $count = $this->itemMapper->starredCount($this->user); @@ -107,7 +117,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadAll () { + public function testReadAll() + { $this->loadFixtures('default'); $this->itemMapper->readAll(PHP_INT_MAX, 10, $this->user); @@ -135,7 +146,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadFolder () { + public function testReadFolder() + { $this->loadFixtures('default'); $folderId = $this->findFolderByName('first folder')->getId(); @@ -166,7 +178,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadFeed () { + public function testReadFeed() + { $this->loadFixtures('default'); $feedId = $this->findFeedByTitle('third feed')->getId(); @@ -196,7 +209,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testDeleteUser () { + public function testDeleteUser() + { $this->loadFixtures('default'); $this->itemMapper->deleteUser($this->user); @@ -205,7 +219,8 @@ class ItemMapperTest extends IntegrationTest { $this->assertEquals(0, $id); } - public function testGetNewestItemId () { + public function testGetNewestItemId() + { $this->loadFixtures('default'); $id = $this->itemMapper->getNewestItemId($this->user); @@ -214,7 +229,8 @@ class ItemMapperTest extends IntegrationTest { $this->assertEquals($itemId, $id); } - public function testFindAllUnreadOrStarred () { + public function testFindAllUnreadOrStarred() + { $this->loadFixtures('default'); $items = $this->itemMapper->findAllUnreadOrStarred($this->user); @@ -222,7 +238,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadItem() { + public function testReadItem() + { $this->loadFixtures('readitem'); // assert that all items are unread $feed = $this->feedMapper->where(['userId' => 'john'])[0]; @@ -260,7 +277,8 @@ class ItemMapperTest extends IntegrationTest { } } - public function testUnreadItem() { + public function testUnreadItem() + { $this->loadFixtures('readitem'); // unread an item $feed = $this->feedMapper->where(['userId' => 'test'])[0]; @@ -286,7 +304,8 @@ class ItemMapperTest extends IntegrationTest { } } - protected function tearDown() { + protected function tearDown() + { parent::tearDown(); $this->clearUserNewsDatabase('john'); } diff --git a/tests/Integration/Fixtures/FeedFixture.php b/tests/Integration/Fixtures/FeedFixture.php index 3d7617a57..66461adbc 100644 --- a/tests/Integration/Fixtures/FeedFixture.php +++ b/tests/Integration/Fixtures/FeedFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -15,13 +15,16 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Feed; -class FeedFixture extends Feed { +class FeedFixture extends Feed +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'userId' => 'test', 'urlHash' => 'urlHash', 'url' => 'http://the.url.com', @@ -42,7 +45,8 @@ class FeedFixture extends Feed { 'updateMode' => 0, 'updateErrorCount' => 0, 'lastUpdateError' => '', - ], $defaults); + ], $defaults + ); unset($defaults['items']); $this->fillDefaults($defaults); } diff --git a/tests/Integration/Fixtures/Fixture.php b/tests/Integration/Fixtures/Fixture.php index f17beb25c..1874c8102 100644 --- a/tests/Integration/Fixtures/Fixture.php +++ b/tests/Integration/Fixtures/Fixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -13,9 +13,11 @@ namespace OCA\News\Tests\Integration\Fixtures; -trait Fixture { +trait Fixture +{ - protected function fillDefaults(array $defaults=[]) { + protected function fillDefaults(array $defaults=[]) + { foreach ($defaults as $key => $value) { $method = 'set' . ucfirst($key); $this->$method($value); diff --git a/tests/Integration/Fixtures/FolderFixture.php b/tests/Integration/Fixtures/FolderFixture.php index 150557b8b..2564e8b71 100644 --- a/tests/Integration/Fixtures/FolderFixture.php +++ b/tests/Integration/Fixtures/FolderFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -15,19 +15,23 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Folder; -class FolderFixture extends Folder { +class FolderFixture extends Folder +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'parentId' => 0, 'name' => 'folder', 'userId' => 'test', 'opened' => true, 'deletedAt' => 0, 'lastModified' => 9 - ], $defaults); + ], $defaults + ); unset($defaults['feeds']); $this->fillDefaults($defaults); } diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index 0832b0ef4..450b56f82 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -15,12 +15,15 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Item; -class ItemFixture extends Item { +class ItemFixture extends Item +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'url' => 'http://google.de', 'title' => 'title', 'author' => 'my author', @@ -33,7 +36,8 @@ class ItemFixture extends Item { 'starred' => false, 'lastModified' => 113, 'rtl' => false, - ], $defaults); + ], $defaults + ); if (!array_key_exists('guid', $defaults)) { $defaults['guid'] = $defaults['title']; diff --git a/tests/Integration/Fixtures/data/default.php b/tests/Integration/Fixtures/data/default.php index 862515b12..41935b5c6 100644 --- a/tests/Integration/Fixtures/data/default.php +++ b/tests/Integration/Fixtures/data/default.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ diff --git a/tests/Integration/Fixtures/data/readitem.php b/tests/Integration/Fixtures/data/readitem.php index 8f953a845..425492741 100644 --- a/tests/Integration/Fixtures/data/readitem.php +++ b/tests/Integration/Fixtures/data/readitem.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index f14a1263b..751cbe5fd 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright Bernhard Posselt 2015 */ @@ -32,24 +32,34 @@ use OCA\News\Db\ItemMapper; use OCA\News\Db\FolderMapper; -abstract class IntegrationTest extends \Test\TestCase { +abstract class IntegrationTest extends \Test\TestCase +{ protected $user = 'test'; protected $userPassword = 'test'; - /** @var ItemMapper */ + /** + * @var ItemMapper + */ protected $itemMapper; - /** @var FeedMapper */ + /** + * @var FeedMapper + */ protected $feedMapper; - /** @var FolderMapper */ + /** + * @var FolderMapper + */ protected $folderMapper; - /** @var IAppContainer */ + /** + * @var IAppContainer + */ protected $container; - protected function setUp() { + protected function setUp() + { parent::setUp(); $app = new Application(); $this->container = $app->getContainer(); @@ -62,7 +72,8 @@ abstract class IntegrationTest extends \Test\TestCase { $this->folderMapper = $this->container->query(FolderMapper::class); } - protected function findItemByTitle($title) { + protected function findItemByTitle($title) + { // db logic in app code, negligible since its a test $items = $this->itemMapper->where(['title' => $title]); $feeds = $this->feedMapper->where(['userId' => $this->user]); @@ -72,10 +83,12 @@ abstract class IntegrationTest extends \Test\TestCase { $feedIds[$feed->getId()] = true; } - $result = array_filter($items, + $result = array_filter( + $items, function (Item $item) use ($feedIds) { - return array_key_exists($item->getFeedId(), $feedIds); - }); + return array_key_exists($item->getFeedId(), $feedIds); + } + ); // ok so this is funny: array_filter preserves indices, meaning that // you can't use 0 as key for the first element return from it :D @@ -84,24 +97,31 @@ abstract class IntegrationTest extends \Test\TestCase { return $result; } - protected function findFolderByName($name) { - return $this->folderMapper->where([ + protected function findFolderByName($name) + { + return $this->folderMapper->where( + [ 'userId' => $this->user, 'name' => $name - ])[0]; + ] + )[0]; } - protected function findFeedByTitle($title) { - return $this->feedMapper->where([ + protected function findFeedByTitle($title) + { + return $this->feedMapper->where( + [ 'userId' => $this->user, 'title' => $title - ])[0]; + ] + )[0]; } /** * @param string $name loads fixtures from a given file */ - protected function loadFixtures($name) { + protected function loadFixtures($name) + { $fixtures = include __DIR__ . '/Fixtures/data/' . $name . '.php'; if (array_key_exists('folders', $fixtures)) { $this->loadFolderFixtures($fixtures['folders']); @@ -111,7 +131,8 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function loadFolderFixtures(array $folderFixtures=[]) { + protected function loadFolderFixtures(array $folderFixtures=[]) + { foreach ($folderFixtures as $folderFixture) { $folder = new FolderFixture($folderFixture); $folderId = $this->loadFixture($folder); @@ -119,19 +140,21 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) { + protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) + { foreach ($feedFixtures as $feedFixture) { $feed = new FeedFixture($feedFixture); $feed->setFolderId($folderId); $feedId = $this->loadFixture($feed); if (!empty($feedFixture['items'])) { - $this->loadItemFixtures($feedFixture['items'], $feedId); - } + $this->loadItemFixtures($feedFixture['items'], $feedId); + } } } - protected function loadItemFixtures(array $itemFixtures=[], $feedId) { + protected function loadItemFixtures(array $itemFixtures=[], $feedId) + { foreach ($itemFixtures as $itemFixture) { $item = new ItemFixture($itemFixture); $item->setFeedId($feedId); @@ -141,10 +164,12 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Saves a fixture in a database and returns the saved result - * @param Entity $fixture + * + * @param Entity $fixture * @return int the id */ - protected function loadFixture(Entity $fixture) { + protected function loadFixture(Entity $fixture) + { if ($fixture instanceof FeedFixture) { return $this->feedMapper->insert($fixture)->getId(); } elseif ($fixture instanceof ItemFixture) { @@ -158,10 +183,12 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Creates and logs in a new ownCloud user + * * @param $user * @param $password */ - protected function setupUser($user, $password) { + protected function setupUser($user, $password) + { $userManager = $this->container->query(IUserManager::class); $userManager->createUser($user, $password); @@ -170,9 +197,11 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Removes a user and his News app database entries from the database + * * @param $user */ - protected function tearDownUser($user) { + protected function tearDownUser($user) + { $userManager = $this->container->query(IUserManager::class); if ($userManager->userExists($user)) { @@ -184,9 +213,11 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Deletes all news entries of a given user + * * @param string $user */ - protected function clearUserNewsDatabase($user) { + protected function clearUserNewsDatabase($user) + { $sql = [ 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` IN (SELECT `id` FROM `*PREFIX*news_feeds` WHERE `user_id` = ?)', @@ -200,7 +231,8 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function tearDown() { + protected function tearDown() + { parent::tearDown(); $this->tearDownUser($this->user); } diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php index da9dd4522..42d3c6e62 100644 --- a/tests/Unit/Config/ConfigTest.php +++ b/tests/Unit/Config/ConfigTest.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Config; @@ -17,16 +17,19 @@ use OCA\News\Config\Config; use PHPUnit_Framework_TestCase; -class ConfigTest extends PHPUnit_Framework_TestCase { +class ConfigTest extends PHPUnit_Framework_TestCase +{ private $fileSystem; private $config; private $configPath; private $loggerParams; - public function setUp() { + public function setUp() + { $this->logger = $this->getMockBuilder( - 'OCP\ILogger') + 'OCP\ILogger' + ) ->disableOriginalConstructor() ->getMock(); $this->fileSystem = $this->getMockBuilder('OCP\Files\Folder')->getMock(); @@ -38,7 +41,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testDefaults() { + public function testDefaults() + { $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); $this->assertEquals(200, $this->config->getAutoPurgeCount()); $this->assertEquals(10, $this->config->getMaxRedirects()); @@ -49,7 +53,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testRead () { + public function testRead() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -57,9 +62,11 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue($file)); $file->expects($this->once()) ->method('getContent') - ->will($this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' - )); + ->will( + $this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' + ) + ); $this->config->read($this->configPath); @@ -69,7 +76,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testReadIgnoresVeryLowPurgeInterval () { + public function testReadIgnoresVeryLowPurgeInterval() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -86,7 +94,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { - public function testReadBool () { + public function testReadBool() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -94,8 +103,10 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue($file)); $file->expects($this->once()) ->method('getContent') - ->will($this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false') + ->will( + $this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false' + ) ); $this->config->read($this->configPath); @@ -105,7 +116,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testReadLogsInvalidValue() { + public function testReadLogsInvalidValue() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -116,15 +128,20 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue('autoPurgeCounts = 3')); $this->logger->expects($this->once()) ->method('warning') - ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.'), - $this->equalTo($this->loggerParams)); + ->with( + $this->equalTo( + 'Configuration value "autoPurgeCounts" ' . + 'does not exist. Ignored value.' + ), + $this->equalTo($this->loggerParams) + ); $this->config->read($this->configPath); } - public function testReadLogsInvalidINI() { + public function testReadLogsInvalidINI() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -135,14 +152,17 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue('')); $this->logger->expects($this->once()) ->method('warning') - ->with($this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams)); + ->with( + $this->equalTo('Configuration invalid. Ignoring values.'), + $this->equalTo($this->loggerParams) + ); $this->config->read($this->configPath); } - public function testWrite () { + public function testWrite() + { $json = 'autoPurgeMinimumInterval = 60' . "\n" . 'autoPurgeCount = 3' . "\n" . 'maxRedirects = 10' . "\n" . @@ -168,7 +188,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { - public function testReadingNonExistentConfigWillWriteDefaults() { + public function testReadingNonExistentConfigWillWriteDefaults() + { $this->fileSystem->expects($this->once()) ->method('nodeExists') ->with($this->equalTo($this->configPath)) @@ -200,7 +221,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testNoLowMinimumAutoPurgeInterval() { + public function testNoLowMinimumAutoPurgeInterval() + { $this->config->setAutoPurgeMinimumInterval(59); $interval = $this->config->getAutoPurgeMinimumInterval(); @@ -208,21 +230,24 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testMinimumAutoPurgeInterval() { + public function testMinimumAutoPurgeInterval() + { $this->config->setAutoPurgeMinimumInterval(61); $interval = $this->config->getAutoPurgeMinimumInterval(); $this->assertSame(61, $interval); } - public function testMaxRedirects() { + public function testMaxRedirects() + { $this->config->setMaxRedirects(21); $redirects = $this->config->getMaxRedirects(); $this->assertSame(21, $redirects); } - public function testFeedFetcherTimeout() { + public function testFeedFetcherTimeout() + { $this->config->setFeedFetcherTimeout(2); $timout = $this->config->getFeedFetcherTimeout(); diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php index 33926d0d2..a2b7f304a 100644 --- a/tests/Unit/Controller/AdminControllerTest.php +++ b/tests/Unit/Controller/AdminControllerTest.php @@ -5,18 +5,18 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Controller; - use OCA\News\Controller\AdminController; -class AdminControllerTest extends \PHPUnit_Framework_TestCase { +class AdminControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $request; @@ -28,28 +28,35 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->configPath = 'my.ini'; - $this->controller = new AdminController($this->appName, $this->request, - $this->config, $this->itemService, $this->configPath); + $this->controller = new AdminController( + $this->appName, $this->request, + $this->config, $this->itemService, $this->configPath + ); } - public function testIndex() { + public function testIndex() + { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, @@ -92,7 +99,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate() { + public function testUpdate() + { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, diff --git a/tests/Unit/Controller/EntityApiSerializerTest.php b/tests/Unit/Controller/EntityApiSerializerTest.php index 261d5f7c4..49b7e0b8d 100644 --- a/tests/Unit/Controller/EntityApiSerializerTest.php +++ b/tests/Unit/Controller/EntityApiSerializerTest.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Controller; @@ -19,15 +19,18 @@ use \OCP\AppFramework\Db\Entity; use \OCA\News\Db\Item; -class TestEntity extends Entity { +class TestEntity extends Entity +{ } -class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { +class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase +{ - public function testSerializeSingle() { + public function testSerializeSingle() + { $item = new Item(); $item->setUnread(true); @@ -38,7 +41,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testSerializeMultiple() { + public function testSerializeMultiple() + { $item = new Item(); $item->setUnread(true); @@ -54,7 +58,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testResponseNoChange() { + public function testResponseNoChange() + { $response = new Response(); $serializer = new EntityApiSerializer('items'); @@ -64,7 +69,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testCompleteArraysTransformed() { + public function testCompleteArraysTransformed() + { $item = new Item(); $item->setUnread(true); @@ -86,7 +92,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testNoEntityNoChange() { + public function testNoEntityNoChange() + { $serializer = new EntityApiSerializer('items'); $in = [ @@ -102,7 +109,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testEntitiesNoChange() { + public function testEntitiesNoChange() + { $serializer = new EntityApiSerializer('items'); $in = [ diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 6701b38a6..592582b3a 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Controller; @@ -22,7 +22,8 @@ use \OCA\News\Db\Item; use \OCA\News\Db\Feed; -class ExportControllerTest extends \PHPUnit_Framework_TestCase { +class ExportControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $request; @@ -36,32 +37,39 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'john'; $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); $this->folderService = $this->getMockBuilder( - '\OCA\News\Service\FolderService') + '\OCA\News\Service\FolderService' + ) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder('\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->opmlExporter = new OPMLExporter(); - $this->controller = new ExportController($this->appName, $this->request, + $this->controller = new ExportController( + $this->appName, $this->request, $this->folderService, $this->feedService, - $this->itemService, $this->opmlExporter, $this->user); + $this->itemService, $this->opmlExporter, $this->user + ); } - public function testOpmlExportNoFeeds(){ + public function testOpmlExportNoFeeds() + { $opml = "\n" . "\n" . @@ -86,7 +94,8 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { } - public function testGetAllArticles(){ + public function testGetAllArticles() + { $item1 = new Item(); $item1->setFeedId(3); $item2 = new Item(); @@ -119,14 +128,16 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { $headers ['Content-Disposition'] ); - $this->assertEquals('[{"guid":null,"url":null,"title":null,' . + $this->assertEquals( + '[{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"updatedDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\/\/goo","rtl":null},{"guid":null,"url":null,' . '"title":null,"author":null,"pubDate":null,"updatedDate":null,"body":null,' . '"enclosureMime":null,"enclosureLink":null,"unread":false,' . '"starred":false,"feedLink":"http:\/\/gee","rtl":null}]', - $return->render()); + $return->render() + ); } } diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index 8c0b25873..bc91e1df8 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Controller; @@ -23,7 +23,8 @@ use \OCA\News\Db\Feed; use \OCA\News\Db\Item; -class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { +class FeedApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $feedService; private $itemService; @@ -35,24 +36,29 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { private $logger; private $loggerParams; - protected function setUp() { + protected function setUp() + { $this->user = 'tom'; $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder( - '\OCP\ILogger') + '\OCP\ILogger' + ) ->disableOriginalConstructor() ->getMock(); $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->feedAPI = new FeedApiController( @@ -68,7 +74,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex() { + public function testIndex() + { $feeds = [new Feed()]; $starredCount = 3; $newestItemId = 2; @@ -88,15 +95,18 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, 'newestItemId' => $newestItemId - ], $response); + ], $response + ); } - public function testIndexNoNewestItemId() { + public function testIndexNoNewestItemId() + { $feeds = [new Feed()]; $starredCount = 3; @@ -115,29 +125,36 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, - ], $response); + ], $response + ); } - public function testDelete() { + public function testDelete() + { $this->feedService->expects($this->once()) ->method('delete') ->with( $this->equalTo(2), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->feedAPI->delete(2); } - public function testDeleteDoesNotExist() { + 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); @@ -148,7 +165,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreate() { + public function testCreate() + { $feeds = [new Feed()]; $this->feedService->expects($this->once()) @@ -159,7 +177,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo('url'), $this->equalTo(3), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') @@ -167,14 +186,17 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('url', 3); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'newestItemId' => 3 - ], $response); + ], $response + ); } - public function testCreateNoItems() { + public function testCreateNoItems() + { $feeds = [new Feed()]; $this->feedService->expects($this->once()) @@ -185,7 +207,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo('ho'), $this->equalTo(3), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') @@ -193,14 +216,17 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('ho', 3); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()] - ], $response); + ], $response + ); } - public function testCreateExists() { + public function testCreateExists() + { $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); @@ -218,7 +244,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateError() { + public function testCreateError() + { $this->feedService->expects($this->once()) ->method('create') ->will( @@ -233,31 +260,36 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRead() { + public function testRead() + { $this->itemService->expects($this->once()) ->method('readFeed') ->with( $this->equalTo(3), $this->equalTo(30), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->feedAPI->read(3, 30); } - public function testMove() { + public function testMove() + { $this->feedService->expects($this->once()) ->method('patch') ->with( $this->equalTo(3), $this->equalTo($this->user), - $this->equalTo(['folderId' => 30])); + $this->equalTo(['folderId' => 30]) + ); $this->feedAPI->move(3, 30); } - public function testMoveDoesNotExist() { + public function testMoveDoesNotExist() + { $this->feedService->expects($this->once()) ->method('patch') ->will( @@ -272,7 +304,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRename() { + public function testRename() + { $feedId = 3; $feedTitle = 'test'; @@ -281,13 +314,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($feedId), $this->equalTo($this->user), - $this->equalTo(['title' => $feedTitle])); + $this->equalTo(['title' => $feedTitle]) + ); $this->feedAPI->rename($feedId, $feedTitle); } - public function testRenameError() { + public function testRenameError() + { $feedId = 3; $feedTitle = 'test'; @@ -296,7 +331,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($feedId), $this->equalTo($this->user), - $this->equalTo(['title' => $feedTitle])) + $this->equalTo(['title' => $feedTitle]) + ) ->will($this->throwException(new ServiceNotFoundException('hi'))); $result = $this->feedAPI->rename($feedId, $feedTitle); @@ -308,7 +344,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testfromAllUsers(){ + public function testfromAllUsers() + { $feed = new Feed(); $feed->setUrl(3); $feed->setId(1); @@ -322,7 +359,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate() { + public function testUpdate() + { $feedId = 3; $userId = 'hi'; @@ -334,7 +372,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateError() { + public function testUpdateError() + { $feedId = 3; $userId = 'hi'; $this->feedService->expects($this->once()) @@ -342,8 +381,10 @@ class FeedApiControllerTest extends \PHPUnit_Framework_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( + $this->equalTo('Could not update feed ' . $this->msg), + $this->equalTo($this->loggerParams) + ); $this->feedAPI->update($userId, $feedId); diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 4018e2174..8bff9b2eb 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -5,10 +5,10 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\Controller; @@ -22,7 +22,8 @@ use OCA\News\Service\ServiceNotFoundException; use OCA\News\Service\ServiceConflictException; -class FeedControllerTest extends \PHPUnit_Framework_TestCase { +class FeedControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $feedService; @@ -38,11 +39,13 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'jack'; $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this @@ -58,15 +61,18 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); - $this->controller = new FeedController($this->appName, $this->request, - $this->folderService, - $this->feedService, - $this->itemService, - $this->settings, - $this->user); + $this->controller = new FeedController( + $this->appName, $this->request, + $this->folderService, + $this->feedService, + $this->itemService, + $this->settings, + $this->user + ); $this->exampleResult = [ 'activeFeed' => [ 'id' => 0, @@ -76,7 +82,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex(){ + public function testIndex() + { $result = [ 'feeds' => [ ['a feed'], @@ -102,7 +109,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndexHighestItemIdExists(){ + public function testIndexHighestItemIdExists() + { $result = [ 'feeds' => [ ['a feed'], @@ -130,23 +138,29 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { - private function activeInitMocks($id, $type){ + private function activeInitMocks($id, $type) + { $this->settings->expects($this->at(0)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId')) + $this->equalTo('lastViewedFeedId') + ) ->will($this->returnValue($id)); $this->settings->expects($this->at(1)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType')) + $this->equalTo('lastViewedFeedType') + ) ->will($this->returnValue($type)); } - public function testActive(){ + public function testActive() + { $id = 3; $type = FeedType::STARRED; $result = [ @@ -164,7 +178,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveFeedDoesNotExist(){ + public function testActiveFeedDoesNotExist() + { $id = 3; $type = FeedType::FEED; $ex = new ServiceNotFoundException('hiu'); @@ -183,7 +198,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveFolderDoesNotExist(){ + public function testActiveFolderDoesNotExist() + { $id = 3; $type = FeedType::FOLDER; $ex = new ServiceNotFoundException('hiu'); @@ -202,7 +218,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveActiveIsNull(){ + public function testActiveActiveIsNull() + { $id = 3; $type = null; $result = $this->exampleResult; @@ -216,7 +233,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreate(){ + public function testCreate() + { $result = [ 'feeds' => [new Feed()], 'newestItemId' => 3 @@ -230,10 +248,12 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') - ->with($this->equalTo('hi'), + ->with( + $this->equalTo('hi'), $this->equalTo(4), $this->equalTo($this->user), - $this->equalTo('yo')) + $this->equalTo('yo') + ) ->will($this->returnValue($result['feeds'][0])); $response = $this->controller->create('hi', 4, 'yo'); @@ -242,7 +262,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateNoItems(){ + public function testCreateNoItems() + { $result = ['feeds' => [new Feed()]]; $this->feedService->expects($this->once()) @@ -255,10 +276,12 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $this->feedService->expects($this->once()) ->method('create') - ->with($this->equalTo('hi'), + ->with( + $this->equalTo('hi'), $this->equalTo(4), $this->equalTo($this->user), - $this->equalTo('yo')) + $this->equalTo('yo') + ) ->will($this->returnValue($result['feeds'][0])); $response = $this->controller->create('hi', 4, 'yo'); @@ -267,7 +290,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateReturnsErrorForInvalidCreate(){ + public function testCreateReturnsErrorForInvalidCreate() + { $msg = 'except'; $ex = new ServiceNotFoundException($msg); $this->feedService->expects($this->once()) @@ -287,7 +311,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateReturnsErrorForDuplicateCreate(){ + public function testCreateReturnsErrorForDuplicateCreate() + { $msg = 'except'; $ex = new ServiceConflictException($msg); $this->feedService->expects($this->once()) @@ -305,7