Skip to content

Commit

Permalink
Adding assert_status assertion for testing http reponses status code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Luraine committed May 15, 2010
1 parent d555b54 commit 5afc805
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/limonade/assertions.php
Expand Up @@ -161,10 +161,13 @@ function assert_header($response, $expected_name, $expected_value = null, $messa
return assert("true; //");
}

function assert_response($response, $expected_status, $message)
function assert_status($response, $expected_status, $message = "expected status code to be equal to '%s' but received '%s'")
{
// if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $header_line, $matches)) {
// $this->_http_version = $matches[1];
// $this->_response_code = $matches[2];
// }
$lines = explode('\n', trim($response));
if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $lines[0], $matches))
{
$status = $matches[2];
return assert('$expected_status == $status; //'.sprintf($message, $expected_status, $status));
}
return assert("false; //no status code returned in this response string");
}

0 comments on commit 5afc805

Please sign in to comment.