-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
use the message argument of assertX functions #6118
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
Assert functions from PHPUnit do have an optional message argument. This is especially usefull for assertTrue because the message printed on failure does not (and can not) contain any details. Demonstrate this possibility
$this->assertTrue($client->getResponse()->isSuccessful()); | ||
$this->assertTrue($client->getResponse()->isSuccessful(), | ||
'response status code is NOT 2xx' | ||
); |
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.
indention looks weird
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.
agree, )
should be at the same level as $this->...
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.
it should be either:
$this->assertTrue(
$client->getResponse()->isSuccessful(),
'Response status code is 2xx'
);
Or just everything on one line.
I like this PR 👍 Status: Reviewed |
My comments about this:
|
My two cents: I never use |
My motivation to write assert messages is not readable code. It is the failure message. Example failure without assert message:
Without checking the source code at the mentioned line I do not know what went wrong. (Did isRedirect() fail or is the content type wrong?) By using assertSame(200, ...) or assertEquals I can guess that I prefer a failure message like this
Write the assert message positive or negative or ...? I do not know which of this messages is clearer. Some suggestions:
|
I agree with @javiereguiluz that I prefer to use positive messages. It seems to be the common practice in Symfony core as well. 👍 for adding this messages btw, it makes things more clear in the PHPunit test report. |
Oh, can you please update your PR? (I know it's from a long time ago, if you don't want to do it anymore/have no time now feel free to say so and we'll take over). Status: needs work |
Hi @SimonHeimberg! I took your commit and added a new one to make the messages positive. See #6736 Thank you for making these changes! I'm going to close this one in favor of the new PR. |
…nHeimberg, WouterJ) This PR was merged into the 2.7 branch. Discussion ---------- Use message argument for PHPunit assert() functions Finishes #6118 Original PR description: > Assert functions from PHPUnit do have an optional message argument. This is especially usefull for assertTrue because the message printed on failure does not (and can not) contain any details. Demonstrate this possibility Commits ------- d604bfd Make messages positive 97e072e use the message argument of assertX functions
Assert functions from PHPUnit do have an optional message argument. This is especially usefull for assertTrue because the message printed on failure does not (and can not) contain any details. Demonstrate this possibility