Skip to content

Commit

Permalink
Inital cleanup of #424
Browse files Browse the repository at this point in the history
  • Loading branch information
edorian committed May 5, 2012
1 parent 4501b35 commit d9cbd24
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
46 changes: 23 additions & 23 deletions PHPUnit/Framework/Constraint/JsonMatches/ErrorMessageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ class PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider
public static function determineJsonError($error, $prefix = '')
{
switch (strtoupper($error)) {
case 'JSON_ERROR_NONE':
return;
case 'JSON_ERROR_DEPTH':
return $prefix . 'Maximum stack depth exceeded';
case 'JSON_ERROR_STATE_MISMATCH':
return $prefix . 'Underflow or the modes mismatch';
case 'JSON_ERROR_CTRL_CHAR':
return $prefix . 'Unexpected control character found';
case 'JSON_ERROR_SYNTAX':
return $prefix . 'Syntax error, malformed JSON';
case 'JSON_ERROR_UTF8':
return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded';
default:
return $prefix . 'Unknown error';
case 'JSON_ERROR_NONE':
return;
case 'JSON_ERROR_DEPTH':
return $prefix . 'Maximum stack depth exceeded';
case 'JSON_ERROR_STATE_MISMATCH':
return $prefix . 'Underflow or the modes mismatch';
case 'JSON_ERROR_CTRL_CHAR':
return $prefix . 'Unexpected control character found';
case 'JSON_ERROR_SYNTAX':
return $prefix . 'Syntax error, malformed JSON';
case 'JSON_ERROR_UTF8':
return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded';
default:
return $prefix . 'Unknown error';
}
}

