Skip to content

Commit

Permalink
Add assertSuccessful(), tweak assertRedirect() (#18629)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson authored and taylorotwell committed Apr 4, 2017
1 parent 9a25d13 commit 77860a8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public static function fromBaseResponse($response)
return new static($response);
}

/**
* Assert that the response has a successful status code.
*
* @return $this
*/
public function assertSuccessful()
{
PHPUnit::assertTrue(
$this->isSuccessful(),
'Response status code ['.$this->getStatusCode().'] is not a successful status code.'
);

return $this;
}

/**
* Assert that the response has the given status code.
*
Expand All @@ -70,13 +85,15 @@ public function assertStatus($status)
* @param string $uri
* @return $this
*/
public function assertRedirect($uri)
public function assertRedirect($uri = null)
{
PHPUnit::assertTrue(
$this->isRedirect(), 'Response status code ['.$this->getStatusCode().'] is not a redirect status code.'
);

PHPUnit::assertEquals(app('url')->to($uri), $this->headers->get('Location'));
if (! is_null($uri)) {
PHPUnit::assertEquals(app('url')->to($uri), $this->headers->get('Location'));
}

return $this;
}
Expand Down

0 comments on commit 77860a8

Please sign in to comment.