فهرست منبع

Make JSON formatter test clearer

Alexander Kurilo 6 سال پیش
والد
کامیت
e1a6bd5ff1
1فایلهای تغییر یافته به همراه6 افزوده شده و 22 حذف شده
  1. 6 22
      tests/Composer/Test/Json/JsonFormatterTest.php

+ 6 - 22
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);
-    }
 }