From e1a6bd5ff1bf2b73cd7a6b2fd029641d4a505147 Mon Sep 17 00:00:00 2001 From: Alexander Kurilo Date: Tue, 7 Aug 2018 23:20:08 +0300 Subject: [PATCH] Make JSON formatter test clearer --- .../Composer/Test/Json/JsonFormatterTest.php | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/tests/Composer/Test/Json/JsonFormatterTest.php b/tests/Composer/Test/Json/JsonFormatterTest.php index fc6cf53ed..417f267e3 100644 --- a/tests/Composer/Test/Json/JsonFormatterTest.php +++ b/tests/Composer/Test/Json/JsonFormatterTest.php @@ -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); - } }