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

Commit cd27d8d

Browse files
authored
PHPLIB-1345 Add tests on Boolean Expression Operators (#27)
1 parent 7b3e2ca commit cd27d8d

File tree

8 files changed

+267
-2
lines changed

8 files changed

+267
-2
lines changed

generator/config/expression/and.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ arguments:
1616
- resolvesToString
1717
- resolvesToNull
1818
variadic: array
19+
tests:
20+
-
21+
name: 'Example'
22+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/#example'
23+
pipeline:
24+
-
25+
$project:
26+
item: 1
27+
qty: 1
28+
result:
29+
$and:
30+
-
31+
$gt:
32+
- '$qty'
33+
- 100
34+
-
35+
$lt:
36+
- '$qty'
37+
- 250

generator/config/expression/not.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: $not
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/'
44
type:
55
- resolvesToBool
6-
encode: single
6+
encode: array
77
description: |
88
Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression.
99
arguments:
@@ -12,3 +12,17 @@ arguments:
1212
type:
1313
- expression
1414
- resolvesToBool
15+
tests:
16+
-
17+
name: 'Example'
18+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/#example'
19+
pipeline:
20+
-
21+
$project:
22+
item: 1
23+
result:
24+
$not:
25+
-
26+
$gt:
27+
- '$qty'
28+
- 250

generator/config/expression/or.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,21 @@ arguments:
1313
- expression
1414
- resolvesToBool
1515
variadic: array
16+
tests:
17+
-
18+
name: 'Example'
19+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/#example'
20+
pipeline:
21+
-
22+
$project:
23+
item: 1
24+
result:
25+
$or:
26+
-
27+
$gt:
28+
- '$qty'
29+
- 250
30+
-
31+
$lt:
32+
- '$qty'
33+
- 200

src/Builder/Expression/NotOperator.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.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Expression;
6+
7+
use MongoDB\Builder\Expression;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Stage;
10+
use MongoDB\Tests\Builder\PipelineTestCase;
11+
12+
/**
13+
* Test $and expression
14+
*/
15+
class AndOperatorTest extends PipelineTestCase
16+
{
17+
public function testExample(): void
18+
{
19+
$pipeline = new Pipeline(
20+
Stage::project(
21+
item: 1,
22+
qty: 1,
23+
result: Expression::and(
24+
Expression::gt(
25+
Expression::numberFieldPath('qty'),
26+
100,
27+
),
28+
Expression::lt(
29+
Expression::numberFieldPath('qty'),
30+
250,
31+
),
32+
),
33+
),
34+
);
35+
36+
$this->assertSamePipeline(Pipelines::AndExample, $pipeline);
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Expression;
6+
7+
use MongoDB\Builder\Expression;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Stage;
10+
use MongoDB\Tests\Builder\PipelineTestCase;
11+
12+
/**
13+
* Test $not expression
14+
*/
15+
class NotOperatorTest extends PipelineTestCase
16+
{
17+
public function testExample(): void
18+
{
19+
$pipeline = new Pipeline(
20+
Stage::project(
21+
item: 1,
22+
result: Expression::not(
23+
Expression::gt(
24+
Expression::numberFieldPath('qty'),
25+
250,
26+
),
27+
),
28+
),
29+
);
30+
31+
$this->assertSamePipeline(Pipelines::NotExample, $pipeline);
32+
}
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Expression;
6+
7+
use MongoDB\Builder\Expression;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Stage;
10+
use MongoDB\Tests\Builder\PipelineTestCase;
11+
12+
/**
13+
* Test $or expression
14+
*/
15+
class OrOperatorTest extends PipelineTestCase
16+
{
17+
public function testExample(): void
18+
{
19+
$pipeline = new Pipeline(
20+
Stage::project(
21+
item: 1,
22+
result: Expression::or(
23+
Expression::gt(
24+
Expression::numberFieldPath('qty'),
25+
250,
26+
),
27+
Expression::lt(
28+
Expression::numberFieldPath('qty'),
29+
200,
30+
),
31+
),
32+
),
33+
);
34+
35+
$this->assertSamePipeline(Pipelines::OrExample, $pipeline);
36+
}
37+
}

tests/Builder/Expression/Pipelines.php

Lines changed: 106 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)