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

75 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2021-10-10 17:51:12 +00:00
namespace OCA\UPschooling\Tests\Unit\Service;
use OCA\UPschooling\Db\MatrixTicket;
use OCA\UPschooling\Db\TicketMapper;
2021-09-19 14:55:30 +00:00
use OCA\UPschooling\Db\UserMapper;
2021-09-18 19:15:03 +00:00
use OCA\UPschooling\Service\MatrixService;
2021-08-22 15:03:19 +00:00
use OCA\UPschooling\Service\TicketService;
use OCP\AppFramework\Db\DoesNotExistException;
use PHPUnit\Framework\TestCase;
2021-09-18 19:15:03 +00:00
use Psr\Log\NullLogger;
2021-10-10 17:51:12 +00:00
class TicketServiceTest extends TestCase {
2021-09-18 19:15:03 +00:00
/** @var TicketService */
private $service;
2021-09-18 19:15:03 +00:00
/** @var MatrixService */
private $matrixService;
/** @var TicketMapper */
2021-09-19 14:55:30 +00:00
private $ticketMapper;
/** @var UserMapper */
private $userMapper;
2021-09-18 19:15:03 +00:00
/** @var string */
private $userId = 'john';
public function setUp(): void {
2021-09-19 14:55:30 +00:00
$this->ticketMapper = $this->getMockBuilder(TicketMapper::class)
->disableOriginalConstructor()
->getMock();
$this->userMapper = $this->getMockBuilder(UserMapper::class)
->disableOriginalConstructor()
->getMock();
2021-09-18 19:15:03 +00:00
$this->matrixService = new MatrixService(new NullLogger());
2021-09-19 14:55:30 +00:00
$this->service = new TicketService($this->matrixService, $this->ticketMapper, $this->userMapper);
}
public function testUpdate() {
// the existing note
$note = MatrixTicket::fromRow([
'id' => 3,
]);
2021-09-19 14:55:30 +00:00
$this->ticketMapper->expects($this->once())
->method('find')
->with($this->equalTo(3))
->will($this->returnValue($note));
// the note when updated
$updatedNote = MatrixTicket::fromRow(['id' => 3]);
2021-09-19 14:55:30 +00:00
$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() {
2021-09-19 14:55:30 +00:00
// $this->expectException(NoteNotFound::class);
// test the correct status code if no note is found
2021-09-19 14:55:30 +00:00
$this->ticketMapper->expects($this->once())
->method('find')
->with($this->equalTo(3))
->will($this->throwException(new DoesNotExistException('')));
$this->service->update(3, 'title', 'content', $this->userId);
}
}