NYCPHP Meetup

NYPHP.org

[nycphp-talk] Test HTTP Headers with PHPUnit

Jakob Buchgraber jakob.buchgraber at googlemail.com
Mon May 14 13:24:34 EDT 2007


Hey!

I was wondering whether it is possible to test with PHPUnit if a HTTP 
header was sent.
It is definitely possible with PHP if run by a webserver.

e.g.
<?php
header ("Some-Header: Value");
var_dump (in_array ("Some-Header: Value", headers_list ()));
?>

However I am running my Unit Tests via PHP CLI, so HTTP Headers aren't 
sent and therefore headers_list () returns an empty array.

So is there anyway to test if the header function was called with a 
specific value from PHP CLI?

PS: I'm currently testing with Exceptions, so if 
HttpResponse::trigger404 () throws an Exception the header couldn't be 
sent otherwise it was sent, but I don't really like this solution.

Cheers,
Jay



More information about the talk mailing list