mapper = $this->getMockBuilder(TicketMapper::class) ->disableOriginalConstructor() ->getMock(); $this->service = new TicketService($this->mapper); } public function testUpdate() { // the existing note $note = MatrixTicket::fromRow([ 'id' => 3, 'title' => 'yo', 'content' => 'nope' ]); $this->mapper->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->mapper->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->mapper->expects($this->once()) ->method('find') ->with($this->equalTo(3)) ->will($this->throwException(new DoesNotExistException(''))); $this->service->update(3, 'title', 'content', $this->userId); } }