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

Assertions for comparing arrays while ignoring a specified list of keys #5600

Closed
wants to merge 2 commits into from

Conversation

sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented Dec 6, 2023

This implements the assertArrayIsEqualToArrayIgnoringListOfKeys() and assertArrayIsIdenticalToArrayIgnoringListOfKeys() assertions that compare two arrays while ignoring a list of keys. This is useful when the arrays that are to be compared contain date/time-dependent or random information.

This also implements the assertArrayIsEqualToArrayOnlyConsideringListOfKeys() and assertArrayIsEqualToArrayOnlyConsideringListOfKeys() assertions that assert that two arrays are equal (or identical, respectively) while only considering a list of keys. This is useful when there are more keys to be ignored (see above) than to actually be considered for the comparison.

I am reluctant to add new assertions, but the use cases they address have been brought up a couple of times recently, so maybe they should be added.

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/assertion Issues related to assertions and expectations labels Dec 6, 2023
@sebastianbergmann sebastianbergmann added this to the PHPUnit 11.0 milestone Dec 6, 2023
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0fc2a23) 88.46% compared to head (2722a9c) 88.47%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5600      +/-   ##
============================================
+ Coverage     88.46%   88.47%   +0.01%     
- Complexity     6258     6272      +14     
============================================
  Files           668      668              
  Lines         20047    20071      +24     
============================================
+ Hits          17734    17758      +24     
  Misses         2313     2313              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastianbergmann sebastianbergmann changed the title Implement assertArrayIsEqualToArrayIgnoringKeys() and assertArrayIsIdenticalToArrayIgnoringKeys() Assertions for comparing while ignoring a specified list of keys Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant