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

Bump sa tools #5646

Merged
merged 4 commits into from
Sep 1, 2022
Merged

Bump sa tools #5646

merged 4 commits into from
Sep 1, 2022

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Sep 1, 2022

No description provided.

@greg0ire greg0ire marked this pull request as ready for review September 1, 2022 19:34
$datetime2 = new DateTimeImmutable('2018-04-10 10:10:10');
$date1 = $datetime1->modify('midnight');
$date2 = $datetime2->modify('midnight');
assert($date1 !== false && $date2 !== false);
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@morozov morozov Sep 1, 2022

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.

Copy link
Member Author

@greg0ire greg0ire Sep 1, 2022

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.

Copy link
Member

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;
Copy link
Member

@morozov morozov Sep 1, 2022

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.

Copy link
Member Author

@greg0ire greg0ire Sep 1, 2022

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.
@greg0ire greg0ire merged commit 4cbbe6e into doctrine:3.4.x Sep 1, 2022
@greg0ire greg0ire deleted the bump-sa-tools branch September 1, 2022 21:26
@greg0ire greg0ire added this to the 3.4.4 milestone Sep 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants