Php unicode支持的单元测试

Php unicode支持的单元测试,php,unicode,encoding,utf-8,Php,Unicode,Encoding,Utf 8,我正在尝试转换为unicode并创建一些单元测试,以确保unicode正常工作 这是我当前的代码,在mb_detect_encoding()行失败,我也不确定这是否是对unicode支持的有效测试: function testMultiLingualEncodings(){ // Create this string via a heredoc. $original = ' A good day, World! Schönen Tag, W

我正在尝试转换为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支持创建一个单元测试,以及上面的方法是否可以修改以解决该目标?

对不起,这没有意义。您的测试文件以一种格式编码。您在测试字符串中输入的内容将以与文件相同的方式进行编码。我也不会依赖mb_detect_编码函数。让我们看下面的字符串:“abcde”。它可以是ASCII或UTF-8。你不能判断,因为没有特殊的性格。编码是一种控制数据的方式

//编辑


为了让您的测试工作执行
$this->assertTrue(mb\u detect\u encoding($original,'UTF-8')=='UTF-8')

我可以确保文件是用UTF-8编码的。(是的)所以在这一点上,我知道原始文件是utf-8。我还在字符串中包含了仅限utf-8的字符。因此,您的“abcde”示例似乎不适用,因为在测试字符串中肯定存在非ascii字符。不管怎样,我只是创建了这个文件,我并不是说这是测试unicode支持的最佳方法,但是如果这不起作用,那么什么-将-。要让您的测试工作做到
$this->assertTrue(mb_detect_encoding($original,'UTF-8')===='UTF-8')
@LukaszKujawa您能将您的注释移动到编辑您的答案吗?那么勾号就有意义了:-)