85290262946dde6f5abc23a2c94ac54922720f24
[yaffs-website] / vendor / phpunit / phpunit / tests / Framework / Constraint / JsonMatches / ErrorMessageProviderTest.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_JsonMatches_ErrorMessageProviderTest extends PHPUnit_Framework_TestCase
15 {
16     /**
17      * @dataProvider translateTypeToPrefixDataprovider
18      * @covers PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::translateTypeToPrefix
19      */
20     public function testTranslateTypeToPrefix($expected, $type)
21     {
22         $this->assertEquals(
23             $expected,
24             PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::translateTypeToPrefix($type)
25         );
26     }
27
28     /**
29      * @dataProvider determineJsonErrorDataprovider
30      * @covers PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError
31      */
32     public function testDetermineJsonError($expected, $error, $prefix)
33     {
34         $this->assertEquals(
35             $expected,
36             PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(
37                 $error,
38                 $prefix
39             )
40         );
41     }
42
43     public static function determineJsonErrorDataprovider()
44     {
45         return array(
46             'JSON_ERROR_NONE'  => array(
47                 null, 'json_error_none', ''
48             ),
49             'JSON_ERROR_DEPTH' => array(
50                 'Maximum stack depth exceeded', JSON_ERROR_DEPTH, ''
51             ),
52             'prefixed JSON_ERROR_DEPTH' => array(
53                 'TUX: Maximum stack depth exceeded', JSON_ERROR_DEPTH, 'TUX: '
54             ),
55             'JSON_ERROR_STATE_MISMatch' => array(
56                 'Underflow or the modes mismatch', JSON_ERROR_STATE_MISMATCH, ''
57             ),
58             'JSON_ERROR_CTRL_CHAR' => array(
59                 'Unexpected control character found', JSON_ERROR_CTRL_CHAR, ''
60             ),
61             'JSON_ERROR_SYNTAX' => array(
62                 'Syntax error, malformed JSON', JSON_ERROR_SYNTAX, ''
63             ),
64             'JSON_ERROR_UTF8`' => array(
65                 'Malformed UTF-8 characters, possibly incorrectly encoded',
66                 JSON_ERROR_UTF8,
67                 ''
68             ),
69             'Invalid error indicator' => array(
70                 'Unknown error', 55, ''
71             ),
72         );
73     }
74
75     public static function translateTypeToPrefixDataprovider()
76     {
77         return array(
78             'expected' => array('Expected value JSON decode error - ', 'expected'),
79             'actual'   => array('Actual value JSON decode error - ', 'actual'),
80             'default'  => array('', ''),
81         );
82     }
83 }