-
Notifications
You must be signed in to change notification settings - Fork 264
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
Conversation
73540a2
to
093ebf2
Compare
@@ -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'); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
093ebf2
to
bf18cf2
Compare
Note: I'll rebase and merge this after mongodb/specifications#1706 is closed. |
bf18cf2
to
8e405c2
Compare
8e405c2
to
2be678e
Compare
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.