Skip to content

Commit bcdb79b

Browse files
committed
test: add tests for the current behavior
1 parent b9ec32e commit bcdb79b

1 file changed

Lines changed: 70 additions & 9 deletions

File tree

tests/system/HTTP/ResponseTest.php

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,23 +269,84 @@ public function testRedirectSetsDefaultCodeAndLocationHeader()
269269
$this->assertSame(302, $response->getStatusCode());
270270
}
271271

272-
public function testRedirectSetsCode()
273-
{
274-
$response = new Response(new App());
272+
/**
273+
* @dataProvider provideForRedirect
274+
*/
275+
public function testRedirect(
276+
string $server,
277+
string $protocol,
278+
string $method,
279+
?int $code,
280+
int $expectedCode
281+
) {
282+
$_SERVER['SERVER_SOFTWARE'] = $server;
283+
$_SERVER['SERVER_PROTOCOL'] = $protocol;
284+
$_SERVER['REQUEST_METHOD'] = $method;
275285

276-
$response->redirect('example.com', 'auto', 307);
286+
$response = new Response(new App());
287+
$response->redirect('example.com', 'auto', $code);
277288

278289
$this->assertTrue($response->hasHeader('location'));
279290
$this->assertSame('example.com', $response->getHeaderLine('Location'));
280-
$this->assertSame(307, $response->getStatusCode());
291+
$this->assertSame($expectedCode, $response->getStatusCode());
292+
}
293+
294+
public function provideForRedirect()
295+
{
296+
yield from [
297+
['Apache/2.4.17', 'HTTP/1.1', 'GET', null, 307],
298+
['Apache/2.4.17', 'HTTP/1.1', 'GET', 307, 307],
299+
['Apache/2.4.17', 'HTTP/1.1', 'GET', 302, 307],
300+
['Apache/2.4.17', 'HTTP/1.1', 'POST', null, 303],
301+
['Apache/2.4.17', 'HTTP/1.1', 'POST', 307, 303],
302+
['Apache/2.4.17', 'HTTP/1.1', 'POST', 302, 303],
303+
['Apache/2.4.17', 'HTTP/1.1', 'HEAD', null, 303],
304+
['Apache/2.4.17', 'HTTP/1.1', 'HEAD', 307, 303],
305+
['Apache/2.4.17', 'HTTP/1.1', 'HEAD', 302, 303],
306+
['Apache/2.4.17', 'HTTP/1.1', 'OPTION', null, 303],
307+
['Apache/2.4.17', 'HTTP/1.1', 'OPTION', 307, 303],
308+
['Apache/2.4.17', 'HTTP/1.1', 'OPTION', 302, 303],
309+
['Apache/2.4.17', 'HTTP/1.1', 'PUT', null, 303],
310+
['Apache/2.4.17', 'HTTP/1.1', 'PUT', 307, 303],
311+
['Apache/2.4.17', 'HTTP/1.1', 'PUT', 302, 303],
312+
['Apache/2.4.17', 'HTTP/1.1', 'DELETE', null, 303],
313+
['Apache/2.4.17', 'HTTP/1.1', 'DELETE', 307, 303],
314+
['Apache/2.4.17', 'HTTP/1.1', 'DELETE', 302, 303],
315+
];
281316
}
282317

283-
public function testRedirectWithIIS()
284-
{
318+
/**
319+
* @dataProvider provideForRedirectWithIIS
320+
*/
321+
public function testRedirectWithIIS(
322+
string $protocol,
323+
string $method,
324+
?int $code,
325+
int $expectedCode
326+
) {
285327
$_SERVER['SERVER_SOFTWARE'] = 'Microsoft-IIS';
286-
$response = new Response(new App());
287-
$response->redirect('example.com', 'auto', 307);
328+
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
329+
$_SERVER['REQUEST_METHOD'] = 'POST';
330+
331+
$response = new Response(new App());
332+
$response->redirect('example.com', 'auto', $code);
333+
288334
$this->assertSame('0;url=example.com', $response->getHeaderLine('Refresh'));
335+
$this->assertSame($expectedCode, $response->getStatusCode());
336+
337+
unset($_SERVER['SERVER_SOFTWARE']);
338+
}
339+
340+
public function provideForRedirectWithIIS()
341+
{
342+
yield from [
343+
['HTTP/1.1', 'GET', null, 302],
344+
['HTTP/1.1', 'GET', 307, 307],
345+
['HTTP/1.1', 'GET', 302, 302],
346+
['HTTP/1.1', 'POST', null, 302],
347+
['HTTP/1.1', 'POST', 307, 307],
348+
['HTTP/1.1', 'POST', 302, 302],
349+
];
289350
}
290351

291352
public function testSetCookieFails()

0 commit comments

Comments
 (0)