-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1271 Add tests from the documentation #6
Changes from all commits
372a051
74c8fdc
b47ad7e
c05fc2a
a3086a5
285973e
b75e59d
36cb967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,27 @@ arguments: | |
name: regex | ||
type: | ||
- regex | ||
|
||
tests: | ||
- | ||
name: 'Perform a LIKE Match' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-a-like-match' | ||
pipeline: | ||
- | ||
$match: | ||
sku: | ||
# Should be nested in $regex | ||
$regularExpression: | ||
pattern: '789$' | ||
options: '' | ||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
$json = <<<'JSON'
{
"foo": {
"$regex": {
"$regularExpression": {
"pattern": "789$",
"options": "i"
}
}
}
}
JSON;
$document = fromJSON($json);
// Fatal error: Uncaught MongoDB\Driver\Exception\UnexpectedValueException: Unexpected nested object value for "$regex" key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That exception originates from Also discussed in the Extended JSON spec: If you're using
And then it proceeds to give two examples. The first example resembles what you're trying to do here, where the That aside, is anything preventing you from using the following?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will result in The codec wraps the regex in the The expected query that I need to encode in Yaml/Json is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $query = (object) ['sku' => (object) ['$regex' => new MongoDB\BSON\Regex('789$', '')]];
$json = MongoDB\BSON\toJSON(MongoDB\BSON\fromPHP($x));
// { "sku" : { "$regex" : { "$regex" : "789$", "$options" : "" } } }
MongoDB\BSON\fromJSON($json);
// Warning: Uncaught MongoDB\Driver\Exception\UnexpectedValueException: Unexpected nested object value for "$regex" key in php shell code:1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue solved by comparing JSON: #13 |
||
- | ||
name: 'Perform Case-Insensitive Regular Expression Match' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match' | ||
pipeline: | ||
- | ||
$match: | ||
sku: | ||
# Should be nested in $regex | ||
$regularExpression: | ||
pattern: '^ABC' | ||
options: 'i' |
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.
Required to modify existing files with the generator.