diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-19 13:20:54 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-19 13:21:11 +0200 |
commit | 517e4ca5435106ab5304849248cbea4e9dffd4b0 (patch) | |
tree | 0f00076f012791b39c710994f695abf723546062 /utility | |
parent | bd35b98d2c130f058b182f726636ee971625823b (diff) |
split up api class for easier testing and clearer code
Diffstat (limited to 'utility')
-rw-r--r-- | utility/config.php | 12 | ||||
-rw-r--r-- | utility/controllertestutility.php | 2 | ||||
-rw-r--r-- | utility/mappertestutility.php | 23 | ||||
-rw-r--r-- | utility/testutility.php | 46 |
4 files changed, 19 insertions, 64 deletions
diff --git a/utility/config.php b/utility/config.php index d415595b7..b2416ce9a 100644 --- a/utility/config.php +++ b/utility/config.php @@ -25,7 +25,7 @@ namespace OCA\News\Utility; -use \OCA\News\Core\API; +use \OCA\News\Core\Logger; class Config { @@ -43,17 +43,17 @@ class Config { private $proxyPort; private $proxyUser; private $proxyPassword; - private $api; + private $logger; - public function __construct($fileSystem, API $api) { + public function __construct($fileSystem, Logger $logger) { $this->fileSystem = $fileSystem; $this->autoPurgeMinimumInterval = 60; $this->autoPurgeCount = 200; $this->simplePieCacheDuration = 30*60; $this->feedFetcherTimeout = 60; $this->useCronUpdates = true; - $this->api = $api; + $this->logger = $logger; $this->proxyHost = ''; $this->proxyPort = 8080; $this->proxyUser = ''; @@ -162,7 +162,7 @@ class Config { $configValues = parse_ini_string($content); if($configValues === false || count($configValues) === 0) { - $this->api->log('Configuration invalid. Ignoring values.' , 'warn'); + $this->logger->log('Configuration invalid. Ignoring values.' , 'warn'); } else { foreach($configValues as $key => $value) { @@ -171,7 +171,7 @@ class Config { settype($value, $type); $this->$key = $value; } else { - $this->api->log('Configuration value "' . $key . + $this->logger->log('Configuration value "' . $key . '" does not exist. Ignored value.' , 'warn'); } } diff --git a/utility/controllertestutility.php b/utility/controllertestutility.php index d3cc435e3..ab534bfc6 100644 --- a/utility/controllertestutility.php +++ b/utility/controllertestutility.php @@ -31,7 +31,7 @@ use OCP\AppFramework\Http\Response; /** * Simple utility class for testing controllers */ -abstract class ControllerTestUtility extends TestUtility { +abstract class ControllerTestUtility extends \PHPUnit_Framework_TestCase { /** diff --git a/utility/mappertestutility.php b/utility/mappertestutility.php index d78e717aa..27b513f15 100644 --- a/utility/mappertestutility.php +++ b/utility/mappertestutility.php @@ -24,16 +24,16 @@ namespace OCA\News\Utility; -use OCA\News\Core\Api; +use OCA\News\Core\Db; /** * Simple utility class for testing mappers */ -abstract class MapperTestUtility extends TestUtility { +abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { - protected $api; + protected $db; private $query; private $pdoResult; private $queryAt; @@ -44,12 +44,13 @@ abstract class MapperTestUtility extends TestUtility { /** * Run this function before the actual test to either set or initialize the - * api. After this the api can be accessed by using $this->api + * db. After this the db can be accessed by using $this->db */ protected function beforeEach(){ - $this->api = $this->getMock('\OCA\News\Core\API', - array('prepareQuery', 'getInsertId'), - array('a')); + $this->db = $this->getMockBuilder( + '\OCA\News\Core\Db') + ->disableOriginalConstructor() + ->getMock(); $this->query = $this->getMock('Query', array('execute', 'bindValue')); $this->pdoResult = $this->getMock('Result', array('fetchRow')); @@ -127,24 +128,24 @@ abstract class MapperTestUtility extends TestUtility { $this->queryAt++; if($limit === null && $offset === null) { - $this->api->expects($this->at($this->prepareAt)) + $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') ->with($this->equalTo($sql)) ->will(($this->returnValue($this->query))); } elseif($limit !== null && $offset === null) { - $this->api->expects($this->at($this->prepareAt)) + $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') ->with($this->equalTo($sql), $this->equalTo($limit)) ->will(($this->returnValue($this->query))); } elseif($limit === null && $offset !== null) { - $this->api->expects($this->at($this->prepareAt)) + $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') ->with($this->equalTo($sql), $this->equalTo(null), $this->equalTo($offset)) ->will(($this->returnValue($this->query))); } else { - $this->api->expects($this->at($this->prepareAt)) + $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') ->with($this->equalTo($sql), $this->equalTo($limit), diff --git a/utility/testutility.php b/utility/testutility.php deleted file mode 100644 index 8e79147d9..000000000 --- a/utility/testutility.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -/** - * ownCloud - News - * - * @author Bernhard Posselt - * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -namespace OCA\News\Utility; - -/** - * Simple utility class for testing anything using an api - */ -abstract class TestUtility extends \PHPUnit_Framework_TestCase { - - - /** - * Boilerplate function for getting an API Mock class - * @param string $apiClass the class inclusive namespace of the api that we - * want to use - * @param array $constructor constructor parameters of the api class - */ - protected function getAPIMock($apiClass='OCA\News\Core\API', - array $constructor=array('appname')){ - $methods = get_class_methods($apiClass); - return $this->getMock($apiClass, $methods, $constructor); - } - - -}
\ No newline at end of file |