Skip to content

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

Closed
sebastianbergmann wants to merge 2 commits intomainfrom
array-comparison-ignoring-keys
Closed

Assertions for comparing arrays while ignoring a specified list of keys#5600
sebastianbergmann wants to merge 2 commits intomainfrom
array-comparison-ignoring-keys

Conversation

@sebastianbergmann
Copy link
Copy Markdown
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
@codecov
Copy link
Copy Markdown

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
@sebastianbergmann sebastianbergmann force-pushed the array-comparison-ignoring-keys branch from 036b3bf to a505e63 Compare December 12, 2023 07:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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