我正在使用 PHPUnit 和类从 Symfony2 测试我的控制器WebTestCase
return self::$client->request(
'POST', '/withdraw',
array("amount" => 130),
array(),array());
$this->assertEquals(
"You can withdraw up to £100.00.",
$crawler->filter("#error-notification")->text());
但我收到这个错误:
Expected: "You can withdraw up to £100.00."
Actual: "You can withdraw up to £100.00."
问题是,在网页和源代码中它看起来不错,所以我在想也许 PHPUnit 在以 UTF8 形式获取文本时遇到了一些麻烦?
我缺少什么?
解决方案:
确保mbstring
扩展已启用。
有一个bug http://dev.kohanaframework.org/issues/4637关于失败的测试iconv
在 Kohana Bugtracker 中报告。
tips:
正如提议的这个问题/答案 https://stackoverflow.com/q/12573621/1832745- 您可以测试正确的 UTF-8 输出:
$this->assertEquals(
mb_detect_encoding(
crawler->filter("#error-notification")->text(),
'UTF-8'
),
'UTF-8'
);
您可以包括accept-charset
客户端发送的请求的标头:
$client->request(
'POST', '/withdraw',
array("amount" => 130),
array(),
array(),
array('HTTP_ACCEPT_CHARSET' => 'utf-8')
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)