diff options
author | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2018-03-27 15:35:06 +0200 |
---|---|---|
committer | Bernhard Posselt <BernhardPosselt@users.noreply.github.com> | 2018-03-27 15:35:06 +0200 |
commit | 5b94705cf3918dc7986c6043b1fbe776bf22958f (patch) | |
tree | 4e8059818a0a913d24938e35238913a721fa6373 /tests/Unit | |
parent | f3c9d13551cef5968baea99c2f25085baee0ed5f (diff) |
Core: Fix compatibility with nextcloud codestyle (#280)
Diffstat (limited to 'tests/Unit')
34 files changed, 1752 insertions, 997 deletions
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 <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\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 <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\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 <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\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 <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<opml version=\"2.0\">\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 <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Tests\Unit\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 { |