Php Symfony中的功能测试:如何在多条线路上进行匹配?
我正在为Symfony中的json api构建一些功能测试 使用Php Symfony中的功能测试:如何在多条线路上进行匹配?,php,json,web-services,symfony-1.4,functional-testing,Php,Json,Web Services,Symfony 1.4,Functional Testing,我正在为Symfony中的json api构建一些功能测试 使用sfTestFunctional对象测试我的结果,我将尝试验证以下响应: { "result": true, "content": [ "one", "two" ] } 比如: $browser = new sfTestFunctional(new sfBrowser()); $browser-> get('/hi')-> with(
sfTestFunctional
对象测试我的结果,我将尝试验证以下响应:
{
"result": true,
"content": [
"one",
"two"
]
}
比如:
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/hi')->
with('response')->
begin()->
isStatusCode(200)->
matches('/result\"\: true/')->
matches('/one.*two/m')->
end()
现在我得到的是:
ok 1 - status code is 200
ok 2 - response content matches regex /result\\: true/"
not ok 3 - response content matches regex /one.*two/m
当然,我做错了什么。有什么提示吗?正则表达式失败
您应该使用包含换行符的
如果设置了此修改器,则图案中的点元字符将匹配所有字符,包括换行符。没有它,新行被排除在外
因此:
否则,您可以进行两种不同的测试:
$browser->
get('/hi')->
with('response')->
begin()->
isStatusCode(200)->
matches('/result\"\: true/')->
matches('/\"one\"')->
matches('/\"two\"')->
end()
是的,就是这个!我不得不去掉m,但现在我可以匹配新行了。谢谢@jOk!因此,IO通过以下方式获得匹配:matches('/one.*two/s')->
$browser->
get('/hi')->
with('response')->
begin()->
isStatusCode(200)->
matches('/result\"\: true/')->
matches('/\"one\"')->
matches('/\"two\"')->
end()