3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Provides human readable messages for each JSON error.
14 * @since Class available since Release 3.7.0
16 class PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider
19 * Translates JSON error to a human readable string.
21 * @param string $error
22 * @param string $prefix
26 public static function determineJsonError($error, $prefix = '')
31 case JSON_ERROR_DEPTH:
32 return $prefix . 'Maximum stack depth exceeded';
33 case JSON_ERROR_STATE_MISMATCH:
34 return $prefix . 'Underflow or the modes mismatch';
35 case JSON_ERROR_CTRL_CHAR:
36 return $prefix . 'Unexpected control character found';
37 case JSON_ERROR_SYNTAX:
38 return $prefix . 'Syntax error, malformed JSON';
40 return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded';
42 return $prefix . 'Unknown error';
47 * Translates a given type to a human readable message prefix.
53 public static function translateTypeToPrefix($type)
55 switch (strtolower($type)) {
57 $prefix = 'Expected value JSON decode error - ';
60 $prefix = 'Actual value JSON decode error - ';