Skip to content

assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() does not correctly handle array order#5729

Merged
sebastianbergmann merged 1 commit intosebastianbergmann:11.0from
jrfnl:feature/assertarrayidentical-bugfix
Mar 10, 2024
Merged

assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() does not correctly handle array order#5729
sebastianbergmann merged 1 commit intosebastianbergmann:11.0from
jrfnl:feature/assertarrayidentical-bugfix

Conversation

@jrfnl
Copy link
Copy Markdown
Contributor

@jrfnl jrfnl commented Mar 10, 2024

Follow up on #5716.

Sorry, I screwed up.

While the fix in #5716 correctly fixes the handling of array keys to be in line with PHP itself, it broke the differentiation between isEqual and isIdentical as the arrays were now being recreated in the order of the keys passed to the $keysToBeConsidered parameter.

This is not problematic for the assertArrayIsEqualToArrayOnlyConsideringListOfKeys() assertion as the array order is not relevant there.

However, it is problematic for the assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() assertion, where the array order is relevant.

This commit fixes it.

Includes unit test safeguarding the fix.

And while the assertArrayIs*ToArrayIgnoringListOfKeys() assertions are not affected, I've also included a unit test for the issue for those assertions, just to be on the safe side.

Follow up on 5716.

Sorry, I screwed up.

While the fix in 5716 correctly fixes the handling of array keys to be in line with PHP itself, it broke the differentiation between `isEqual` and `isIdentical` as the arrays were now being recreated in the order of the keys passed to the `$keysToBeConsidered` parameter.

This is not problematic for the `assertArrayIsEqualToArrayOnlyConsideringListOfKeys()` assertion as the array order is not relevant there.

However, it is problematic for the `assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys()` assertion, where the array order is relevant.

This commit fixes it.

Includes unit test safeguarding the fix.

And while the `assertArrayIs*ToArrayIgnoringListOfKeys()` assertions are not affected, I've also included a unit test for the issue for those assertions, just to be on the safe side.
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.95%. Comparing base (dcb95b9) to head (ffbc040).
Report is 1 commits behind head on 11.0.

Additional details and impacted files
@@             Coverage Diff              @@
##               11.0    #5729      +/-   ##
============================================
- Coverage     89.95%   89.95%   -0.01%     
+ Complexity     6464     6460       -4     
============================================
  Files           683      683              
  Lines         19591    19586       -5     
============================================
- Hits          17624    17619       -5     
  Misses         1967     1967              

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

@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/assertion Issues related to assertions and expectations labels Mar 10, 2024
@sebastianbergmann sebastianbergmann merged commit a6eedd5 into sebastianbergmann:11.0 Mar 10, 2024
@sebastianbergmann sebastianbergmann changed the title assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys(): bug fix - array order not correctly handled assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() does not correctly handle array order Mar 10, 2024
@jrfnl jrfnl deleted the feature/assertarrayidentical-bugfix branch March 10, 2024 16:43
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 18, 2026
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/bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants