From 517e4ca5435106ab5304849248cbea4e9dffd4b0 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 19 Apr 2014 13:20:54 +0200 Subject: split up api class for easier testing and clearer code --- tests/unit/businesslayer/BusinessLayerTest.php | 4 +--- tests/unit/businesslayer/FeedBusinessLayerTest.php | 26 ++++++++++------------ .../unit/businesslayer/FolderBusinessLayerTest.php | 19 +++++----------- tests/unit/businesslayer/ItemBusinessLayerTest.php | 4 +--- tests/unit/businesslayer/StatusFlagTest.php | 2 +- 5 files changed, 21 insertions(+), 34 deletions(-) (limited to 'tests/unit/businesslayer') diff --git a/tests/unit/businesslayer/BusinessLayerTest.php b/tests/unit/businesslayer/BusinessLayerTest.php index 7f3677d18..54ca11cba 100644 --- a/tests/unit/businesslayer/BusinessLayerTest.php +++ b/tests/unit/businesslayer/BusinessLayerTest.php @@ -39,14 +39,12 @@ class TestBusinessLayer extends BusinessLayer { } } -class BusinessLayerTest extends \OCA\News\Utility\TestUtility { +class BusinessLayerTest extends \PHPUnit_Framework_TestCase { - protected $api; protected $mapper; protected $newsBusinessLayer; protected function setUp(){ - $this->api = $this->getAPIMock(); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 19ff7da7f..f856f2ca6 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -34,7 +34,7 @@ use \OCA\News\Db\Item; use \OCA\News\Fetcher\Fetcher; use \OCA\News\Fetcher\FetcherException; -class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { +class FeedBusinessLayerTest extends \PHPUnit_Framework_TestCase { private $feedMapper; private $feedBusinessLayer; @@ -48,9 +48,15 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { private $autoPurgeMinimumInterval; private $enhancer; private $purifier; + private $l10n; + private $logger; protected function setUp(){ - $this->api = $this->getAPIMock(); + $this->logger = $this->getMockBuilder( + '\OCA\News\Core\Logger') + ->disableOriginalConstructor() + ->getMock(); + $this->l10n = $this->getMock('L10N', array('t')); $this->time = 222; $this->autoPurgeMinimumInterval = 10; $timeFactory = $this->getMock('TimeFactory', array('getTime')); @@ -79,7 +85,7 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper, - $this->fetcher, $this->itemMapper, $this->api, + $this->fetcher, $this->itemMapper, $this->logger, $this->l10n, $timeFactory, $config, $this->enhancer, $this->purifier); $this->user = 'jack'; @@ -101,12 +107,8 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { public function testCreateDoesNotFindFeed(){ $ex = new FetcherException('hi'); $url = 'test'; - $trans = $this->getMock('Trans', array('t')); - $trans->expects($this->once()) + $this->l10n->expects($this->once()) ->method('t'); - $this->api->expects($this->once()) - ->method('getTrans') - ->will($this->returnValue($trans)); $this->fetcher->expects($this->once()) ->method('fetch') ->with($this->equalTo($url)) @@ -361,7 +363,7 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { $this->fetcher->expects($this->once()) ->method('fetch') ->will($this->throwException($ex)); - $this->api->expects($this->any()) + $this->logger->expects($this->any()) ->method('log'); $this->feedMapper->expects($this->at(1)) @@ -601,17 +603,13 @@ class FeedBusinessLayerTest extends \OCA\News\Utility\TestUtility { $insertFeed->setPreventUpdate(true); $insertFeed->setFolderId(0); - $trans = $this->getMock('trans', array('t')); - $trans->expects($this->once()) + $this->l10n->expects($this->once()) ->method('t') ->will($this->returnValue('Articles without feed')); $this->feedMapper->expects($this->once()) ->method('findAllFromUser') ->with($this->equalTo($this->user)) ->will($this->returnValue($feeds)); - $this->api->expects($this->once()) - ->method('getTrans') - ->will($this->returnValue($trans)); $this->feedMapper->expects($this->once()) ->method('insert') ->with($this->equalTo($insertFeed)) diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php index 17eb1b8ae..22b9e53d0 100644 --- a/tests/unit/businesslayer/FolderBusinessLayerTest.php +++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php @@ -31,16 +31,17 @@ require_once(__DIR__ . "/../../classloader.php"); use \OCA\News\Db\Folder; -class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility { +class FolderBusinessLayerTest extends \PHPUnit_Framework_TestCase { private $folderMapper; private $folderBusinessLayer; private $time; private $user; private $autoPurgeMinimumInterval; + private $l10n; protected function setUp(){ - $this->api = $this->getAPIMock(); + $this->l10n = $this->getMock('L10N', array('t')); $this->time = 222; $timeFactory = $this->getMock('TimeFactory', array('getTime')); $timeFactory->expects($this->any()) @@ -59,7 +60,7 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility { ->method('getAutoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->folderBusinessLayer = new FolderBusinessLayer( - $this->folderMapper, $this->api, $timeFactory, + $this->folderMapper, $this->l10n, $timeFactory, $config); $this->user = 'hi'; } @@ -103,12 +104,8 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility { array('id' => 1) ); - $trans = $this->getMock('Trans', array('t')); - $trans->expects($this->once()) + $this->l10n->expects($this->once()) ->method('t'); - $this->api->expects($this->once()) - ->method('getTrans') - ->will($this->returnValue($trans)); $this->folderMapper->expects($this->once()) ->method('findByName') ->with($this->equalTo($folderName)) @@ -179,12 +176,8 @@ class FolderBusinessLayerTest extends \OCA\News\Utility\TestUtility { array('id' => 1) ); - $trans = $this->getMock('Trans', array('t')); - $trans->expects($this->once()) + $this->l10n->expects($this->once()) ->method('t'); - $this->api->expects($this->once()) - ->method('getTrans') - ->will($this->returnValue($trans)); $this->folderMapper->expects($this->once()) ->method('findByName') ->with($this->equalTo($folderName)) diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php index a3e7f7a14..f0f9d1906 100644 --- a/tests/unit/businesslayer/ItemBusinessLayerTest.php +++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php @@ -33,9 +33,8 @@ use \OCA\News\Db\StatusFlag; use \OCA\News\Db\FeedType; -class ItemBusinessLayerTest extends \OCA\News\Utility\TestUtility { +class ItemBusinessLayerTest extends \PHPUnit_Framework_TestCase { - private $api; private $mapper; private $itemBusinessLayer; private $user; @@ -51,7 +50,6 @@ class ItemBusinessLayerTest extends \OCA\News\Utility\TestUtility { $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->api = $this->getAPIMock(); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/unit/businesslayer/StatusFlagTest.php b/tests/unit/businesslayer/StatusFlagTest.php index d503b6630..d96f40a6b 100644 --- a/tests/unit/businesslayer/StatusFlagTest.php +++ b/tests/unit/businesslayer/StatusFlagTest.php @@ -29,7 +29,7 @@ namespace OCA\News\Db; require_once(__DIR__ . "/../../classloader.php"); -class StatusFlagTest extends \OCA\News\Utility\TestUtility { +class StatusFlagTest extends \PHPUnit_Framework_TestCase { private $statusFlag; -- cgit v1.2.3