Add numeric tolerance and JSON matching assertions - #26
Merged
Merged
Conversation
isCloseTo() defaults to PHP_FLOAT_EPSILON: enough for float arithmetic noise, too small to hide a wrong value.
It is PHP 8.3+, while the package supports 8.1.
Matching by index meant an expected element had to sit first, which missed the case the assertion exists for. A missing key no longer reads as null either.
arrayContainsAssociativeArray() had the same two bugs; both share SubsetMatcher now.
k2gl
force-pushed
the
json-and-numeric-assertions
branch
from
September 9, 2026 17:52
728caf6 to
c73d183
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Floats and JSON responses were the two things you still had to leave the fluent chain for — decoding a body by hand, or dropping down to assertEqualsWithDelta.
The subset matching turned out to be the interesting part. Reusing the old array helper made list indexes behave like object keys, so containsJson(['items' => [['id' => 2]]]) missed anything that was not the first element. Lists are matched by membership now, and arrayContainsAssociativeArray() moved onto the same rule — which also means an expected null stops passing against a document that has no such key, so tests that were asserting nothing will go red.