/** * test the __call method * * @return void */ public function testBaseMagicCallMethod() { $title = "New Title"; $detail = "Custom detail message"; $status = 406; $code = "Some Status Code"; $id = "13242134-456657-asdfasdf"; $href = 'https://www.asdfasdfasdf.com/'; $links = array('link' => 'link'); $paths = array('something' => 'something'); $testBaseSerializerException = new BaseSerializerException($title, $detail, $status, $code, $id, $href, $links, $paths); $this->assertEquals($title, $testBaseSerializerException->title(), "BaseSerializerException::title() should match our passed in `title`: {$title}"); $this->assertEquals($detail, $testBaseSerializerException->detail(), "BaseSerializerException::detail() should match our passed in `detail`: {$detail}"); $this->setExpectedException('BadMethodCallException', "No method or property ::getSomething for this class"); $testBaseSerializerException->getSomething(); }
/** * render the BaseSerializerException for a JSON API request * * @param BaseSerializerException $error an instance of BaseSerializerException * @return void */ protected function renderSerializerAsJsonApi(BaseSerializerException $error) { // Add a response type for JSON API $this->controller->response->type(array('jsonapi' => 'application/vnd.api+json')); // Set the controller to response as JSON API $this->controller->response->type('jsonapi'); // Set the correct Status Code $this->controller->response->statusCode($error->status()); // set the errors object to match JsonApi's standard $errors = array('errors' => array(array('id' => h($error->id()), 'href' => h($error->href()), 'status' => h($error->status()), 'code' => h($error->code()), 'title' => h($error->title()), 'detail' => h($error->detail()), 'links' => $error->links(), 'paths' => $error->paths()))); // json encode the errors $jsonEncodedErrors = json_encode($errors); // set the body to the json encoded errors $this->controller->response->body($jsonEncodedErrors); return $this->controller->response->send(); }