Nextcloud-App/tests/Unit/Service/NoteServiceTest.php

79 lines
2.1 KiB
PHP

<?php
namespace Unit\Service;
use OCA\UPschooling\Db\MatrixTicket;
use OCA\UPschooling\Db\TicketMapper;
use OCA\UPschooling\Db\UserMapper;
use OCA\UPschooling\Service\MatrixService;
use OCA\UPschooling\Service\TicketService;
use OCP\AppFramework\Db\DoesNotExistException;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
class NoteServiceTest extends TestCase {
/** @var TicketService */
private $service;
/** @var MatrixService */
private $matrixService;
/** @var TicketMapper */
private $ticketMapper;
/** @var UserMapper */
private $userMapper;
/** @var string */
private $userId = 'john';
public function setUp(): void {
$this->ticketMapper = $this->getMockBuilder(TicketMapper::class)
->disableOriginalConstructor()
->getMock();
$this->userMapper = $this->getMockBuilder(UserMapper::class)
->disableOriginalConstructor()
->getMock();
$this->matrixService = new MatrixService(new NullLogger());
$this->service = new TicketService($this->matrixService, $this->ticketMapper, $this->userMapper);
}
public function testUpdate() {
// the existing note
$note = MatrixTicket::fromRow([
'id' => 3,
'title' => 'yo',
'content' => 'nope'
]);
$this->ticketMapper->expects($this->once())
->method('find')
->with($this->equalTo(3))
->will($this->returnValue($note));
// the note when updated
$updatedNote = MatrixTicket::fromRow(['id' => 3]);
$updatedNote->setTitle('title');
$updatedNote->setContent('content');
$this->ticketMapper->expects($this->once())
->method('update')
->with($this->equalTo($updatedNote))
->will($this->returnValue($updatedNote));
$result = $this->service->update(3, 'title', 'content', $this->userId);
$this->assertEquals($updatedNote, $result);
}
public function testUpdateNotFound() {
// $this->expectException(NoteNotFound::class);
// test the correct status code if no note is found
$this->ticketMapper->expects($this->once())
->method('find')
->with($this->equalTo(3))
->will($this->throwException(new DoesNotExistException('')));
$this->service->update(3, 'title', 'content', $this->userId);
}
}