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

Documentation improvements regarding typesafety of "equals" and "same" #5910

Open
DBX12 opened this issue Aug 2, 2024 · 2 comments
Open

Comments

@DBX12
Copy link

DBX12 commented Aug 2, 2024

While working with codeception/verify, I've realized that equals does not assert the types of the variables but same does. I've already opened a PR there and got informed that this change should be made first in phpunit itself.

What is your position on this? If you think the changes I made in codeception/verify are beneficial in phpunit as well, I'd happily provide a PR for it.

Did I catch all relevant locations?

  • assertEquals and similar functions in src/Framework/Assert/Functions.php:385-437
  • assertNotEquals and similar functions in src/Framework/Assert/Functions.php:439-501
  • Assert::equals and similar functions in src/Framework/Assert.php:387-431
  • Assert::notEquals and similar functions in src/Framework/Assert.php:438-490
@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit Aug 2, 2024
@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit-documentation-english Aug 2, 2024
@sebastianbergmann
Copy link
Owner

Sorry, I was confused fas I saw "Documentation" in the title and thought "this belongs in the documentation repository".

Sure, we can improve that. If we do, then any improvement should not be limited to comments in the code (which I personally never look at) but should also include the actual documentation.

@Bilge
Copy link
Contributor

Bilge commented Aug 2, 2024

It's not just the case that equals ignores types; it does a loose equality comparison (==); the meaning of which changes depending on the operands.

$date = '2000-01-01';
Assert::assertEquals($a = new DateTime($date), $b = new DateTime($date)); // true
Assert::assertSame($a, $b); // false

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

3 participants