1
我試圖轉換爲unicode並創建一些單元測試以確保unicode正常工作。支持unicode的單元測試
這裏是我當前的代碼,從而未能在mb_detect_encoding()線,並且我也不能確定它是否是Unicode支持有效的測試:
function testMultiLingualEncodings(){
// Create this string via a heredoc.
$original = '
A good day, World!
Schönen Tag, Welt!
Une bonne journée, tout le monde!
يوم جيد، العالم
좋은 일, 세계!
Một ngày tốt lành, thế giới!
こんにちは、世界!
'; // Contains international characters from utf-8
$this->assertTrue(mb_detect_encoding($original, 'UTF-8', true) === true); // Fails regardless of whether strict is true or not.
$returned = query_item("select :multi limit 10", array(':multi'=>$original)); // Select this exact string, parameterized, from the database
//debug($returned, string_diff($returned, $original));
$this->assertTrue((bool)$original); // test original isn't null.
$this->assertTrue((bool)$returned); // Test returned string isn't null.
$this->assertTrue($original === $returned); // Test original exactly matches returned string
}
所以mb_detect_encoding()說,上面的初始字符串不是UTF-8。我也試圖將該字符串傳入數據庫並將其取出,然後與原始字符串進行比較。但是,我不確定這是否是對數據庫連接編碼的有效測試。
所以一般來說,我如何創建一個utf-8支持的單元測試,並且上面的方法是可以修改來解決這個目標的方法?
我可以確保該文件是UTF-8編碼,雖然。 (這是)所以在那一點上,我知道原始文件是utf-8。我還在字符串中僅包含了utf-8中的字符。因此,您的「ABCDE」的例子似乎並不適用,因爲那裏是肯定的測試字符串-not- ASCII字符。 無論如何,我只是創建了一個文件,我並不是說這是測試的Unicode支持的最佳途徑,但如果不工作,什麼-will-。 – Kzqai
爲了使您的測試工作要做'$這個 - > assertTrue(mb_detect_encoding($原來, 'UTF-8')=== 'UTF-8')' –
@LukaszKujawa你能移動你的評論是你的答案編輯?蜱將使意義然後:-) –