/** * Raise an xmlrpc server fault * * @param string|\Exception $fault * @param int $code * @return Server\Fault */ public function fault($fault = null, $code = 404) { if (!$fault instanceof \Exception) { $fault = (string) $fault; if (empty($fault)) { $fault = 'Unknown Error'; } $fault = new Server\Exception\RuntimeException($fault, $code); } return Server\Fault::getInstance($fault); }
/** * __toString() test */ public function test__toString() { $dom = new \DOMDocument('1.0', 'UTF-8'); $r = $dom->appendChild($dom->createElement('methodResponse')); $f = $r->appendChild($dom->createElement('fault')); $v = $f->appendChild($dom->createElement('value')); $s = $v->appendChild($dom->createElement('struct')); $m1 = $s->appendChild($dom->createElement('member')); $m1->appendChild($dom->createElement('name', 'faultCode')); $cv = $m1->appendChild($dom->createElement('value')); $cv->appendChild($dom->createElement('int', 411)); $m2 = $s->appendChild($dom->createElement('member')); $m2->appendChild($dom->createElement('name', 'faultString')); $sv = $m2->appendChild($dom->createElement('value')); $sv->appendChild($dom->createElement('string', 'Testing fault')); $xml = $dom->saveXML(); $e = new Server\Exception\RuntimeException('Testing fault', 411); $fault = Server\Fault::getInstance($e); $this->assertEquals(trim($xml), trim($fault->__toString())); }