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