Skip to content

Commit fff9ef8

Browse files
Jack Zubantaylorotwell
Jack Zuban
authored andcommitted
Use TestResponse assertions and data provider in RouteRedirectTest (#24790)
1 parent a8f17c5 commit fff9ef8

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

tests/Integration/Routing/RouteRedirectTest.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,28 @@
1010
*/
1111
class RouteRedirectTest extends TestCase
1212
{
13-
public function test_route_redirect()
13+
/**
14+
* @dataProvider routeRedirectDataSets
15+
*
16+
* @param string $redirectFrom
17+
* @param string $redirectTo
18+
* @param string $responseUri
19+
*/
20+
public function testRouteRedirect($redirectFrom, $redirectTo, $responseUri)
1421
{
15-
Route::redirect('from', 'to', 301);
22+
Route::redirect($redirectFrom, $redirectTo, 301);
1623

17-
$response = $this->get('/from');
18-
$this->assertEquals(301, $response->getStatusCode());
19-
$this->assertEquals('to', $response->headers->get('Location'));
24+
$response = $this->get($responseUri);
25+
$response->assertRedirect($redirectTo);
26+
$response->assertStatus(301);
2027
}
2128

22-
public function test_route_redirect_with_params()
29+
public function routeRedirectDataSets(): array
2330
{
24-
Route::redirect('from/{param}/{param2?}', 'to', 301);
25-
26-
$response = $this->get('/from/value1/value2');
27-
$response->assertRedirect('to');
28-
29-
$this->assertEquals(301, $response->getStatusCode());
30-
$this->assertEquals('to', $response->headers->get('Location'));
31-
32-
$response = $this->get('/from/value1');
33-
$response->assertRedirect('to');
34-
35-
$this->assertEquals(301, $response->getStatusCode());
36-
$this->assertEquals('to', $response->headers->get('Location'));
31+
return [
32+
'route redirect with no parameters' => ['from', 'to', '/from'],
33+
'route redirect with one parameter' => ['from/{param}/{param2?}', 'to', '/from/value1'],
34+
'route redirect with two parameters' => ['from/{param}/{param2?}', 'to', '/from/value1/value2'],
35+
];
3736
}
3837
}

0 commit comments

Comments
 (0)