Better respect PHP native array key handling for assertArrayIs*ToArrayOnlyConsideringListOfKeys()
#5716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #5600
As things are, arrays in PHP can have either integer or string keys. Depending on the key input, PHP does some type juggling magic though, like auto-converting purely integer string keys to integers and flooring floating point keys to integers.
While experienced devs will know this pitfall, less experienced devs (who also write tests) may not be as aware and may provide the keys in
$keysToBeConsidered
the same way as the original array was defined, not realizing that the type of some of the keys will have auto-magically been changed by PHP.The code in the new
assertArrayIs*ToArrayOnlyConsideringListOfKeys()
assertions, with its use of strictin_array()
did not respect the key juggling PHP does, while the code for theassertArrayIs*ToArrayIgnoringListOfKeys
assertions did (asunset()
- andisset()
for that matter - will do the same type juggling for the array keys).This commit adjusts the code for the
assertArrayIs*ToArrayOnlyConsideringListOfKeys()
assertions to handle arrays keys passed in$keysToBeConsidered
consistently in the same way PHP itself would do.Includes tests.
Includes tests for the same for the
assertArrayIs*ToArrayIgnoringListOfKeys
assertions which were not affected by this bug.