This repository was archived by the owner on Feb 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1342 Add tests on Arithmetic Expression Operators #52
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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 $abs expression | ||
*/ | ||
class AbsOperatorTest extends PipelineTestCase | ||
{ | ||
public function testExample(): void | ||
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
delta: Expression::abs( | ||
Expression::subtract( | ||
Expression::numberFieldPath('startTemp'), | ||
Expression::numberFieldPath('endTemp'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
$this->assertSamePipeline(Pipelines::AbsExample, $pipeline); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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 $ceil expression | ||
*/ | ||
class CeilOperatorTest extends PipelineTestCase | ||
{ | ||
public function testExample(): void | ||
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
value: 1, | ||
ceilingValue: Expression::ceil( | ||
Expression::numberFieldPath('value'), | ||
), | ||
), | ||
); | ||
|
||
$this->assertSamePipeline(Pipelines::CeilExample, $pipeline); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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 $divide expression | ||
*/ | ||
class DivideOperatorTest extends PipelineTestCase | ||
{ | ||
public function testExample(): void | ||
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
city: 1, | ||
workdays: Expression::divide( | ||
Expression::numberFieldPath('hours'), | ||
8, | ||
), | ||
), | ||
); | ||
|
||
$this->assertSamePipeline(Pipelines::DivideExample, $pipeline); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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 $exp expression | ||
*/ | ||
class ExpOperatorTest extends PipelineTestCase | ||
{ | ||
public function testExample(): void | ||
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
effectiveRate: Expression::subtract( | ||
Expression::exp( | ||
Expression::numberFieldPath('interestRate'), | ||
), | ||
1, | ||
), | ||
), | ||
); | ||
|
||
$this->assertSamePipeline(Pipelines::ExpExample, $pipeline); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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 $floor expression | ||
*/ | ||
class FloorOperatorTest extends PipelineTestCase | ||
{ | ||
public function testExample(): void | ||
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
value: 1, | ||
floorValue: Expression::floor( | ||
Expression::numberFieldPath('value'), | ||
), | ||
), | ||
); | ||
|
||
$this->assertSamePipeline(Pipelines::FloorExample, $pipeline); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I've checked the result is the same if the value is in an array or a single value
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.
Is this because StdDevPopOperator encodes as a single element, which utilizes its only
$expression
property (a list)? I suppose$expressions
would be a more descriptive name for the property but I realize the class is auto-generated and derived from the name of the variadic arg itself.In any event, I think it makes sense to capture this explanation in a YAML comment here to explain exactly why you're changing the expected pipeline.
IIRC, this kind of thing came up in previous PRs, since there are other operators that omit logic to encode using the "short" form.
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.
The argument is variadic so we always get an array. That's one reason why I made an accumulator operator distrinct from the expression operator.
Comment added.