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 * @since File available since Release 3.7.0
14 class Framework_Constraint_JsonMatchesTest extends PHPUnit_Framework_TestCase
17 * @dataProvider evaluateDataprovider
18 * @covers PHPUnit_Framework_Constraint_JsonMatches::evaluate
19 * @covers PHPUnit_Framework_Constraint_JsonMatches::matches
20 * @covers PHPUnit_Framework_Constraint_JsonMatches::__construct
22 public function testEvaluate($expected, $jsonOther, $jsonValue)
24 $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue);
25 $this->assertEquals($expected, $constraint->evaluate($jsonOther, '', true));
29 * @covers PHPUnit_Framework_Constraint_JsonMatches::toString
31 public function testToString()
33 $jsonValue = json_encode(array('Mascott' => 'Tux'));
34 $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue);
36 $this->assertEquals('matches JSON string "' . $jsonValue . '"', $constraint->toString());
39 public static function evaluateDataprovider()
42 'valid JSON' => array(true, json_encode(array('Mascott' => 'Tux')), json_encode(array('Mascott' => 'Tux'))),
43 'error syntax' => array(false, '{"Mascott"::}', json_encode(array('Mascott' => 'Tux'))),
44 'error UTF-8' => array(false, json_encode('\xB1\x31'), json_encode(array('Mascott' => 'Tux'))),
45 'invalid JSON in class instantiation' => array(false, json_encode(array('Mascott' => 'Tux')), '{"Mascott"::}'),