2008年12月3日星期三

Re: [fw-mvc] Zend_Test - How to emulate raw XML POST data?

-- afx114 <jordan@bit-box.com> wrote
(on Tuesday, 02 December 2008, 04:59 PM -0800):
>
>
> funkyfly wrote:
> >
> > you can set it within the test method with:
> > $this->request->setMethod('POST')->setRawBody('<xml/>');
> >
>
> Hi, this doesn't appear to be working. In my controller, it appears as if
> the raw POST data is not there (or empty). The fact that it is empty means
> that the raw POST data isn't getting sent. Here is my full test code:
>
> public function testSendRawXML()
> {
> $xml = '<someXml>12345</someXml>';
> $this->request->setMethod('POST')->setRawBody($xml);
> $this->dispatch('/controller/action');
> }
>
> In my controller, I am reading in the raw POST data with the following code:
>
> $xml = file_get_contents('php://input');
>
> It is evaluating to empty, so it doesn't look like raw POST is getting set.
> Any ideas?

Don't use php://input in your controller -- pull the raw post body from
the request object:

$xml = $this->getRequest()->getRawBody();

Why do that, and not go to php://input? So you can test... which is
precisely what you're trying to do. ;)

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: