-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added a note about redirections to absolute URLs in tests #7521
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -284,8 +284,9 @@ document:: | |||
|
|||
// Assert that the response is a redirect to /demo/contact | |||
$this->assertTrue( | |||
$client->getResponse()->isRedirect('/demo/contact'), | |||
'response is a redirect to /demo/contact' | |||
$client->getResponse()->isRedirect('/demo/contact') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ease debugging, I learned to favor:
$this->assertSame(Response::HTTP_FOUND, $client->getResponse()->getStatusCode());
$this->assertSame('/demo/contact', $client->getResponse()->headers->get('location'));
And since it's very verbose and repetitive I've got a ControllerTestTrait which provides assertions like:
public function assertResponseStatusCode(Client $client, $code)
{
$this->assertSame($code, $client->getResponse()->getStatusCode());
}
public function assertClientIsRedirectedTo(Client $client, $url, $permanent = false)
{
$this->assertResponseStatusCode($client, $permanent ? Response::HTTP_MOVED_PERMANENTLY : Response::HTTP_FOUND);
$this->assertSame($url, $client->getResponse()->headers->get('location'));
}
As said in another PR, we need to avoid failure messages like "true is not false" as much as possible to debug faster. Comparing values gives insight immediately.
Maybe it is worth to update the example to advise it, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that's too much for this PR. Even if I agree with your idea (although I use a different implementation) I'd say that change would need a discussion first. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Javier. Let's keep it as is here.
Thank you @javiereguiluz. |
… (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
This fixes symfony/symfony#21189