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

Addition of rule for cases better represented with assertSameSize() method #207

Open
wants to merge 3 commits into
base: 1.4.x
Choose a base branch
from

Conversation

o0h
Copy link
Sponsor

@o0h o0h commented Apr 4, 2024

This Pull Request enhances the AssertSameWithCountRule in PHPUnit to handle additional use cases. The new rule now checks when both sides of the assertSame are counts, and suggests assertSameSize instead when necessary.

Here is some detail on what has changed:

  • AssertSameWithCountRule now includes a check for cases where expected value of assertCount is the direct result of count function call.
  • In these cases, a special assertion function assertSameSize is suggested to compare the sizes of collections rather than using the original assertSame function.

The code changes involve adjustments in method call structures, evaluation of counts and introduction of cases for assertSameSize.

@o0h o0h marked this pull request as draft April 5, 2024 01:57
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
this should only be reported with bleeding edge. Use private bool $bleedingEdge in the rule constructor and add the new behaviour only when this is true. Here's an example how it should look in config: https://github.com/phpstan/phpstan-doctrine/blob/0d967379b8ea58c4f4499b17eeb9f29718350497/rules.neon#L57

@o0h
Copy link
Sponsor Author

o0h commented Apr 5, 2024

Hi, @ondrejmirtes!

Thanks for the quick feedback!
Sorry that it's not passing the CI checks just yet. I'll sort out the issue and let you know once it's ready for review.

I'll be sure to use the bleeding edge flag as you suggested. Just hang tight a little longer!

Best regards,

@o0h o0h force-pushed the suggest-assert-same-size branch from f74e9be to bff5e12 Compare April 5, 2024 18:05
Expanded the AssertSameWithCountRule in PHPUnit rules to handle additional scenarios. Now the rule checks if both sides of the assertSame are counts, and suggests assertSameSize instead when necessary. The modification enhances the rule's applicability and accuracy.
@o0h o0h force-pushed the suggest-assert-same-size branch from bff5e12 to 3a37222 Compare April 5, 2024 19:00
@o0h o0h marked this pull request as ready for review April 5, 2024 19:09
@o0h
Copy link
Sponsor Author

o0h commented Apr 5, 2024

I have completed the necessary corrections that were of concern.
I would appreciate it if you could take a look and check it.
Thank you 😃

The link in the README file's "bleeding edge" reference has been updated to accurately direct users to the relevant blog post. Also corrected the typo by capitalizing the initial letter of the sentence.
@o0h o0h requested a review from ondrejmirtes April 28, 2024 05:26
}

if (
$right instanceof Node\Expr\MethodCall
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH this diff is very messy. I can't tell if the no-bleedingEdge behaviour is preserved or not. Can you split the changes in multiple commits? First extract logic into isCount... methods without changing the behaviour, and then introduce bleedingEdge-on behaviour that will be a new separate if statement. Can you please do that? Thank you.

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

Successfully merging this pull request may close these issues.

None yet

2 participants