Skip to content

Commit

Permalink
add redirect using url
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyPradana committed Oct 15, 2023
1 parent 9996919 commit e6e4305
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/System/Integrate/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,13 @@ function ($matches) use ($parameter, &$valueIndex) {
return new RedirectResponse($url);
}
}

if (!function_exists('redirect')) {
/**
* Redirect to Url.
*/
function redirect(string $url): RedirectResponse
{
return new RedirectResponse($url);
}
}
27 changes: 19 additions & 8 deletions tests/Integrate/Helper/RedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ final class RedirectResponseTest extends TestCase
public function itRiderectToCorrectUrl()
{
Router::get('/test/(:any)', fn ($test) => $test)->name('test');
$res = redirect_route('test', ['ok']);
$redirect = new TestResponse($res);
$redirect->assertStatusCode(302);
$redirect->assertSee('Redirecting to /test/ok');
$redirect = redirect_route('test', ['ok']);
$response = new TestResponse($redirect);
$response->assertStatusCode(302);
$response->assertSee('Redirecting to /test/ok');

Router::reset();
}
Expand All @@ -30,10 +30,10 @@ public function itRiderectToCorrectUrl()
public function itRiderectToCorrectUrlWithPlanUrl()
{
Router::get('/test', fn ($test) => $test)->name('test');
$res = redirect_route('test');
$redirect = new TestResponse($res);
$redirect->assertStatusCode(302);
$redirect->assertSee('Redirecting to /test');
$redirect = redirect_route('test');
$response = new TestResponse($redirect);
$response->assertStatusCode(302);
$response->assertSee('Redirecting to /test');

Router::reset();
}
Expand All @@ -54,4 +54,15 @@ public function itThrowErrorWhenPatternNotExist()

Router::reset();
}

/**
* @test
*/
public function itCanRedirectUsingUlrGiven()
{
$redirect = redirect('/test');
$response = new TestResponse($redirect);
$response->assertStatusCode(302);
$response->assertSee('Redirecting to /test');
}
}

0 comments on commit e6e4305

Please sign in to comment.