Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix unit test
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jul 18, 2019
commit 947847c14a706bc15552ff11ae41afa00e7b6da5
6 changes: 2 additions & 4 deletions tests/Unit/AppInfo/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ protected function tearDown() {
public function testRegisterApp() {
$this->manager->expects($this->once())
->method('registerApp')
->willReturnCallback(function($closure) {
$this->assertInstanceOf(\Closure::class, $closure);
$navigation = $closure();
$this->assertInstanceOf(App::class, $navigation);
->willReturnCallback(function($service) {
$this->assertSame(App::class, $service);
});

include(__DIR__ . '/../../../appinfo/app.php');
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public function testGetCapabilities() {
'delete-all',
'icons',
'rich-strings',
'action-web',
],
'push' => [
'devices',
'object-data',
'delete',
],
'admin-notifications' => [
'ocs',
Expand Down
45 changes: 30 additions & 15 deletions tests/Unit/Controller/EndpointControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCA\Notifications\Controller\EndpointController;
use OCA\Notifications\Exceptions\NotificationNotFoundException;
use OCA\Notifications\Handler;
use OCA\Notifications\Push;
use OCA\Notifications\Tests\Unit\TestCase;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand Down Expand Up @@ -59,27 +60,19 @@ class EndpointControllerTest extends TestCase {

/** @var IUser|MockObject */
protected $user;
/** @var Push|MockObject */
protected $push;

protected function setUp() {
parent::setUp();

/** @var IRequest|MockObject */
$this->request = $this->createMock(IRequest::class);

/** @var Handler|MockObject */
$this->handler = $this->createMock(Handler::class);

/** @var IManager|MockObject */
$this->manager = $this->createMock(IManager::class);

/** @var IConfig|MockObject */
$this->config = $this->createMock(IConfig::class);

/** @var IUserSession|MockObject */
$this->session = $this->createMock(IUserSession::class);

/** @var IUser|MockObject */
$this->user = $this->createMock(IUser::class);
$this->push = $this->createMock(Push::class);

$this->session->expects($this->any())
->method('getUser')
Expand All @@ -98,7 +91,8 @@ protected function getController(array $methods = [], $username = 'username') {
$this->handler,
$this->manager,
$this->config,
$this->session
$this->session,
$this->push
);
}

Expand All @@ -109,7 +103,8 @@ protected function getController(array $methods = [], $username = 'username') {
$this->handler,
$this->manager,
$this->config,
$this->session
$this->session,
$this->push,
])
->setMethods($methods)
->getMock();
Expand Down Expand Up @@ -163,7 +158,7 @@ public function testListNotifications($apiVersion, array $notifications, $expect
->getMock();
$filter->expects($this->once())
->method('setUser')
->willReturn('username');
->willReturn($filter);

$this->manager->expects($this->once())
->method('hasNotifiers')
Expand All @@ -175,6 +170,11 @@ public function testListNotifications($apiVersion, array $notifications, $expect
->method('prepare')
->willReturnArgument(0);

$this->config->expects($this->once())
->method('getUserValue')
->with('username', 'core', 'lang', null)
->willReturn('en');

$this->handler->expects($this->once())
->method('get')
->with($filter)
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testListNotificationsThrows($apiVersion, array $notifications, $
->getMock();
$filter->expects($this->once())
->method('setUser')
->willReturn('username');
->willReturn($filter);

$this->manager->expects($this->once())
->method('hasNotifiers')
Expand All @@ -240,6 +240,11 @@ public function testListNotificationsThrows($apiVersion, array $notifications, $
->method('prepare')
->willReturnArgument(0);

$this->config->expects($this->once())
->method('getUserValue')
->with('username', 'core', 'lang', null)
->willReturn('en');

$this->handler->expects($this->once())
->method('get')
->with($filter)
Expand Down Expand Up @@ -316,6 +321,11 @@ public function testGetNotification($apiVersion, $id, $username) {
->with($id, $notification)
->willReturn(['$notification']);

$this->config->expects($this->once())
->method('getUserValue')
->with($username, 'core', 'lang', null)
->willReturn('en');

$response = $controller->getNotification($apiVersion, $id);
$this->assertInstanceOf(DataResponse::class, $response);
$this->assertSame(Http::STATUS_OK, $response->getStatus());
Expand Down Expand Up @@ -361,6 +371,11 @@ public function testGetNotificationNoId($apiVersion, $hasNotifiers, $id, $called
->method('getById')
->willReturn($notification);

$this->config->expects($this->once())
->method('getUserValue')
->with('username', 'core', 'lang', null)
->willReturn('en');

$this->manager->expects($this->once())
->method('prepare')
->willThrowException(new \InvalidArgumentException());
Expand Down