Yaffs site version 1.1
[yaffs-website] / vendor / phpunit / phpunit / tests / Framework / Constraint / JsonMatchesTest.php
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
11 /**
12  * @since      File available since Release 3.7.0
13  */
14 class Framework_Constraint_JsonMatchesTest extends PHPUnit_Framework_TestCase
15 {
16     /**
17      * @dataProvider evaluateDataprovider
18      * @covers PHPUnit_Framework_Constraint_JsonMatches::evaluate
19      * @covers PHPUnit_Framework_Constraint_JsonMatches::matches
20      * @covers PHPUnit_Framework_Constraint_JsonMatches::__construct
21      */
22     public function testEvaluate($expected, $jsonOther, $jsonValue)
23     {
24         $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue);
25         $this->assertEquals($expected, $constraint->evaluate($jsonOther, '', true));
26     }
27
28     /**
29      * @covers PHPUnit_Framework_Constraint_JsonMatches::toString
30      */
31     public function testToString()
32     {
33         $jsonValue  = json_encode(array('Mascott' => 'Tux'));
34         $constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue);
35
36         $this->assertEquals('matches JSON string "' . $jsonValue . '"', $constraint->toString());
37     }
38
39     public static function evaluateDataprovider()
40     {
41         return array(
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"::}'),
46         );
47     }
48 }