Skip to content

Commit

Permalink
Added constructors for common Response instances
Browse files Browse the repository at this point in the history
  • Loading branch information
shudd3r committed Aug 31, 2022
1 parent 926cd8c commit 74ea1a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public static function redirect($uri, int $status = 303): self
return new self($status, null, ['Location' => (string) $uri]);
}

public static function badRequest(StreamInterface $body = null): self
{
return new self(400, $body);
}

public static function unauthorized(StreamInterface $body = null): self
{
return new self(401, $body);
}

public static function notFound(StreamInterface $body = null): self
{
return new self(404, $body);
Expand Down
7 changes: 3 additions & 4 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ public function testNamedConstructors()
new Response(301, null, ['Location' => '/foo/bar/baz']),
Response::redirect('/foo/bar/baz', 301)
);
$this->equivalentConstructs(
new Response(404),
Response::notFound()
);
$this->equivalentConstructs(new Response(400), Response::badRequest());
$this->equivalentConstructs(new Response(401), Response::unauthorized());
$this->equivalentConstructs(new Response(404), Response::notFound());
$this->equivalentConstructs(
new Response(404, new FakeStream('Not Found. Sorry.')),
Response::notFound(new FakeStream('Not Found. Sorry.'))
Expand Down

0 comments on commit 74ea1a9

Please sign in to comment.