Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add assertRedirectToRoute to TestResponse #44926

Merged
merged 2 commits into from
Nov 14, 2022
Merged

[9.x] Add assertRedirectToRoute to TestResponse #44926

merged 2 commits into from
Nov 14, 2022

Conversation

zaherg
Copy link
Contributor

@zaherg zaherg commented Nov 13, 2022

Illuminate\Testing\TestResponse has several helpers to assert the response has a redirect of various types. There is assertRedirect(string $uri = null), assertRedirectContains(string $uri), and assertRedirectToSignedRoute(string $name = null, array $parameters = []).

This PR add a missing assertion assertRedirectToRoute, which in theory does not differ much from assertRedirectToSignedRoute.

Used as the following:

$this->get('test-route')
    ->assertRedirectToRoute('named-route');

and in case of passing parameters we use it as the following:

$this->get('test-route')
    ->assertRedirectToRoute('named-route-with-param', 'hello');

$this->get('test-route-with-extra-param')
    ->assertRedirectToRoute('named-route-with-param', [
        'param' => 'foo',
        'extra' => 'another',
    ]);

@zaherg zaherg changed the title [9.x] Adding assertRedirectToRoute to TestResponse [9.x] Add assertRedirectToRoute to TestResponse Nov 13, 2022
@taylorotwell taylorotwell merged commit 0247079 into laravel:9.x Nov 14, 2022
@gms8994
Copy link
Contributor

gms8994 commented Nov 15, 2022

The assertRedirectToRoute function suggests that it can take a null value, but passing in a null value throws an error:

See this test case for PoC:

public function testAssertRedirectToRouteWithoutRouteName()
{
    $this->router->get('test-route', function () {
        return new RedirectResponse($this->urlGenerator->route('named-route'));
    });

    $this->get('test-route')
        ->assertRedirectToRoute();
}

@zaherg
Copy link
Contributor Author

zaherg commented Nov 16, 2022

I'll push new code in a few min.

thanks @gms8994 for catching this, I added your test to the code to make sure everything is working as it should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants