Either use a Mock that returns a header but does not send it or write a Response object, for example.
class HttpResponse
{
protected $_status = '200 OK';
protected $_headers = array();
protected $_body = null;
public function setStatus($status)
{
$this->_status = $status;
}
public function getStatus()
{
return $this->_status;
}
public function addHeader($name, $value)
{
$this->_headers[$name] = $value;
return $this;
}
public function getHeaders()
{
return $this->_headers;
}
public function write($data)
{
$this->_body .= $data;
return $this;
}
public function send()
{
header('HTTP/1.0 ' . $this->_status);
foreach ($this->headers as $name => $value) {
header("$name : $value");
}
echo $this->_body;
$this->resetRequest();
}
public function resetRequest()
{
$this->_status = '200 OK';
$this->_headers = array();
$this->_body = null;
}
}
So, while you're not send(), you can check the status through getters. You can also add a method __toString()that returns the Entire Response as a string and a regular expression to see if it looks like what you expect it to look like.
source
share