/** * Decodes the JSON string and performs a lint check if decoding fails. * * @param string $json The JSON data. * @param boolean $assoc Convert objects to associative arrays? * @param integer $depth The maximum recursion depth. * @param integer $options The bitmask JSON decode options (PHP 5.4+). * * @return mixed The decoded data. * * @throws Exception\Exception * @throws JsonException If the JSON string could not be decoded. */ public function decode($json, $assoc = false, $depth = 512, $options = 0) { if (JSON_DECODE_FOURTH_ARG) { $data = json_decode($json, $assoc, $depth, $options); } else { $data = json_decode($json, $assoc, $depth); } if (JSON_ERROR_NONE !== ($error = json_last_error())) { if (JSON_ERROR_UTF8 === $error) { throw JsonException::createUsingCode($error); } $this->lint($json); // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd return $data; }
public function testCreateUsingCode() { $exception = JsonException::createUsingCode(JSON_ERROR_NONE); $this->assertEquals('No error has occurred.', $exception->getMessage()); }