/** @test **/ public function it_marks_errors() { $e = new \PHRETS\Models\RETSError(); $e->setCode(1234); $e->setMessage('Test Error Message'); $o = new Object(); $this->assertFalse($o->isError()); $o->setError($e); $this->assertTrue($o->isError()); $this->assertSame(1234, $o->getError()->getCode()); $this->assertSame('Test Error Message', $o->getError()->getMessage()); }
public function parse(ResponseInterface $response) { $headers = $response->getHeaders(); $obj = new Object(); $obj->setContent($response->getBody() ? $response->getBody()->__toString() : null); $obj->setContentDescription(\array_get($headers, 'Content-Description', [null])[0]); $obj->setContentSubDescription(\array_get($headers, 'Content-Sub-Description', [null])[0]); $obj->setContentId(\array_get($headers, 'Content-ID', [null])[0]); $obj->setObjectId(\array_get($headers, 'Object-ID', [null])[0]); $obj->setContentType(\array_get($headers, 'Content-Type', [null])[0]); $obj->setLocation(\array_get($headers, 'Location', [null])[0]); $obj->setMimeVersion(\array_get($headers, 'MIME-Version', [null])[0]); $obj->setPreferred(\array_get($headers, 'Preferred', [null])[0]); if ($this->isError($response)) { $xml = $response->xml(); $error = new RETSError(); $error->setCode((string) \array_get($xml, 'ReplyCode')); $error->setMessage((string) \array_get($xml, 'ReplyText')); $obj->setError($error); } return $obj; }