public function create($title, $content, $userId) { $note = new Note(); $note->setTitle($title); $note->setContent($content); $note->setUserId($userId); return $this->mapper->insert($note); }
public function testUpdate() { // the existing note $note = Note::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 = Note::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 testUpdate() { // create a new note that should be updated $note = new Note(); $note->setTitle('old_title'); $note->setContent('old_content'); $note->setUserId($this->userId); $id = $this->mapper->insert($note)->getId(); // fromRow does not set the fields as updated $updatedNote = Note::fromRow(['id' => $id, 'user_id' => $this->userId]); $updatedNote->setContent('content'); $updatedNote->setTitle('title'); $result = $this->controller->update($id, 'title', 'content'); $this->assertEquals($updatedNote, $result->getData()); // clean up $this->mapper->delete($result->getData()); }