diff --git a/src/System/Integrate/helper.php b/src/System/Integrate/helper.php index 273b35fb..2b1ab8dd 100644 --- a/src/System/Integrate/helper.php +++ b/src/System/Integrate/helper.php @@ -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); + } +} diff --git a/tests/Integrate/Helper/RedirectResponseTest.php b/tests/Integrate/Helper/RedirectResponseTest.php index 0aeadedf..b7758ac6 100644 --- a/tests/Integrate/Helper/RedirectResponseTest.php +++ b/tests/Integrate/Helper/RedirectResponseTest.php @@ -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(); } @@ -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(); } @@ -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'); + } }