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.
15
* @subpackage Framework_Constraint
16
* @author Sebastian Bergmann <sebastian@phpunit.de>
17
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
18
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
19
* @link http://www.phpunit.de/
20
* @since Class available since Release 3.7.20
22
class PHPUnit_Framework_Constraint_IsJson extends PHPUnit_Framework_Constraint
25
* Evaluates the constraint for parameter $other. Returns true if the
26
* constraint is met, false otherwise.
28
* @param mixed $other Value or object to evaluate.
31
protected function matches($other)
34
if (json_last_error()) {
42
* Returns the description of the failure
44
* The beginning of failure messages is "Failed asserting that" in most
45
* cases. This method should return the second part of that sentence.
47
* @param mixed $other Evaluated value or object.
50
protected function failureDescription($other)
53
$error = PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(
58
'%s is valid JSON (%s)',
59
$this->exporter->shortenedExport($other),
65
* Returns a string representation of the constraint.
69
public function toString()
71
return 'is valid JSON';