Skip to content

PHPC-2791: Add tests for duplicate BSON keys - #2191

Merged
GromNaN merged 3 commits into
mongodb:v2.5from
GromNaN:PHPC-2791
Oct 30, 2026
Merged

GromNaN merged 3 commits into
mongodb:v2.5from
GromNaN:PHPC-2791

Conversation

@GromNaN

@GromNaN GromNaN commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Add tests that document how the driver handles BSON documents with duplicate keys, following the prose tests of the BSON corpus spec:

  • 2.1 Test encoding (tests/bson/bson-document-duplicate-keys-001.phpt): PHPC does not expose a BSON builder API, and PHP collapses duplicate keys in array literals, so Document::fromPHP() keeps only the last value.
  • 2.2 Test decoding (tests/bson/bson-document-duplicate-keys-002.phpt): iteration returns both elements, get() and offsetGet() return the first value, toPHP() returns the last value, and Extended JSON keeps both keys.
  • 2.3 Test round-trip (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.
  • 2.4 Test parsing Extended JSON (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_KEYS flag added in CDRIVER-6492 is not exposed. PackedArray with duplicate indexes is already covered by bson-packedarray-get-005.phpt.

The API documentation on php.net is updated in php/doc-extensions#50

Jira: PHPC-2791

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 GromNaN added the tidy a change not worth a release (e.g. coding standards, CI, typos) label Oct 23, 2026
@GromNaN
GromNaN marked this pull request as ready for review October 23, 2026 17:25
@GromNaN
GromNaN requested a review from a team as a code owner October 23, 2026 17:26
@GromNaN
GromNaN requested review from paulinevos and a balanced review from Copilot and removed request for a team October 23, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Copilot AI balanced review requested due to automatic review settings October 26, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are limited to focused tests that match existing behavior, with no blocking issues identified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@GromNaN
GromNaN enabled auto-merge (squash) October 26, 2026 20:33
@GromNaN
GromNaN merged commit 47b2ca5 into mongodb:v2.5 Oct 30, 2026
47 checks passed
This was referenced Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tidy a change not worth a release (e.g. coding standards, CI, typos)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants