1<?php 2/* 3 * This file is part of PHPUnit. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11class Framework_Constraint_JsonMatchesTest extends PHPUnit_Framework_TestCase 12{ 13 /** 14 * @dataProvider evaluateDataprovider 15 */ 16 public function testEvaluate($expected, $jsonOther, $jsonValue) 17 { 18 $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue); 19 $this->assertEquals($expected, $constraint->evaluate($jsonOther, '', true)); 20 } 21 22 public function testToString() 23 { 24 $jsonValue = json_encode(['Mascott' => 'Tux']); 25 $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue); 26 27 $this->assertEquals('matches JSON string "' . $jsonValue . '"', $constraint->toString()); 28 } 29 30 public static function evaluateDataprovider() 31 { 32 return [ 33 'valid JSON' => [true, json_encode(['Mascott' => 'Tux']), json_encode(['Mascott' => 'Tux'])], 34 'error syntax' => [false, '{"Mascott"::}', json_encode(['Mascott' => 'Tux'])], 35 'error UTF-8' => [false, json_encode('\xB1\x31'), json_encode(['Mascott' => 'Tux'])], 36 'invalid JSON in class instantiation' => [false, json_encode(['Mascott' => 'Tux']), '{"Mascott"::}'], 37 ]; 38 } 39} 40