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 * Asserts whether or not two JSON objects are equal.
14 * @since Class available since Release 3.7.0
16 class PHPUnit_Framework_Constraint_JsonMatches extends PHPUnit_Framework_Constraint
24 * Creates a new constraint.
26 * @param string $value
28 public function __construct($value)
30 parent::__construct();
31 $this->value = $value;
35 * Evaluates the constraint for parameter $other. Returns true if the
36 * constraint is met, false otherwise.
38 * This method can be overridden to implement the evaluation algorithm.
40 * @param mixed $other Value or object to evaluate.
44 protected function matches($other)
46 $decodedOther = json_decode($other);
47 if (json_last_error()) {
51 $decodedValue = json_decode($this->value);
52 if (json_last_error()) {
56 return $decodedOther == $decodedValue;
60 * Returns a string representation of the object.
64 public function toString()
67 'matches JSON string "%s"',