我知道这篇文章已经发布了一年,但今天我遇到了类似的问题,并在这里发布了我的解决方案。
为了防止Google Groups的帖子被删除,我在此处复制:
问题
我的.feature文件大致如下:
Then I get a response with "error" equals to "<error>"
And I get a response with "error" equals to "<error_message>"
Examples:
|error | error_message |
|NotFoundHttpException | Something with quotes "More text here" |
你可以看到,我在调用同一个步骤来检查文本中包含引号和不包含引号的另一列。
当我运行Behat测试时,"More text here"被视为另一个参数,并且Behat会建议提供另一个片段。
解决方案
为了解决这个问题,我们需要使用与"不同的其他字符来告诉Behat存在一个变量,在我的情况下,我使用了单引号。
因此,我已经像这样更改了.feature文件:
Then I get a response with "error" equals to "<error>"
And I get a response with "error_message" equals to '<error_message>' escaping quotes
Examples:
|error | error_message |
|NotFoundHttpException | Something with quotes "More text here" |
那么我已经更新了我的PHP测试实现,就像这样:
public function iGetAResponseWithEqualsTo($attibute, $value)
这个实现被称为“非常相似的实现”。
我在阅读这篇文章后想到了这个解决方案,以备有需要的人参考。
Then the response json should have fragment '{"username": "admin"}'
非常好用。 - yaroslavche