1

Hey sorry if this question is too specific but Im having to refactor some legacy Symfony1.4 code and I can't work out how to dump the response of a get request in a test, to aid debugging a strange error.

The test in question looks like this:

public function testDataset () {
$browser = $this->getBrowser();
$browser->
get('/search/dataset')->
with('request')->begin()->
isParameter('module', 'search')->
isParameter('action', 'dataset')->
end()->
with('response')->begin()->
isStatusCode(200)->
checkElement('body', '/Choose your dataset/')->
checkElement('#compareBy', '/High-density residental/')->
checkElement('#compareBy', '/Medium-density residential/')->
checkElement('#compareBy', '/Low-density residential/')->
checkElement('#compareBy', '/Commercial/')->
checkElement('#compareBy', '/CBD/')->
checkElement('#compareBy', '/Heavy industrial/')->
checkElement('#compareBy', '/Light industrial/')->
checkElement('#compareBy', '/Highway \/ Motorway/')->
checkElement('#compareBy', '/Arterial roads/')->
checkElement('#compareBy', '/Local roads/')->
checkElement('#compareBy', '/Open space/')->
checkElement('#dataLocation','/All New Zealand/')->
checkElement('#dataLocation','/All North Island/')->
checkElement('#dataLocation','/All South Island/')->
checkElement('#dataLocation','/Northland/')->
checkElement('#dataLocation','/Auckland/')->
checkElement('#dataLocation','/Waikato/')->
checkElement('#dataLocation','/Bay of Plenty/')->
checkElement('#dataLocation','/Taranaki/')->
checkElement('#dataLocation','/Gisborne/')->
checkElement('#dataLocation','/Hawkes Bay/')->
checkElement('#dataLocation','/Manawatu-Wanganui/')->
checkElement('#dataLocation','/Wellington/')->
checkElement('#dataLocation','/Nelson/')->
checkElement('#dataLocation','/Tasman/')->
checkElement('#dataLocation','/Marlborough/')->
checkElement('#dataLocation','/West Coast/')->
checkElement('#dataLocation','/Canterbury/')->
checkElement('#dataLocation','/Otago/')->
checkElement('#dataLocation','/Southland/')->
checkElement('#waterTypes','/All stormwater/')->
checkElement('#waterTypes','/Untreated stormwater/')->
checkElement('#waterTypes','/Treated stormwater/')->
checkElement('#waterTypes','/Urban streams/')->
checkElement('#waterTypes','/All water types/')->
checkElement('#flowType','/Storm event/')->
checkElement('#flowType','/Baseflow/')->
end();
}

And its failing with:

functional_frontend_searchActionsTest::testDataset
response selector "#compareBy" matches regex "/High-density residental/"
Failed asserting that false is true.

The page loads fine but I don't know how to actually dump the page response body in the test to investigate what the test is seeing. Ive tried $browser->getContent(), $browser->getResponse(), $browser->getBody()..

This is fairly trivial in phpunit / Symfony2 and Im sure there is a way to do this, can anyone help?

1 Answer 1

1

You can use the debug method on the sfWebResponse object. as example:

$browser->with('response')->debug();

You can check in the legacy doc here:

Debugging Functional Tests

Sometimes a functional test fails. As symfony simulates a browser without any graphical interface, it can be hard to diagnose the problem. Thankfully, symfony provides the debug() method to output the response header and content:

$browser->with('response')->debug();

The debug() method can be inserted anywhere in a response tester block and will halt the script execution.

Hope this help

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you thats prefect. I also found you can use "print_r( $browser->getResponse()->getContent() );die;" to dump the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.