dongzi3434 2018-05-20 14:04
浏览 65
已采纳

Iconv在phpunit中返回错误的字符串

I have project in SF4 and use phpunit 6.5.8. I tested service that use iconv:

iconv('UTF-8', 'ASCII//TRANSLIT', $string)

When I use this service in application and when $string has value: "ąbć", returned is "abc" but when the same service is runed in phpunit returned is "?b?".

I don't understand why it don't work... Of course the test is negative but in application it works good.

  • 写回答

2条回答 默认 最新

  • dpbdl44228 2018-06-09 11:41
    关注

    Ok, I solved a problem. Php in CLI don't set locale. So we must set it before tests.

    1. Check location which you have in system:

    locale -a
    

    For example:

    $ locale -a
    C
    C.UTF-8
    en_US.utf8
    

    2. In the tests add:

    setlocale(LC_CTYPE, 'en_US.utf8');
    

    3. Example:

        public static function setUpBeforeClass()
        {
            setlocale(LC_CTYPE, 'en_US.utf8');
        }
    

    source:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信