-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Bump sa tools #5646
Bump sa tools #5646
Conversation
$datetime2 = new DateTimeImmutable('2018-04-10 10:10:10'); | ||
$date1 = $datetime1->modify('midnight'); | ||
$date2 = $datetime2->modify('midnight'); | ||
assert($date1 !== false && $date2 !== false); |
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.
Should these be two independent PHPUnit assertions?
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.
test framework assertions are supposed to be used when it's related to the use case that's the focus of this test. If $date1
and $date2
are false we have a different and much greater problem than a failing date-difference test.
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 tend to use assert
for assertions that are not really part of the test assertions, but a help for static analysis. I suppose in case of failure, the UX is going to be better with PHPUnit asserts though.
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.
The fact that these dates are not false is a pre-condition of the test itself which the static analyzer forces us to use. We know that it will fail if those are not met, so it's part of the test. We have a ton of such assertions in the codebase.
In any event, I believe this is a bad test and it should be deleted rather than fixed.
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.
My point is: it won't indicate a failure in the SUT, hence why I tend to want to make some kind of distinction. That last part is maybe not a good enough reason to prefer assert
though.
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.
In this specific case, the failure would happen in the data provider, so technically, it's the job of PHPUnit to report it as a setup failure rather than a failure in the SUT.
$date1 = $datetime1->modify('midnight'); | ||
$date2 = $datetime2->modify('midnight'); | ||
assert($date1 !== false && $date2 !== false); | ||
$expected = $date1->diff($date2)->days; |
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.
Not exactly related but if the expected value depends on the system clock, the test is not reproducible. I'd remove this "dynamic" case instead of fixing it.
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.
You're right, plus it's way too complex for a test, let's remove it.
Tests should stay be as simple as possible because their logic is not tested. This case makes the test unnecessarily hard to read.
1e10583
to
5916a43
Compare
5916a43
to
1b51745
Compare
No description provided.