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

PHPLIB-1344 Add tests on Bitwise Operators #26

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
21 changes: 21 additions & 0 deletions generator/config/expression/bitAnd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ arguments:
- resolvesToInt
- resolvesToLong
variadic: array
tests:
-
name: 'Bitwise AND with Two Integers'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-two-integers'
pipeline:
-
$project:
result:
$bitAnd:
- '$a'
- '$b'
-
name: 'Bitwise AND with a Long and Integer'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-a-long-and-integer'
pipeline:
-
$project:
result:
$bitAnd:
- '$a'
- { "$numberLong": "63" }
9 changes: 9 additions & 0 deletions generator/config/expression/bitNot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ arguments:
type:
- resolvesToInt
- resolvesToLong
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/#example'
pipeline:
-
$project:
result:
$bitNot: '$a'
21 changes: 21 additions & 0 deletions generator/config/expression/bitOr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ arguments:
- resolvesToInt
- resolvesToLong
variadic: array
tests:
-
name: 'Bitwise OR with Two Integers'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-two-integers'
pipeline:
-
$project:
result:
$bitOr:
- '$a'
- '$b'
-
name: 'Bitwise OR with a Long and Integer'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-a-long-and-integer'
pipeline:
-
$project:
result:
$bitOr:
- '$a'
- { "$numberLong": "63" }
11 changes: 11 additions & 0 deletions generator/config/expression/bitXor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ arguments:
- resolvesToInt
- resolvesToLong
variadic: array
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/#example'
pipeline:
-
$project:
result:
$bitXor:
- '$a'
- '$b'
45 changes: 45 additions & 0 deletions tests/Builder/Expression/BitAndOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

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

/**
* Test $bitAnd expression
*/
class BitAndOperatorTest extends PipelineTestCase
{
public function testBitwiseANDWithALongAndInteger(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitAnd(
Expression::longFieldPath('a'),
new Int64('63'),
),
),
);

$this->assertSamePipeline(Pipelines::BitAndBitwiseANDWithALongAndInteger, $pipeline);
}

public function testBitwiseANDWithTwoIntegers(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitAnd(
Expression::intFieldPath('a'),
Expression::intFieldPath('b'),
),
),
);

$this->assertSamePipeline(Pipelines::BitAndBitwiseANDWithTwoIntegers, $pipeline);
}
}
29 changes: 29 additions & 0 deletions tests/Builder/Expression/BitNotOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 $bitNot expression
*/
class BitNotOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitNot(
Expression::longFieldPath('a'),
),
),
);

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

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

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

/**
* Test $bitOr expression
*/
class BitOrOperatorTest extends PipelineTestCase
{
public function testBitwiseORWithALongAndInteger(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitOr(
Expression::longFieldPath('a'),
new Int64('63'),
),
),
);

$this->assertSamePipeline(Pipelines::BitOrBitwiseORWithALongAndInteger, $pipeline);
}

public function testBitwiseORWithTwoIntegers(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitOr(
Expression::intFieldPath('a'),
Expression::intFieldPath('b'),
),
),
);

$this->assertSamePipeline(Pipelines::BitOrBitwiseORWithTwoIntegers, $pipeline);
}
}
30 changes: 30 additions & 0 deletions tests/Builder/Expression/BitXorOperatorTest.php
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 $bitXor expression
*/
class BitXorOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
result: Expression::bitXor(
Expression::longFieldPath('a'),
Expression::longFieldPath('b'),
),
),
);

$this->assertSamePipeline(Pipelines::BitXorExample, $pipeline);
}
}
121 changes: 121 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.