Exemple #1
0
 public function testResponseShouldCastErrorToJsonIfIsError()
 {
     $error = new Zend_Json_Server_Error();
     $error->setCode(Zend_Json_Server_Error::ERROR_INTERNAL)->setMessage('error occurred');
     $this->response->setId('foo')->setResult(true)->setError($error);
     $json = $this->response->toJson();
     $test = Zend_Json::decode($json);
     $this->assertTrue(is_array($test));
     $this->assertTrue(array_key_exists('result', $test));
     $this->assertTrue(array_key_exists('id', $test));
     $this->assertFalse(array_key_exists('jsonrpc', $test));
     $this->assertEquals($this->response->getId(), $test['id']);
     $this->assertEquals($error->getCode(), $test['error']['code']);
     $this->assertEquals($error->getMessage(), $test['error']['message']);
 }
 /**
  * Helper method to authenticate this API call
  *
  * @param string $message
  * @param int $code
  *
  * @return null
  */
 private function error($message, $code = 500)
 {
     // Create a new error-object
     $error = new Zend_Json_Server_Error();
     $error->setCode($code);
     $error->setMessage($message);
     /** @var Zend_Json_Server_Response $response */
     $response = $this->server->getResponse();
     // Add the error to the current response
     $response->setError($error);
     // Set the response
     $this->server->setResponse($response);
     $this->server->handle();
     // Set the HTTP-header
     header('HTTP/1.1 ' . $code . ' ' . $message, true);
     header('Status: ' . $code . ' ' . $message, true);
     // Close the application
     $this->close();
 }
 private function error($message, $code = '500')
 {
     // Create a new error-object
     $error = new Zend_Json_Server_Error();
     $error->setCode($code);
     $error->setMessage($message);
     // Add the error to the current response
     $response = $this->server->getResponse();
     $response->setError($error);
     // Set the response
     $this->server->setResponse($response);
     $this->server->handle();
     // Set the HTTP-header
     @header('HTTP/1.1 ' . $code . ' ' . $message);
     @header('Status: ' . $code . ' ' . $message);
     // Close the application
     $application = JFactory::getApplication();
     $application->close();
 }