File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -81,4 +81,15 @@ public function withHeaders(array $headers): static
8181 return $ new ;
8282 }
8383
84+ /*
85+ * REDIRECT ***************************************************************
86+ */
87+
88+ public function withRedirect (string $ url , int $ statusCode = 302 ): static
89+ {
90+ return $ this
91+ ->withStatus ($ statusCode )
92+ ->withHeader ('Location ' , $ url );
93+ }
94+
8495}
Original file line number Diff line number Diff line change @@ -88,6 +88,30 @@ public function testWithAttributes(): void
8888 Assert::equal ('baz ' , $ this ->response ->getHeaderLine ('X-Bar ' ));
8989 }
9090
91+ public function testWithRedirect (): void
92+ {
93+ $ this ->response = $ this ->response ->withRedirect ('https://example.com ' );
94+
95+ Assert::equal (302 , $ this ->response ->getStatusCode ());
96+ Assert::equal ('https://example.com ' , $ this ->response ->getHeaderLine ('Location ' ));
97+ }
98+
99+ public function testWithRedirectCustomStatusCode (): void
100+ {
101+ $ this ->response = $ this ->response ->withRedirect ('https://example.com ' , 301 );
102+
103+ Assert::equal (301 , $ this ->response ->getStatusCode ());
104+ Assert::equal ('https://example.com ' , $ this ->response ->getHeaderLine ('Location ' ));
105+ }
106+
107+ public function testWithRedirect303 (): void
108+ {
109+ $ this ->response = $ this ->response ->withRedirect ('https://example.com/other ' , 303 );
110+
111+ Assert::equal (303 , $ this ->response ->getStatusCode ());
112+ Assert::equal ('https://example.com/other ' , $ this ->response ->getHeaderLine ('Location ' ));
113+ }
114+
91115 public function testOf (): void
92116 {
93117 $ this ->response = $ this ->response
You can’t perform that action at this time.
0 commit comments