Get the body of the request

724 views
Skip to first unread message

Adrian Moya

unread,
Mar 31, 2012, 12:59:04 PM3/31/12
to guz...@googlegroups.com
Hi Michael, is there a way to get the body of a request before sending? I discovered an error in one of my clients I wish to cover with a unit test, so that I can check (as I currently do with the url and the query params) if the body is getting built correctly. Something like:

$command->prepare();

$this->assertEquals('{"something":"something"}', $command->getRequest()->getRequestBody());

I currently was able to came up with this:

$this->assertEquals('{"something":"something"}', $command->getRequest()->getBody()->read(200));

But I still have to play with lenght to get it right. I plan to implement this test on all my POST commands.

Thanks! 

Michael Dowling

unread,
Mar 31, 2012, 1:20:40 PM3/31/12
to guz...@googlegroups.com
Hi Adrian,

You can read the body as a string by casting the body of the request to string or by calling the __toString method of the request entity body.

Thanks,
Michael

Reply all
Reply to author
Forward
0 new messages