Skip to content

Commit 74ea1a9

Browse files
committed
Added constructors for common Response instances
1 parent 926cd8c commit 74ea1a9

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/Response.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public static function redirect($uri, int $status = 303): self
9292
return new self($status, null, ['Location' => (string) $uri]);
9393
}
9494

95+
public static function badRequest(StreamInterface $body = null): self
96+
{
97+
return new self(400, $body);
98+
}
99+
100+
public static function unauthorized(StreamInterface $body = null): self
101+
{
102+
return new self(401, $body);
103+
}
104+
95105
public static function notFound(StreamInterface $body = null): self
96106
{
97107
return new self(404, $body);

tests/ResponseTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ public function testNamedConstructors()
138138
new Response(301, null, ['Location' => '/foo/bar/baz']),
139139
Response::redirect('/foo/bar/baz', 301)
140140
);
141-
$this->equivalentConstructs(
142-
new Response(404),
143-
Response::notFound()
144-
);
141+
$this->equivalentConstructs(new Response(400), Response::badRequest());
142+
$this->equivalentConstructs(new Response(401), Response::unauthorized());
143+
$this->equivalentConstructs(new Response(404), Response::notFound());
145144
$this->equivalentConstructs(
146145
new Response(404, new FakeStream('Not Found. Sorry.')),
147146
Response::notFound(new FakeStream('Not Found. Sorry.'))

0 commit comments

Comments
 (0)