Make JSON formatter test clearer

main
Alexander Kurilo 6 years ago committed by Jordi Boggiano
parent 5a22a4f1f3
commit e1a6bd5ff1

@ -18,19 +18,18 @@ use PHPUnit\Framework\TestCase;
class JsonFormatterTest extends TestCase
{
/**
* Test if \u0119 (196+153) will get correctly formatted
* See ticket #2613
* Test if \u0119 will get correctly formatted (unescaped)
* https://github.com/composer/composer/issues/2613
*/
public function testUnicodeWithPrependedSlash()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('Test requires the mbstring extension');
}
$data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"';
$encodedData = JsonFormatter::format($data, true, true);
$expected = '34+92+92+196+153+34';
$this->assertEquals($expected, $this->getCharacterCodes($encodedData));
$backslash = chr(92);
$data = '"' . $backslash . $backslash . $backslash . 'u0119"';
$expected = '"' . $backslash . $backslash . 'ę"';
$this->assertEquals($expected, JsonFormatter::format($data, true, true));
}
/**
@ -46,19 +45,4 @@ class JsonFormatterTest extends TestCase
$escaped = '"\ud83d\ude00"';
$this->assertEquals($escaped, JsonFormatter::format($escaped, true, true));
}
/**
* Convert string to character codes split by a plus sign
* @param string $string
* @return string
*/
protected function getCharacterCodes($string)
{
$codes = array();
for ($i = 0; $i < strlen($string); $i++) {
$codes[] = ord($string[$i]);
}
return implode('+', $codes);
}
}

Loading…
Cancel
Save