public function testSetAll() { $getters = array(); foreach ($this->data as $data) { $note = new Note($data); $setAll = new Note(); $setAll->setAll($data); $this->assertEquals($note->toJsonData(), $setAll->toJsonData(), 'String compare fails'); $this->assertEquals($note, $setAll, 'Object compare fails'); $data = isset($data[Note::RESPONSE_KEY]) ? $data[Note::RESPONSE_KEY] : $data; foreach ($data as $k => $v) { if (!isset($getters[$k])) { $getter = 'get' . implode('', array_map('ucfirst', explode('_', $k))); $getters[$k] = $getter; } $getter = $getters[$k]; if (!method_exists($note, $getter)) { continue; } if ($note->{$getter}(false) instanceof DateTime) { $this->assertInstanceOf('DateTime', $setAll->{$getter}(false)); //transform ISO 8601 format to Y-m-d H:i:s $ymdhis = substr(str_replace('T', ' ', $v), 0, -6); $this->assertEquals($v, $note->{$getter}(false)->format('c')); $this->assertEquals($v, $setAll->{$getter}(false)->format('c')); $this->assertEquals($ymdhis, $setAll->{$getter}(), $ymdhis); $this->assertEquals($ymdhis, $note->{$getter}(), $ymdhis); } else { $this->assertEquals($v, $note->{$getter}()); $this->assertEquals($v, $setAll->{$getter}()); } $this->assertEquals($note->{$getter}(), $setAll->{$getter}()); } } }
/** * Add note to ticket, ticket model is expected to be set on Note model * @param Note $note * @return Note * @throws \RuntimeException */ public function addNoteToTicket(Note $note) { $url = sprintf('/helpdesk/tickets/%d/conversations/note.json', $note->getTicket()->getDisplayId()); $response = json_decode($this->restCall($url, self::METHOD_POST, $note->toJsonData())); if (!property_exists($response, 'note')) { throw new RuntimeException(sprintf('Failed to add note: %s', json_encode($response))); } //todo set properties on Note instance return $note->setAll($response); }