开发者

how to test PUT request parsing in PHPUnit

I'm parsing a PUT query this way :

$raw = file_get_contents('php://input');
$params = array();
parse_str($raw, $params);

and I'd like to inject some test content into php://input to test it (and for some non-unit tests too).

I tried to google a bit the matter, but 'put' is a short keyword and I didn't get anything relevant.

I'm ready to change a bit my parsing code to help testing or remove it if PH开发者_如何学JAVAP 5.3 already has infrastructure for that (I couldn't find anything in the release notes).


You can't write to the php://input stream (and you can usually only read it once). Instead of hard-coding the stream location, how about you allow it to be configured in your parser? That way you can use a mock object in your unit tests which has a different location (e.g. file or php://temp stream).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