8000 Domain required in Phpunit test when redirecting · Issue #21189 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Domain required in Phpunit test when redirecting #21189

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

Closed
c33s opened this issue Jan 7, 2017 · 8 comments
Closed

Domain required in Phpunit test when redirecting #21189

c33s opened this issue Jan 7, 2017 · 8 comments

Comments

@c33s
Copy link
c33s commented Jan 7, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2.1
  • PHPUnit 5.7.4
  • PHP 7.0.13
  • Windows7x64
  • Symfony 3.2.1

the following test, taken from https://symfony.com/doc/current/testing.html#working-with-the-test-client (scroll up to Useful Assertions), shows the example without domain:

// Assert that the response is a redirect to /demo/contact
$this->assertTrue(
    $client->getResponse()->isRedirect('/demo/contact'),
    'response is a redirect to /demo/contact'
);

doing the same in my tests fails:

    public function testPressRedirect()
    {
        $client = static::createClient();
        $client->request('GET', '/press');
        $this->assertTrue($client->getResponse()->isRedirect('/en/press')); //fails
    }

routing.yml

_press_redirect:
    path: /press
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /en/press
        permanent: true

I have to include the domain and the protocol to make it work:

    public function testPressRedirect()
    {
        $client = static::createClient();
        $client->request('GET', '/press');
        $this->assertTrue($client->getResponse()->isRedirect('http://localhost/en/press')); //works
    }
@xabbuh
Copy link
Member
xabbuh commented Jan 8, 2017

I think this is something that needs to be clarified in the documentation instead.

@javiereguiluz
Copy link
Member

@xabbuh what's exactly the cause for this? I'd like to create the doc change you suggested, but I don't fully understand this. Thanks!

@xabbuh
Copy link
Member
xabbuh commented Feb 22, 2017

@javiereguiluz In the example where we show how to pass the expected path to isRedirect() we should path the full URL instead.

@javiereguiluz
Copy link
Member

That's what I don't understand ... I've checked some of my tests and I don't use the absolute URL ... and they work 😕

@jakzal
Copy link
Contributor
jakzal commented Feb 22, 2017

It all depends on how you generate the url you later pass to the RedirectResponse. If you generated an absolute path, the redirect will be made to an absolute path.

@javiereguiluz
Copy link
Member

@jakzal it's all clear now! Thanks!

@yceruto
Copy link
Member
yceruto commented Feb 22, 2017

@javiereguiluz you can see an example here: https://github.com/symfony/symfony-demo/pull/481/files#diff-225f8fc4f30fb429a96063d2612368b3R77 ;)

@javiereguiluz
Copy link
Member

@c33s at the end this wasn't a Symfony bug but something that could be better documented. That's why I'm closing this and we're improving the docs at symfony/symfony-docs#7521

Thank you all for your help!

xabbuh added a commit to symfony/symfony-docs that referenced this issue Apr 15, 2017
… (javiereguiluz)

This PR was squashed before being merged into the 2.7 branch (closes #7521).

Discussion
----------

Added a note about redirections to absolute URLs in tests

This fixes symfony/symfony#21189

Commits
-------

8414fb7 Added a note about redirections to absolute URLs in tests
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

No branches or pull requests

5 participants
0