Expand All @@ -92,15 +92,15 @@ public static function determineJsonError($error, $prefix = '')
public static function translateTypeToPrefix($type)
{
switch (strtolower($type)) {
case 'expected':
$prefix = 'Expected value JSON decode error - ';
break;
case 'actual':
$prefix = 'Actual value JSON decode error - ';
break;
default:
$prefix = '';
break;
case 'expected':
$prefix = 'Expected value JSON decode error - ';
break;
case 'actual':
$prefix = 'Actual value JSON decode error - ';
break;
default:
$prefix = '';
break;
}
return $prefix;
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Framework/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4095,7 +4095,7 @@ public function testAssertJsonStringEqualsJsonFileExpectingInvalidArgumentExcept
{
$file = __DIR__ . '/../_files/JsonData/simpleObject.js';
try {
$this->assertJsonStringEqualsJsonFile($file, null);
$this->assertJsonStringEqualsJsonFile($file, NULL);
} catch (InvalidArgumentException $e) {
return;
}
Expand All @@ -4120,7 +4120,7 @@ public function testAssertJsonStringNotEqualsJsonFileExpectingInvalidArgumentExc
{
$file = __DIR__ . '/../_files/JsonData/simpleObject.js';
try {
$this->assertJsonStringNotEqualsJsonFile($file, null);
$this->assertJsonStringNotEqualsJsonFile($file, NULL);
} catch (InvalidArgumentException $e) {
return;
}
Expand Down Expand Up @@ -4151,8 +4151,8 @@ public function testAssertJsonFileEqualsJsonFile()
public static function validInvalidJsonDataprovider()
{
return array(
'error syntax in expected JSON' => array('{"Mascott"::}', '{"Mascott" : "Tux"}'),
'error UTF-8 in actual JSON' => array('{"Mascott" : "Tux"}', '{"Mascott" : :}'),
'error syntax in expected JSON' => array('{"Mascott"::}', '{"Mascott" : "Tux"}'),
'error UTF-8 in actual JSON' => array('{"Mascott" : "Tux"}', '{"Mascott" : :}'),
);
}

Expand Down
32 changes: 19 additions & 13 deletions Tests/Framework/Constraint/JsonMatches/ErrorMessageProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @package PHPUnit
* @author Bastian Feder <php@bastian-feder.de>
* @copyright 2002-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://www.phpunit.de/
* @since File available since Release 3.7.0
Expand All @@ -45,7 +45,7 @@
/**
* @package PHPUnit
* @author Bastian Feder <php@bastian-feder.de>
* @copyright 2011 Bastian Feder <php@bastian-feder.de>
* @copyright 2011-2012 Bastian Feder <php@bastian-feder.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://www.phpunit.de/
* @since File available since Release 3.7.0
Expand Down Expand Up @@ -79,29 +79,35 @@ public function testDetermineJsonError($expected, $error, $prefix)
);
}

/*************************************************************************/
/* Dataprovider & Callbacks */
/*************************************************************************/

public static function determineJsonErrorDataprovider()
{
return array(
'JSON_ERROR_NONE' => array(null, 'json_error_none', ''),
'JSON_ERROR_DEPTH' => array('Maximum stack depth exceeded', 'json_error_depth', ''),
'JSON_ERROR_NONE' => array(
NULL, 'json_error_none', ''
),
'JSON_ERROR_DEPTH' => array(
'Maximum stack depth exceeded', 'json_error_depth', ''
),
'prefixed JSON_ERROR_DEPTH' => array(
'TUX: Maximum stack depth exceeded', 'json_error_depth', 'TUX: '),
'TUX: Maximum stack depth exceeded', 'json_error_depth', 'TUX: '
),
'JSON_ERROR_STATE_MISMatch' => array(
'Underflow or the modes mismatch', 'json_error_state_mismatch', ''),
'Underflow or the modes mismatch', 'json_error_state_mismatch', ''
),
'JSON_ERROR_CTRL_CHAR' => array(
'Unexpected control character found', 'json_error_ctrl_char', ''),
'Unexpected control character found', 'json_error_ctrl_char', ''
),
'JSON_ERROR_SYNTAX' => array(
'Syntax error, malformed JSON', 'json_error_syntax', ''),
'Syntax error, malformed JSON', 'json_error_syntax', ''
),
'JSON_ERROR_UTF8`' => array(
'Malformed UTF-8 characters, possibly incorrectly encoded',
'json_error_utf8',
''
),
'Invalid error indicator' => array('Unknown error', 'invalid_error_indicator', ''),
'Invalid error indicator' => array(
'Unknown error', 'invalid_error_indicator', ''
),
);
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/Framework/Constraint/JsonMatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Framework_Constraint_JsonMatchesTest extends PHPUnit_Framework_TestCase
public function testEvaluate($expected, $jsonOther, $jsonValue)
{
$constraint = new PHPUnit_Framework_Constraint_JsonMatches($jsonValue);
$this->assertEquals($expected, $constraint->evaluate($jsonOther, '', true));
$this->assertEquals($expected, $constraint->evaluate($jsonOther, '', TRUE));
}

/**
Expand All @@ -81,10 +81,10 @@ public function testToString()
public static function evaluateDataprovider()
{
return array(
'valid JSON' => array(true, json_encode(array('Mascott' => 'Tux')), json_encode(array('Mascott' => 'Tux'))),
'error syntax' => array(false, '{"Mascott"::}', json_encode(array('Mascott' => 'Tux'))),
'error UTF-8' => array(false, json_encode('\xB1\x31'), json_encode(array('Mascott' => 'Tux'))),
'invalid JSON in class instantiation' => array(false, json_encode(array('Mascott' => 'Tux')), '{"Mascott"::}'),
'valid JSON' => array(TRUE, json_encode(array('Mascott' => 'Tux')), json_encode(array('Mascott' => 'Tux'))),
'error syntax' => array(FALSE, '{"Mascott"::}', json_encode(array('Mascott' => 'Tux'))),
'error UTF-8' => array(FALSE, json_encode('\xB1\x31'), json_encode(array('Mascott' => 'Tux'))),
'invalid JSON in class instantiation' => array(FALSE, json_encode(array('Mascott' => 'Tux')), '{"Mascott"::}'),
);
}
}

0 comments on commit d9cbd24

Please sign in to comment.