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 * Constraint that asserts that a string is valid JSON.
14 * @since Class available since Release 3.7.20
16 class PHPUnit_Framework_Constraint_IsJson extends PHPUnit_Framework_Constraint
19 * Evaluates the constraint for parameter $other. Returns true if the
20 * constraint is met, false otherwise.
22 * @param mixed $other Value or object to evaluate.
26 protected function matches($other)
29 if (json_last_error()) {
37 * Returns the description of the failure
39 * The beginning of failure messages is "Failed asserting that" in most
40 * cases. This method should return the second part of that sentence.
42 * @param mixed $other Evaluated value or object.
46 protected function failureDescription($other)
49 $error = PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(
54 '%s is valid JSON (%s)',
55 $this->exporter->shortenedExport($other),
61 * Returns a string representation of the constraint.
65 public function toString()
67 return 'is valid JSON';