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

PHPLIB-1345 Add tests on Boolean Expression Operators #27

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions generator/config/expression/and.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ arguments:
- resolvesToString
- resolvesToNull
variadic: array
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/#example'
pipeline:
-
$project:
item: 1
qty: 1
result:
$and:
-
$gt:
- '$qty'
- 100
-
$lt:
- '$qty'
- 250
16 changes: 15 additions & 1 deletion generator/config/expression/not.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: $not
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/'
type:
- resolvesToBool
encode: single
encode: array
description: |
Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression.
arguments:
Expand All @@ -12,3 +12,17 @@ arguments:
type:
- expression
- resolvesToBool
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/#example'
pipeline:
-
$project:
item: 1
result:
$not:
-
$gt:
- '$qty'
- 250
18 changes: 18 additions & 0 deletions generator/config/expression/or.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ arguments:
- expression
- resolvesToBool
variadic: array
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/#example'
pipeline:
-
$project:
item: 1
result:
$or:
-
$gt:
- '$qty'
- 250
-
$lt:
- '$qty'
- 200
2 changes: 1 addition & 1 deletion src/Builder/Expression/NotOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions tests/Builder/Expression/AndOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $and expression
*/
class AndOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
item: 1,
qty: 1,
result: Expression::and(
Expression::gt(
Expression::numberFieldPath('qty'),
100,
),
Expression::lt(
Expression::numberFieldPath('qty'),
250,
),
),
),
);

$this->assertSamePipeline(Pipelines::AndExample, $pipeline);
}
}
33 changes: 33 additions & 0 deletions tests/Builder/Expression/NotOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $not expression
*/
class NotOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
item: 1,
result: Expression::not(
Expression::gt(
Expression::numberFieldPath('qty'),
250,
),
),
),
);

$this->assertSamePipeline(Pipelines::NotExample, $pipeline);
}
}
37 changes: 37 additions & 0 deletions tests/Builder/Expression/OrOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $or expression
*/
class OrOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
item: 1,
result: Expression::or(
Expression::gt(
Expression::numberFieldPath('qty'),
250,
),
Expression::lt(
Expression::numberFieldPath('qty'),
200,
),
),
),
);

$this->assertSamePipeline(Pipelines::OrExample, $pipeline);
}
}
106 changes: 106 additions & 0 deletions tests/Builder/Expression/Pipelines.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.