Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1569: Implement $$matchAsDocument and $$matchAsRoot #1508

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Oct 30, 2024

https://jira.mongodb.org/browse/PHPLIB-1569
https://jira.mongodb.org/browse/PHPLIB-1577

POC for mongodb/specifications#1706

Includes an extra test for numeric comparisons, which can be removed when PHPLIB-1577 is addressed.

@jmikola jmikola requested a review from a team as a code owner October 30, 2024 17:55
@jmikola jmikola requested a review from GromNaN October 30, 2024 17:55
@alcaeus alcaeus closed this Oct 31, 2024
@alcaeus alcaeus reopened this Oct 31, 2024
@jmikola jmikola force-pushed the 1.x-phplib-1569 branch 2 times, most recently from 73540a2 to 093ebf2 Compare October 31, 2024 13:28
tests/UnifiedSpecTests/Constraint/Matches.php Show resolved Hide resolved
@@ -263,6 +268,35 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
return;
}

if ($name === '$$matchAsDocument') {
assertInstanceOf(BSONDocument::class, $operator['$$matchAsDocument'], '$$matchAsDocument requires a BSON document');
Copy link
Member

Choose a reason for hiding this comment

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

A MongoDB\Model\BSONDocument instance is expected because of the default typeMap of PHPLIB. Isn't there a risk that a test will change the typeMap and obtain a stdClass or array?

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally thought this has to do with the PHPLIB typeMap but forgot that it is actually due to the Matches::prepare() method, which is used to normalize both the expected and actual values.

}

if ($name === '$$matchAsRoot') {
$constraint = new Matches($operator['$$matchAsRoot'], $this->entityMap, allowExtraRootKeys: true);
Copy link
Member

Choose a reason for hiding this comment

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

Why allowExtraRootKeys is true for $$matchAsRoot and false for $$matchAsDocument?

Copy link
Member Author

Choose a reason for hiding this comment

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

Per the UTF spec, $$matchAsDocument does not allow extra keys in the decoded JSON document.

$$matchAsRoot only exists to enable "allow extra keys" behavior when matching.

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

LGTM.

@jmikola
Copy link
Member Author

jmikola commented Nov 4, 2024

Note: I'll rebase and merge this after mongodb/specifications#1706 is closed.

@jmikola jmikola merged commit 2bc2c91 into mongodb:v1.x Nov 6, 2024
31 checks passed
@jmikola jmikola deleted the 1.x-phplib-1569 branch November 6, 2024 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants