Skip to content

Commit 592b0a0

Browse files
authored
PHPLIB-1384: Use default value in Query::exists() (mongodb#60)
* PHPLIB-1384: Use default value in Query::exists() * Remove default value from exists() calls
1 parent 214baf1 commit 592b0a0

File tree

8 files changed

+39
-9
lines changed

8 files changed

+39
-9
lines changed

generator/config/query/exists.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ arguments:
1111
name: exists
1212
type:
1313
- bool
14+
default: true
1415
tests:
1516
-
1617
name: 'Exists and Not Equal To'
@@ -29,3 +30,10 @@ tests:
2930
$match:
3031
qty:
3132
$exists: true
33+
-
34+
name: 'Missing Field'
35+
pipeline:
36+
-
37+
$match:
38+
qty:
39+
$exists: false

src/Builder/Query/ExistsOperator.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Query/FactoryTrait.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/Query/AndOperatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testANDQueriesWithMultipleExpressionsSpecifyingTheSameField(): v
2323
price: Query::ne(1.99),
2424
),
2525
Query::query(
26-
price: Query::exists(true),
26+
price: Query::exists(),
2727
),
2828
),
2929
),

tests/Builder/Query/ExistsOperatorTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testExistsAndNotEqualTo(): void
1919
$pipeline = new Pipeline(
2020
Stage::match(
2121
qty: [
22-
Query::exists(true),
22+
Query::exists(),
2323
Query::nin([5, 15]),
2424
],
2525
),
@@ -28,13 +28,22 @@ public function testExistsAndNotEqualTo(): void
2828
$this->assertSamePipeline(Pipelines::ExistsExistsAndNotEqualTo, $pipeline);
2929
}
3030

31+
public function testMissingField(): void
32+
{
33+
$pipeline = new Pipeline(
34+
Stage::match(
35+
qty: Query::exists(false),
36+
),
37+
);
38+
39+
$this->assertSamePipeline(Pipelines::ExistsMissingField, $pipeline);
40+
}
41+
3142
public function testNullValues(): void
3243
{
3344
$pipeline = new Pipeline(
3445
Stage::match(
35-
qty: [
36-
Query::exists(true),
37-
],
46+
qty: Query::exists(),
3847
),
3948
);
4049

tests/Builder/Query/Pipelines.php

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

tests/Builder/Stage/CurrentOpStageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testInactiveSessions(): void
2323
),
2424
Stage::match(
2525
active: false,
26-
transaction: Query::exists(true),
26+
transaction: Query::exists(),
2727
),
2828
);
2929

tests/Builder/Stage/FacetStageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testExample(): void
4040
),
4141
categorizedByPrice: new Pipeline(
4242
Stage::match(
43-
price: Query::exists(true),
43+
price: Query::exists(),
4444
),
4545
Stage::bucket(
4646
groupBy: Expression::numberFieldPath('price'),

0 commit comments

Comments
 (0)