88use PHPUnit \Framework \Attributes \DataProvider ;
99use PHPUnit \Framework \TestCase ;
1010use Tempest \Framework \Testing \Http \TestResponseHelper ;
11+ use Tempest \Http \GenericRequest ;
1112use Tempest \Http \GenericResponse ;
13+ use Tempest \Http \Method ;
1214use Tempest \Http \Status ;
1315
1416/**
@@ -19,7 +21,7 @@ final class TestResponseHelperTest extends TestCase
1921 public function test_get_response (): void
2022 {
2123 $ response = new GenericResponse (status: Status::OK );
22- $ helper = new TestResponseHelper ($ response );
24+ $ helper = new TestResponseHelper ($ response, new GenericRequest (Method:: GET , ' / ' ) );
2325
2426 $ this ->assertSame ($ response , $ helper ->response );
2527 }
@@ -31,6 +33,7 @@ public function test_assert_has_header(): void
3133 status: Status::OK ,
3234 headers: ['Location ' => '/new-location ' ],
3335 ),
36+ new GenericRequest (Method::GET , '/ ' ),
3437 );
3538
3639 $ helper ->assertHasHeader ('Location ' );
@@ -39,9 +42,8 @@ public function test_assert_has_header(): void
3942 public function test_assert_has_header_failure (): void
4043 {
4144 $ helper = new TestResponseHelper (
42- new GenericResponse (
43- status: Status::OK ,
44- ),
45+ new GenericResponse (status: Status::OK ),
46+ new GenericRequest (Method::GET , '/ ' ),
4547 );
4648
4749 $ this ->expectException (AssertionFailedError::class);
@@ -56,6 +58,7 @@ public function test_assert_header_value_equals(): void
5658 status: Status::OK ,
5759 headers: ['Content-Type ' => ['application/json ' ]],
5860 ),
61+ new GenericRequest (Method::GET , '/ ' ),
5962 );
6063
6164 $ helper ->assertHeaderContains ('Content-Type ' , 'application/json ' );
@@ -65,6 +68,7 @@ public function test_assert_header_value_equals_failure(): void
6568 {
6669 $ helper = new TestResponseHelper (
6770 new GenericResponse (status: Status::OK ),
71+ new GenericRequest (Method::GET , '/ ' ),
6872 );
6973
7074 $ this ->expectException (AssertionFailedError::class);
@@ -81,6 +85,7 @@ public function test_assert_redirect(): void
8185 'Location ' => ['/other-location ' ],
8286 ],
8387 ),
88+ new GenericRequest (Method::GET , '/ ' ),
8489 );
8590
8691 $ helper ->assertRedirect ();
@@ -90,6 +95,7 @@ public function test_assert_redirect_without_location_header(): void
9095 {
9196 $ helper = new TestResponseHelper (
9297 new GenericResponse (status: Status::FOUND ),
98+ new GenericRequest (Method::GET , '/ ' ),
9399 );
94100
95101 $ this ->expectException (AssertionFailedError::class);
@@ -104,6 +110,7 @@ public function test_assert_redirect_without_3xx_status_code(): void
104110 status: Status::OK ,
105111 headers: ['Location ' => '/other-location ' ],
106112 ),
113+ new GenericRequest (Method::GET , '/ ' ),
107114 );
108115
109116 $ this ->expectException (AssertionFailedError::class);
@@ -118,6 +125,7 @@ public function test_assert_redirect_to(): void
118125 status: Status::FOUND ,
119126 headers: ['Location ' => ['/other-location ' ]],
120127 ),
128+ new GenericRequest (Method::GET , '/ ' ),
121129 );
122130
123131 $ helper ->assertRedirect ('/other-location ' );
@@ -127,6 +135,7 @@ public function test_assert_ok(): void
127135 {
128136 $ helper = new TestResponseHelper (
129137 new GenericResponse (status: Status::OK ),
138+ new GenericRequest (Method::GET , '/ ' ),
130139 );
131140
132141 $ helper ->assertOk ();
@@ -136,6 +145,7 @@ public function test_assert_ok_fails_with_not_okay_response(): void
136145 {
137146 $ helper = new TestResponseHelper (
138147 new GenericResponse (status: Status::INTERNAL_SERVER_ERROR ),
148+ new GenericRequest (Method::GET , '/ ' ),
139149 );
140150
141151 $ this ->expectException (AssertionFailedError::class);
@@ -147,6 +157,7 @@ public function test_assert_not_found(): void
147157 {
148158 $ helper = new TestResponseHelper (
149159 new GenericResponse (status: Status::NOT_FOUND ),
160+ new GenericRequest (Method::GET , '/ ' ),
150161 );
151162
152163 $ helper ->assertNotFound ();
@@ -156,6 +167,7 @@ public function test_assert_not_found_fails_with_okay_response(): void
156167 {
157168 $ helper = new TestResponseHelper (
158169 new GenericResponse (status: Status::OK ),
170+ new GenericRequest (Method::GET , '/ ' ),
159171 );
160172
161173 $ this ->expectException (AssertionFailedError::class);
@@ -166,15 +178,15 @@ public function test_assert_not_found_fails_with_okay_response(): void
166178 #[DataProvider('provide_assert_status_cases ' )]
167179 public function test_assert_status (Status $ expectedStatus , GenericResponse $ response ): void
168180 {
169- $ helper = new TestResponseHelper ($ response );
181+ $ helper = new TestResponseHelper ($ response, new GenericRequest (Method:: GET , ' / ' ) );
170182
171183 $ helper ->assertStatus ($ expectedStatus );
172184 }
173185
174186 #[DataProvider('provide_assert_status_fails_when_status_does_not_match_cases ' )]
175187 public function test_assert_status_fails_when_status_does_not_match (Status $ expectedStatus , GenericResponse $ response ): void
176188 {
177- $ helper = new TestResponseHelper ($ response );
189+ $ helper = new TestResponseHelper ($ response, new GenericRequest (Method:: GET , ' / ' ) );
178190
179191 $ this ->expectException (AssertionFailedError::class);
180192
@@ -185,6 +197,7 @@ public function test_assert_json_has_keys(): void
185197 {
186198 $ helper = new TestResponseHelper (
187199 new GenericResponse (status: Status::OK , body: ['title ' => 'Timeline Taxi ' , 'author ' => ['name ' => 'John ' ]]),
200+ new GenericRequest (Method::GET , '/ ' ),
188201 );
189202
190203 $ helper ->assertJsonHasKeys ('title ' , 'author.name ' );
@@ -194,6 +207,7 @@ public function test_assert_json_contains(): void
194207 {
195208 $ helper = new TestResponseHelper (
196209 new GenericResponse (status: Status::OK , body: ['title ' => 'Timeline Taxi ' , 'author ' => ['name ' => 'John ' ]]),
210+ new GenericRequest (Method::GET , '/ ' ),
197211 );
198212
199213 $ helper ->assertJsonContains (['title ' => 'Timeline Taxi ' ]);
@@ -205,6 +219,7 @@ public function test_assert_json(): void
205219 {
206220 $ helper = new TestResponseHelper (
207221 new GenericResponse (status: Status::OK , body: ['title ' => 'Timeline Taxi ' , 'author ' => ['name ' => 'John ' ]]),
222+ new GenericRequest (Method::GET , '/ ' ),
208223 );
209224
210225 $ helper ->assertJson (['title ' => 'Timeline Taxi ' , 'author ' => ['name ' => 'John ' ]]);
0 commit comments