There is ajax method, which is at the end of tojson . In the method, data is generated, then they are grouped into an array of the form $response = [ 'code' => $responseCode, 'message' => $message ];
public function recoverPasswordAjax() { $message = _('Произошла ошибка, попробуйте еще раз.'); $responseCode = 0; $response = [ 'code' => $responseCode, 'message' => $message ]; $this->toJSON($response, true); } final public function toJSON($var, $send = false, $mask = 0) { $result = toJSON($var, $mask); if ($send) { header('Content-Type: application/json; charset=utf-8'); print($result); exit(); } return $result; } function toJSON($var, $mask = 0) { $result = json_encode($var, $mask); return $result ? $result : ''; } How to test such a method using unit tests, or is it only functional tests possible?