Repository navigation
Conversation
Document how Document handles duplicate keys when decoding and when round-tripping, following the BSON corpus spec prose tests 2.2 and 2.3.
GromNaN
marked this pull request as ready for review
October 23, 2026 17:25
GromNaN
requested review from
paulinevos
and
a balanced review from Copilot
and removed request for
a team
October 23, 2026 17:26
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
These focused test-only additions have no identified blocking issues; the remaining expectation-portability concern is non-blocking.
1 open issue
What changed in this PR
Adds regression tests documenting how MongoDB\BSON\Document handles duplicate keys, aligned with the BSON corpus prose tests. No driver behavior changes.
Changes:
- Covers PHP encoding and BSON decoding, including iteration, lookup, and conversion behavior.
- Verifies duplicate-key preservation through raw BSON and Extended JSON round-trips.
- Confirms Extended JSON parsing preserves duplicate keys in order.
| File | Description |
|---|---|
| tests/bson/bson-document-duplicate-keys-004.phpt | Tests duplicate-key preservation during Extended JSON parsing. |
| tests/bson/bson-document-duplicate-keys-003.phpt | Tests BSON, Extended JSON, and PHP round-trips. |
| tests/bson/bson-document-duplicate-keys-002.phpt | Documents duplicate-key behavior across decoding APIs. |
| tests/bson/bson-document-duplicate-keys-001.phpt | Verifies PHP collapses duplicate keys before encoding. |
Review effort: Balanced
Comment on lines
+36
to
+49
| --EXPECT-- | ||
| Iteration returns both elements in order | ||
| string(3) "foo" | ||
| int(1) | ||
| string(3) "foo" | ||
| int(2) | ||
|
|
||
| get() and offsetGet() return the first value | ||
| int(1) | ||
| int(1) | ||
| bool(true) | ||
|
|
||
| toPHP() returns the last value | ||
| object(stdClass)#3 (1) { |
This branch has not been deployed
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.

Add tests that document how the driver handles BSON documents with duplicate keys, following the prose tests of the BSON corpus spec:
tests/bson/bson-document-duplicate-keys-001.phpt): PHPC does not expose a BSON builder API, and PHP collapses duplicate keys in array literals, soDocument::fromPHP()keeps only the last value.tests/bson/bson-document-duplicate-keys-002.phpt): iteration returns both elements,get()andoffsetGet()return the first value,toPHP()returns the last value, and Extended JSON keeps both keys.tests/bson/bson-document-duplicate-keys-003.phpt): raw BSON and the Extended JSON round-trip keep duplicates, the PHP round-trip keeps only the last value.tests/bson/bson-document-duplicate-keys-004.phpt):Document::fromJSON()keeps duplicate keys in order.No behavior change. The driver does not validate duplicate keys, so the
BSON_VALIDATE_DUPLICATE_KEYSflag added in CDRIVER-6492 is not exposed.PackedArraywith duplicate indexes is already covered bybson-packedarray-get-005.phpt.The API documentation on php.net is updated in php/doc-extensions#50
Jira: PHPC-2791