0

Symfony で json API の機能テストをいくつか作成しています。

オブジェクトを使用し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

確かに、私は何か悪いことをしています。ヒントはありますか?

4

1 に答える 1

2

正規表現は失敗します。

newlinesを含むdotall (PCRE_DOTALL)のフラグs使用する必要があります。

この修飾子が設定されている場合、パターン内のドット メタ文字は、改行を含むすべての文字に一致します。それがない場合、改行は除外されます。

そう:

$browser->
    get('/hi')->
    with('response')->
    begin()->
    isStatusCode(200)->
    matches('/result\"\: true/')->
    matches('/one.*two/sm')->
end()

それ以外の場合は、2 つの異なるテストを作成できます。

$browser->
    get('/hi')->
    with('response')->
    begin()->
    isStatusCode(200)->
    matches('/result\"\: true/')->
    matches('/\"one\"')->
    matches('/\"two\"')->
end()
于 2012-12-19T18:52:46.863 に答える