Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-04-19 12:37:59 +0300
committerJoas Schilling <coding@schilljs.com>2017-04-19 12:37:59 +0300
commita2346e6a8fef52d7a466c86468e4ed4786bcad55 (patch)
tree5f15464a954ad8df08052964a495459d3e783176
parent280e707c2a52e776f3ec410ce02a7d8d11d4dabd (diff)
Fix existing tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--tests/Unit/AppInfo/AppTest.php12
-rw-r--r--tests/Unit/AppTest.php62
2 files changed, 53 insertions, 21 deletions
diff --git a/tests/Unit/AppInfo/AppTest.php b/tests/Unit/AppInfo/AppTest.php
index 0b1ccea..9e4ec8f 100644
--- a/tests/Unit/AppInfo/AppTest.php
+++ b/tests/Unit/AppInfo/AppTest.php
@@ -22,6 +22,7 @@
namespace OCA\Notifications\Tests\Unit\AppInfo;
+use OC\User\Session;
use OCA\Notifications\App;
use OCA\Notifications\Tests\Unit\TestCase;
use OCP\IRequest;
@@ -46,14 +47,9 @@ class AppTest extends TestCase {
protected function setUp() {
parent::setUp();
- $this->manager = $this->getMockBuilder(IManager::class)
- ->getMock();
-
- $this->request = $this->getMockBuilder(IRequest::class)
- ->getMock();
-
- $this->session = $this->getMockBuilder(IUserSession::class)
- ->getMock();
+ $this->manager = $this->createMock(IManager::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->session = $this->createMock(Session::class);
$this->overwriteService('NotificationManager', $this->manager);
$this->overwriteService('Request', $this->request);
diff --git a/tests/Unit/AppTest.php b/tests/Unit/AppTest.php
index 691a562..64e395f 100644
--- a/tests/Unit/AppTest.php
+++ b/tests/Unit/AppTest.php
@@ -25,12 +25,14 @@ namespace OCA\Notifications\Tests\Unit;
use OCA\Notifications\App;
use OCA\Notifications\Handler;
+use OCA\Notifications\Push;
use OCP\Notification\INotification;
class AppTest extends TestCase {
/** @var Handler|\PHPUnit_Framework_MockObject_MockObject */
protected $handler;
-
+ /** @var Push|\PHPUnit_Framework_MockObject_MockObject */
+ protected $push;
/** @var INotification|\PHPUnit_Framework_MockObject_MockObject */
protected $notification;
@@ -40,34 +42,68 @@ class AppTest extends TestCase {
protected function setUp() {
parent::setUp();
- $this->handler = $this->getMockBuilder(Handler::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->notification = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->handler = $this->createMock(Handler::class);
+ $this->push = $this->createMock(Push::class);
+ $this->notification = $this->createMock(INotification::class);
$this->app = new App(
- $this->handler
+ $this->handler,
+ $this->push
);
}
- public function testNotify() {
+ public function dataNotify() {
+ return [
+ [23, 'user1'],
+ [42, 'user2'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataNotify
+ *
+ * @param int $id
+ * @param string $user
+ */
+ public function testNotify($id, $user) {
+ $this->notification->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
+
$this->handler->expects($this->once())
->method('add')
+ ->with($this->notification)
+ ->willReturn($id);
+ $this->handler->expects($this->once())
+ ->method('getById')
+ ->with($id, $user)
+ ->willReturn($this->notification);
+ $this->push->expects($this->once())
+ ->method('pushToDevice')
->with($this->notification);
$this->app->notify($this->notification);
}
- public function testGetCount() {
+ public function dataGetCount() {
+ return [
+ [23],
+ [42],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetCount
+ *
+ * @param int $count
+ */
+ public function testGetCount($count) {
$this->handler->expects($this->once())
->method('count')
->with($this->notification)
- ->willReturn(42);
+ ->willReturn($count);
- $this->assertSame(42, $this->app->getCount($this->notification));
+ $this->assertSame($count, $this->app->getCount($this->notification));
}
public function testMarkProcessed() {