summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Service
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-09-20 22:03:05 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-25 19:18:04 +0200
commit60ab4941cc7e6ede095e9e4aee3c2bf9a5c3bff6 (patch)
treebaf0b07dd1c545efeb59437af46a99f4d9f69425 /tests/Unit/Service
parent2c8b4fa019749113658b9ed8cae211b679e4cbc0 (diff)
Move to nextcloud config and update phpunit
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Service')
-rw-r--r--tests/Unit/Service/FeedServiceTest.php73
-rw-r--r--tests/Unit/Service/FolderServiceTest.php44
-rw-r--r--tests/Unit/Service/ItemServiceTest.php214
-rw-r--r--tests/Unit/Service/ServiceTest.php2
-rw-r--r--tests/Unit/Service/StatusServiceTest.php197
5 files changed, 332 insertions, 198 deletions
diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php
index 76c8f89f6..84c2121ed 100644
--- a/tests/Unit/Service/FeedServiceTest.php
+++ b/tests/Unit/Service/FeedServiceTest.php
@@ -16,7 +16,7 @@ namespace OCA\News\Tests\Unit\Service;
use FeedIo\Reader\ReadErrorException;
-use OCA\News\Config\Config;
+use OC\L10N\L10N;
use OCA\News\Db\FeedMapper;
use OCA\News\Db\ItemMapper;
use OCA\News\Service\FeedService;
@@ -28,6 +28,7 @@ use OCA\News\Db\Feed;
use OCA\News\Db\Item;
use OCA\News\Fetcher\Fetcher;
use OCA\News\Fetcher\FetcherException;
+use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -37,28 +38,60 @@ use PHPUnit\Framework\TestCase;
class FeedServiceTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|FeedMapper
+ */
private $feedMapper;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper
+ */
+ private $itemMapper;
+
/** @var FeedService */
private $feedService;
+
+ /**
+ * @var string
+ */
private $user;
- private $response;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|Fetcher
+ */
private $fetcher;
- private $itemMapper;
- private $threshold;
+
+ /**
+ * @var int
+ */
private $time;
- private $importParser;
+
+ /**
+ * @var int
+ */
private $autoPurgeMinimumInterval;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|\HTMLPurifier
+ */
private $purifier;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|L10N
+ */
private $l10n;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|ILogger
+ */
private $logger;
- private $loggerParams;
- protected function setUp()
+ protected function setUp(): void
{
$this->logger = $this->getMockBuilder(ILogger::class)
->disableOriginalConstructor()
->getMock();
- $this->loggerParams = ['hi'];
+ $loggerParams = ['hi'];
$this->time = 222;
$this->autoPurgeMinimumInterval = 10;
$timeFactory = $this->getMockBuilder(Time::class)
@@ -86,31 +119,34 @@ class FeedServiceTest extends TestCase
->getMockBuilder(\HTMLPurifier::class)
->disableOriginalConstructor()
->getMock();
- $config = $this->getMockBuilder(Config::class)
+ $config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
- ->method('getAutoPurgeMinimumInterval')
+ ->method('getAppValue')
+ ->with('news', 'autoPurgeMinimumInterval')
->will($this->returnValue($this->autoPurgeMinimumInterval));
$this->feedService = new FeedService(
$this->feedMapper,
$this->fetcher, $this->itemMapper, $this->logger, $this->l10n,
- $timeFactory, $config, $this->purifier, $this->loggerParams
+ $timeFactory, $config, $this->purifier, $loggerParams
);
$this->user = 'jack';
}
-
+ /**
+ * @covers \OCA\News\Service\FeedService::findAll
+ */
public function testFindAll()
{
$this->feedMapper->expects($this->once())
->method('findAllFromUser')
- ->with($this->equalTo($this->user))
- ->will($this->returnValue($this->response));
+ ->with($this->user)
+ ->will($this->returnValue([]));
$result = $this->feedService->findAll($this->user);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals([], $result);
}
@@ -120,7 +156,7 @@ class FeedServiceTest extends TestCase
$url = 'test';
$this->fetcher->expects($this->once())
->method('fetch')
- ->with($this->equalTo($url))
+ ->with($url)
->will($this->throwException($ex));
$this->expectException(ServiceNotFoundException::class);
$this->feedService->create($url, 1, $this->user);
@@ -1145,12 +1181,9 @@ class FeedServiceTest extends TestCase
$this->feedService->patch(3, $this->user, ['fullTextEnabled' => true]);
}
-
- /**
- * @expectedException OCA\News\Service\ServiceNotFoundException
- */
public function testPatchDoesNotExist()
{
+ $this->expectException('OCA\News\Service\ServiceNotFoundException');
$feed = Feed::fromRow(['id' => 3]);
$this->feedMapper->expects($this->once())
->method('find')
diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php
index 47c1c9a8d..4086f55e1 100644
--- a/tests/Unit/Service/FolderServiceTest.php
+++ b/tests/Unit/Service/FolderServiceTest.php
@@ -13,13 +13,14 @@
namespace OCA\News\Tests\Unit\Service;
-use OCA\News\Config\Config;
+use OC\L10N\L10N;
use \OCA\News\Db\Folder;
use OCA\News\Db\FolderMapper;
use OCA\News\Service\FolderService;
use OCA\News\Service\ServiceConflictException;
use OCA\News\Service\ServiceValidationException;
use OCA\News\Utility\Time;
+use OCP\IConfig;
use OCP\IL10N;
use PHPUnit\Framework\TestCase;
@@ -28,14 +29,37 @@ use PHPUnit\Framework\TestCase;
class FolderServiceTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|FolderMapper
+ */
private $folderMapper;
+
+ /**
+ * @var FolderService
+ */
private $folderService;
+
+ /**
+ * @var int
+ */
private $time;
+
+ /**
+ * @var string
+ */
private $user;
+
+ /**
+ * @var int
+ */
private $autoPurgeMinimumInterval;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|L10N
+ */
private $l10n;
- protected function setUp()
+ protected function setUp(): void
{
$this->l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()
@@ -51,11 +75,12 @@ class FolderServiceTest extends TestCase
->disableOriginalConstructor()
->getMock();
$this->autoPurgeMinimumInterval = 10;
- $config = $this->getMockBuilder(Config::class)
+ $config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
- ->method('getAutoPurgeMinimumInterval')
+ ->method('getAppValue')
+ ->with('news', 'autoPurgeMinimumInterval')
->will($this->returnValue($this->autoPurgeMinimumInterval));
$this->folderService = new FolderService(
$this->folderMapper, $this->l10n, $timeFactory, $config
@@ -119,11 +144,10 @@ class FolderServiceTest extends TestCase
$this->folderService->create($folderName, 'john', 3);
}
- /**
- * @expectedException \OCA\News\Service\ServiceValidationException
- */
public function testCreateThrowsExWhenFolderNameEmpty()
{
+ $this->expectException('OCA\News\Service\ServiceValidationException');
+
$folderName = '';
$this->folderMapper->expects($this->once())
@@ -211,7 +235,7 @@ class FolderServiceTest extends TestCase
}
- public function testMarkDeleted()
+ public function testMarkDeleted()
{
$id = 3;
$folder = new Folder();
@@ -230,7 +254,7 @@ class FolderServiceTest extends TestCase
}
- public function testUnmarkDeleted()
+ public function testUnmarkDeleted()
{
$id = 3;
$folder = new Folder();
@@ -295,7 +319,7 @@ class FolderServiceTest extends TestCase
}
- public function testDeleteUser()
+ public function testDeleteUser()
{
$this->folderMapper->expects($this->once())
->method('deleteUser')
diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php
index 9a89d2e1a..e56add152 100644
--- a/tests/Unit/Service/ItemServiceTest.php
+++ b/tests/Unit/Service/ItemServiceTest.php
@@ -13,7 +13,6 @@
namespace OCA\News\Tests\Unit\Service;
-use OCA\News\Config\Config;
use OCA\News\Db\ItemMapper;
use OCA\News\Service\ItemService;
use OCA\News\Service\ServiceNotFoundException;
@@ -30,20 +29,26 @@ use PHPUnit\Framework\TestCase;
class ItemServiceTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper
+ */
private $mapper;
/**
- * @var ItemService
+ * @var ItemService
*/
private $itemService;
- private $user;
- private $response;
- private $status;
+
+ /**
+ * @var int
+ */
private $time;
- private $newestItemId;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IConfig
+ */
private $config;
- private $systemConfig;
- protected function setUp()
+ protected function setUp(): void
{
$this->time = 222;
$this->timeFactory = $this->getMockBuilder(Time::class)
@@ -58,23 +63,10 @@ class ItemServiceTest extends TestCase
$this->mapper = $this->getMockBuilder(ItemMapper::class)
->disableOriginalConstructor()
->getMock();
- $this->config = $this->getMockBuilder(Config::class)
+ $this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
- $this->systemConfig = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->itemService = new ItemService(
- $this->mapper,
- $this->timeFactory, $this->config, $this->systemConfig
- );
- $this->user = 'jack';
- $this->id = 3;
- $this->updatedSince = 20333;
- $this->showAll = true;
- $this->offset = 5;
- $this->limit = 20;
- $this->newestItemId = 4;
+ $this->itemService = new ItemService($this->mapper, $this->timeFactory, $this->config);
}
@@ -84,18 +76,15 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllNewFeed')
->with(
- $this->equalTo($this->id),
- $this->equalTo($this->updatedSince),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user)
+ $this->equalTo(3),
+ $this->equalTo(20333),
+ $this->equalTo(true),
+ $this->equalTo('jack')
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue([]));
- $result = $this->itemService->findAllNew(
- $this->id, $type, $this->updatedSince, $this->showAll,
- $this->user
- );
- $this->assertEquals($this->response, $result);
+ $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack');
+ $this->assertEquals([], $result);
}
@@ -105,18 +94,15 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllNewFolder')
->with(
- $this->equalTo($this->id),
- $this->equalTo($this->updatedSince),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user)
+ $this->equalTo(3),
+ $this->equalTo(20333),
+ $this->equalTo(true),
+ $this->equalTo('jack')
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
- $result = $this->itemService->findAllNew(
- $this->id, $type, $this->updatedSince, $this->showAll,
- $this->user
- );
- $this->assertEquals($this->response, $result);
+ $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack');
+ $this->assertEquals(['val'], $result);
}
@@ -126,18 +112,18 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllNew')
->with(
- $this->equalTo($this->updatedSince),
+ $this->equalTo(20333),
$this->equalTo($type),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user)
+ $this->equalTo(true),
+ $this->equalTo('jack')
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
$result = $this->itemService->findAllNew(
- $this->id, $type, $this->updatedSince, $this->showAll,
- $this->user
+ 3, $type, 20333, true,
+ 'jack'
);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals(['val'], $result);
}
@@ -147,21 +133,21 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllFeed')
->with(
- $this->equalTo($this->id),
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($this->showAll),
+ $this->equalTo(3),
+ $this->equalTo(20),
+ $this->equalTo(5),
+ $this->equalTo(true),
$this->equalTo(false),
- $this->equalTo($this->user),
+ $this->equalTo('jack'),
$this->equalTo([])
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
$result = $this->itemService->findAll(
- $this->id, $type, $this->limit, $this->offset,
- $this->showAll, false, $this->user
+ 3, $type, 20, 5,
+ true, false, 'jack'
);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals(['val'], $result);
}
@@ -171,21 +157,21 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllFolder')
->with(
- $this->equalTo($this->id),
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($this->showAll),
+ $this->equalTo(3),
+ $this->equalTo(20),
+ $this->equalTo(5),
+ $this->equalTo(true),
$this->equalTo(true),
- $this->equalTo($this->user),
+ $this->equalTo('jack'),
$this->equalTo([])
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
$result = $this->itemService->findAll(
- $this->id, $type, $this->limit, $this->offset,
- $this->showAll, true, $this->user
+ 3, $type, 20, 5,
+ true, true, 'jack'
);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals(['val'], $result);
}
@@ -195,21 +181,21 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAll')
->with(
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
+ $this->equalTo(20),
+ $this->equalTo(5),
$this->equalTo($type),
- $this->equalTo($this->showAll),
$this->equalTo(true),
- $this->equalTo($this->user),
+ $this->equalTo(true),
+ $this->equalTo('jack'),
$this->equalTo([])
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
$result = $this->itemService->findAll(
- $this->id, $type, $this->limit, $this->offset,
- $this->showAll, true, $this->user
+ 3, $type, 20, 5,
+ true, true, 'jack'
);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals(['val'], $result);
}
@@ -220,21 +206,21 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAll')
->with(
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
+ $this->equalTo(20),
+ $this->equalTo(5),
$this->equalTo($type),
- $this->equalTo($this->showAll),
$this->equalTo(true),
- $this->equalTo($this->user),
+ $this->equalTo(true),
+ $this->equalTo('jack'),
$this->equalTo($search)
)
- ->will($this->returnValue($this->response));
+ ->will($this->returnValue(['val']));
$result = $this->itemService->findAll(
- $this->id, $type, $this->limit, $this->offset,
- $this->showAll, true, $this->user, $search
+ 3, $type, 20, 5,
+ true, true, 'jack', $search
);
- $this->assertEquals($this->response, $result);
+ $this->assertEquals(['val'], $result);
}
@@ -260,7 +246,7 @@ class ItemServiceTest extends TestCase
->with(
$this->equalTo($guidHash),
$this->equalTo($feedId),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
)
->will($this->returnValue($item));
@@ -268,7 +254,7 @@ class ItemServiceTest extends TestCase
->method('update')
->with($this->equalTo($expectedItem));
- $this->itemService->star($feedId, $guidHash, true, $this->user);
+ $this->itemService->star($feedId, $guidHash, true, 'jack');
$this->assertTrue($item->isStarred());
}
@@ -296,7 +282,7 @@ class ItemServiceTest extends TestCase
->with(
$this->equalTo($guidHash),
$this->equalTo($feedId),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
)
->will($this->returnValue($item));
@@ -304,7 +290,7 @@ class ItemServiceTest extends TestCase
->method('update')
->with($this->equalTo($expectedItem));
- $this->itemService->star($feedId, $guidHash, false, $this->user);
+ $this->itemService->star($feedId, $guidHash, false, 'jack');
$this->assertFalse($item->isStarred());
}
@@ -329,11 +315,11 @@ class ItemServiceTest extends TestCase
$this->equalTo($itemId),
$this->equalTo(true),
$this->equalTo($this->time),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
)
->will($this->returnValue($item));
- $this->itemService->read($itemId, true, $this->user);
+ $this->itemService->read($itemId, true, 'jack');
}
@@ -345,7 +331,7 @@ class ItemServiceTest extends TestCase
->method('readItem')
->will($this->throwException(new DoesNotExistException('')));
- $this->itemService->read(1, true, $this->user);
+ $this->itemService->read(1, true, 'jack');
}
public function testStarDoesNotExist()
@@ -356,7 +342,7 @@ class ItemServiceTest extends TestCase
->method('findByGuidHash')
->will($this->throwException(new DoesNotExistException('')));
- $this->itemService->star(1, 'hash', true, $this->user);
+ $this->itemService->star(1, 'hash', true, 'jack');
}
@@ -369,10 +355,10 @@ class ItemServiceTest extends TestCase
->with(
$this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
);
- $this->itemService->readAll($highestItemId, $this->user);
+ $this->itemService->readAll($highestItemId, 'jack');
}
@@ -387,10 +373,10 @@ class ItemServiceTest extends TestCase
$this->equalTo($folderId),
$this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
);
- $this->itemService->readFolder($folderId, $highestItemId, $this->user);
+ $this->itemService->readFolder($folderId, $highestItemId, 'jack');
}
@@ -405,17 +391,18 @@ class ItemServiceTest extends TestCase
$this->equalTo($feedId),
$this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user)
+ $this->equalTo('jack')
);
- $this->itemService->readFeed($feedId, $highestItemId, $this->user);
+ $this->itemService->readFeed($feedId, $highestItemId, 'jack');
}
public function testAutoPurgeOldWillPurgeOld()
{
$this->config->expects($this->once())
- ->method('getAutoPurgeCount')
+ ->method('getAppValue')
+ ->with('news', 'autoPurgeCount')
->will($this->returnValue(2));
$this->mapper->expects($this->once())
->method('deleteReadOlderThanThreshold')
@@ -427,7 +414,8 @@ class ItemServiceTest extends TestCase
public function testAutoPurgeOldWontPurgeOld()
{
$this->config->expects($this->once())
- ->method('getAutoPurgeCount')
+ ->method('getAppValue')
+ ->with('news', 'autoPurgeCount')
->will($this->returnValue(-1));
$this->mapper->expects($this->never())
->method('deleteReadOlderThanThreshold');
@@ -436,23 +424,23 @@ class ItemServiceTest extends TestCase
}
- public function testGetNewestItemId()
+ public function testGetNewestItemId()
{
$this->mapper->expects($this->once())
->method('getNewestItemId')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo('jack'))
->will($this->returnValue(12));
- $result = $this->itemService->getNewestItemId($this->user);
+ $result = $this->itemService->getNewestItemId('jack');
$this->assertEquals(12, $result);
}
- public function testGetNewestItemIdDoesNotExist()
+ public function testGetNewestItemIdDoesNotExist()
{
$this->mapper->expects($this->once())
->method('getNewestItemId')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo('jack'))
->will(
$this->throwException(
new DoesNotExistException('There are no items')
@@ -460,7 +448,7 @@ class ItemServiceTest extends TestCase
);
$this->expectException(ServiceNotFoundException::class);
- $this->itemService->getNewestItemId($this->user);
+ $this->itemService->getNewestItemId('jack');
}
@@ -470,10 +458,10 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('starredCount')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo('jack'))
->will($this->returnValue($star));
- $result = $this->itemService->starredCount($this->user);
+ $result = $this->itemService->starredCount('jack');
$this->assertEquals($star, $result);
}
@@ -485,22 +473,22 @@ class ItemServiceTest extends TestCase
$this->mapper->expects($this->once())
->method('findAllUnreadOrStarred')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo('jack'))
->will($this->returnValue($star));
- $result = $this->itemService->getUnreadOrStarred($this->user);
+ $result = $this->itemService->getUnreadOrStarred('jack');
$this->assertEquals($star, $result);
}
- public function testDeleteUser()
+ public function testDeleteUser()
{
$this->mapper->expects($this->once())
->method('deleteUser')
- ->will($this->returnValue($this->user));
+ ->will($this->returnValue('jack'));
- $this->itemService->deleteUser($this->user);
+ $this->itemService->deleteUser('jack');
}
diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php
index eb1898290..8f601be46 100644
--- a/tests/Unit/Service/ServiceTest.php
+++ b/tests/Unit/Service/ServiceTest.php
@@ -37,7 +37,7 @@ class ServiceTest extends TestCase
protected $mapper;
protected $newsService;
- protected function setUp()
+ protected function setUp(): void
{
$this->mapper = $this->getMockBuilder(ItemMapper::class)
->disableOriginalConstructor()
diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php
index 8c42997a0..ee2e19614 100644
--- a/tests/Unit/Service/StatusServiceTest.php
+++ b/tests/Unit/Service/StatusServiceTest.php
@@ -13,8 +13,6 @@
namespace OCA\News\Tests\Unit\Service;
-use OCA\News\Config\Config;
-use \OCA\News\Db\FeedType;
use OCA\News\Service\StatusService;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -23,83 +21,174 @@ use PHPUnit\Framework\TestCase;
class StatusServiceTest extends TestCase
{
-
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IConfig
+ */
private $settings;
- private $config;
+
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection
+ */
+ private $connection;
+
+ /**
+ * @var StatusService
+ */
private $service;
- private $appName;
- public function setUp()
+ public function setUp(): void
{
- $this->appName = 'news';
$this->settings = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
- $this->config = $this->getMockBuilder(Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->db = $this->getMockBuilder(IDBConnection::class)
+ $this->connection = $this->getMockBuilder(IDBConnection::class)
->disableOriginalConstructor()
->getMock();
- $this->service = new StatusService(
- $this->settings, $this->db,
- $this->config, $this->appName
- );
- }
-
- private function beforeStatus($cronMode='cron', $cronEnabled=true,
- $version='1.0'
- ) {
- $this->settings->expects($this->at(0))
- ->method('getAppValue')
- ->with(
- $this->equalTo($this->appName),
- $this->equalTo('installed_version')
- )
- ->will($this->returnValue($version));
-
- $this->settings->expects($this->at(1))
- ->method('getAppValue')
- ->with(
- $this->equalTo('core'),
- $this->equalTo('backgroundjobs_mode')
- )
- ->will($this->returnValue($cronMode));
-
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue($cronEnabled));
-
+ $this->service = new StatusService($this->settings, $this->connection, 'news');
}
-
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
public function testGetStatus()
{
- $this->beforeStatus();
-
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, true],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('cron'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => false,
+ 'incorrectDbCharset' => false,
+ ],
+ ];
$response = $this->service->getStatus();
- $this->assertEquals('1.0', $response['version']);
- $this->assertFalse($response['warnings']['improperlyConfiguredCron']);
+ $this->assertEquals($expected, $response);
}
-
+ /**
+ * @covers \OCA\News\Service\StatusService::getStatus
+ */
public function testGetStatusNoCorrectCronAjax()
{
- $this->beforeStatus('ajax');
-
+ $this->settings->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->withConsecutive(
+ ['news', 'installed_version'],
+ ['news', 'useCronUpdates']
+ )
+ ->will($this->returnValueMap([
+ ['news', 'installed_version', '', '1.0'],
+ ['news', 'useCronUpdates', true, true],
+ ]));
+
+ $this->settings->expects($this->exactly(1))
+ ->method('getSystemValue')
+ ->with('backgroundjobs_mode')
+ ->will($this->returnValue('ajax'));
+
+ $this->connection->expects($this->exactly(1))
+ ->method('supports4ByteText')
+ ->will($this->returnValue(true));
+
+ $expected = [
+ 'version' => '1.0',
+ 'warnings' => [
+ 'improperlyConfiguredCron' => true,
+ 'incorrectDbCharset' => false,
+ ],
+ ];
$response = $this->service->getStatus();
- $this->assertTrue($response['warnings']['improperlyConfiguredCron']);
+ $this->assertEquals($expected, $response);
}
-
-
+ /**
+ * @covers \OCA\News\Service\StatusService: