/** * @param $id * @param ContactM $model * @return \Freshdesk\Model\Contact * @throws \RuntimeException */ public function getContactById($id, ContactM $model = null) { if ($id instanceof ContactM) { $model = $id; $id = $model->getId(); } $response = json_decode($this->restCall('/contacts/' . $id . '.json', Rest::METHOD_GET)); if (property_exists($response, 'errors')) { throw new \RuntimeException(sprintf('Error: %s', $response->errors->error)); } if ($model === null) { $model = new ContactM(); } return $model->setAll($response); }
public function testGetContact() { $this->restMock->method('restCall')->willReturn(json_encode($this->data)); $contact = new ContactM($this->data); $dates = array('getCreatedAt' => $contact->getCreatedAt(), 'getUpdatedAt' => $contact->getUpdatedAt()); /** @var ContactM $model */ $model = $this->restMock->getContactById($contact->getId()); $this->assertInstanceOf(get_class($contact), $model); $this->assertEquals($contact, $model); foreach ($dates as $getter => $value) { if ($value) { $this->assertInstanceOf(get_class($value), $model->{$getter}()); $this->assertEquals($value, $model->{$getter}()); $this->assertEquals($value->format('Y-m-d H:i:s'), $model->{$getter}()->format('Y-m-d H:i:s')); } else { $this->assertEmpty($model->{$getter}()); } } }