Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 92ecc8f

Browse files
authored
PHPLIB-1352 Add tests on Object Expression Operators (#40)
1 parent 471e7f7 commit 92ecc8f

File tree

5 files changed

+504
-0
lines changed

5 files changed

+504
-0
lines changed

generator/config/expression/setField.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,81 @@ arguments:
2727
description: |
2828
The value that you want to assign to field. value can be any valid expression.
2929
Set to $$REMOVE to remove field from the input document.
30+
tests:
31+
-
32+
name: 'Add Fields that Contain Periods'
33+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-contain-periods--.-'
34+
pipeline:
35+
-
36+
$replaceWith:
37+
$setField:
38+
field: 'price.usd'
39+
input: '$$ROOT'
40+
value: '$price'
41+
-
42+
# $unset: 'price'
43+
$unset:
44+
- 'price'
45+
-
46+
name: 'Add Fields that Start with a Dollar Sign'
47+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-start-with-a-dollar-sign----'
48+
pipeline:
49+
-
50+
$replaceWith:
51+
$setField:
52+
field:
53+
$literal: '$price'
54+
input: '$$ROOT'
55+
value: '$price'
56+
-
57+
# $unset: 'price'
58+
$unset:
59+
- 'price'
60+
-
61+
name: 'Update Fields that Contain Periods'
62+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-contain-periods--.-'
63+
pipeline:
64+
-
65+
$match:
66+
_id: 1
67+
-
68+
$replaceWith:
69+
$setField:
70+
field: 'price.usd'
71+
input: '$$ROOT'
72+
value: 49.99
73+
-
74+
name: 'Update Fields that Start with a Dollar Sign'
75+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-start-with-a-dollar-sign----'
76+
pipeline:
77+
-
78+
$match:
79+
_id: 1
80+
-
81+
$replaceWith:
82+
$setField:
83+
field:
84+
$literal: '$price'
85+
input: '$$ROOT'
86+
value: 49.99
87+
-
88+
name: 'Remove Fields that Contain Periods'
89+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-contain-periods--.-'
90+
pipeline:
91+
-
92+
$replaceWith:
93+
$setField:
94+
field: 'price.usd'
95+
input: '$$ROOT'
96+
value: '$$REMOVE'
97+
-
98+
name: 'Remove Fields that Start with a Dollar Sign'
99+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-start-with-a-dollar-sign----'
100+
pipeline:
101+
-
102+
$replaceWith:
103+
$setField:
104+
field:
105+
$literal: '$price'
106+
input: '$$ROOT'
107+
value: '$$REMOVE'

generator/config/expression/unsetField.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,39 @@ arguments:
2020
- resolvesToObject
2121
description: |
2222
Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined.
23+
tests:
24+
-
25+
name: 'Remove Fields that Contain Periods'
26+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-contain-periods--.-'
27+
pipeline:
28+
-
29+
$replaceWith:
30+
$unsetField:
31+
field: 'price.usd'
32+
input: '$$ROOT'
33+
-
34+
name: 'Remove Fields that Start with a Dollar Sign'
35+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-start-with-a-dollar-sign----'
36+
pipeline:
37+
-
38+
$replaceWith:
39+
$unsetField:
40+
field:
41+
$literal: '$price'
42+
input: '$$ROOT'
43+
-
44+
name: 'Remove A Subfield'
45+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-a-subfield'
46+
pipeline:
47+
-
48+
$replaceWith:
49+
$setField:
50+
field: 'price'
51+
input: '$$ROOT'
52+
value:
53+
$unsetField:
54+
field: 'euro'
55+
input:
56+
# $getField: 'price'
57+
$getField:
58+
field: 'price'

tests/Builder/Expression/Pipelines.php

Lines changed: 214 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)