Skip to content

Commit

Permalink
Add custom message to response code assertions
Browse files Browse the repository at this point in the history
It would be nice to be able to pass in a custom message to the response code convenience methods.  Especially since it is already supported in the protected method _assertStatus.
  • Loading branch information
jadedcore committed Oct 19, 2017
1 parent 5cbedd3 commit 4acf17f
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -702,39 +702,51 @@ public function viewVariable($name)
*
* @return void
*/
public function assertResponseOk()
public function assertResponseOk($message)
{
$this->_assertStatus(200, 204, 'Status code is not between 200 and 204');
if (empty($message)) {
$message = 'Status code is not between 200 and 204';
}
$this->_assertStatus(200, 204, $message);
}

/**
* Asserts that the response status code is in the 2xx/3xx range.
*
* @return void
*/
public function assertResponseSuccess()
public function assertResponseSuccess($message)
{
$this->_assertStatus(200, 308, 'Status code is not between 200 and 308');
if (empty($message)) {
$message = 'Status code is not between 200 and 308';
}
$this->_assertStatus(200, 308, $message);
}

/**
* Asserts that the response status code is in the 4xx range.
*
* @return void
*/
public function assertResponseError()
public function assertResponseError($message)
{
$this->_assertStatus(400, 429, 'Status code is not between 400 and 429');
if (empty($message)) {
$message = 'Status code is not between 400 and 429';
}
$this->_assertStatus(400, 429, $message);
}

/**
* Asserts that the response status code is in the 5xx range.
*
* @return void
*/
public function assertResponseFailure()
public function assertResponseFailure($message)
{
$this->_assertStatus(500, 505, 'Status code is not between 500 and 505');
if (empty($message)) {
$message = 'Status code is not between 500 and 505';
}
$this->_assertStatus(500, 505, $message);
}

/**
Expand All @@ -743,10 +755,15 @@ public function assertResponseFailure()
* @param int $code Status code to assert.
* @return void
*/
public function assertResponseCode($code)
public function assertResponseCode($code, $message)
{
$actual = $this->_response->getStatusCode();
$this->_assertStatus($code, $code, 'Status code is not ' . $code . ' but ' . $actual);

if (empty($message)) {
$message = 'Status code is not ' . $code . ' but ' . $actual;
}

$this->_assertStatus($code, $code, $message);
}

/**
Expand Down

0 comments on commit 4acf17f

Please sign in to comment.