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

Commit 7b3e2ca

Browse files
authored
PHPLIB-1344 Add tests on Bitwise Operators (#26)
1 parent 5e8b98a commit 7b3e2ca

File tree

9 files changed

+332
-0
lines changed

9 files changed

+332
-0
lines changed

generator/config/expression/bitAnd.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,24 @@ arguments:
1515
- resolvesToInt
1616
- resolvesToLong
1717
variadic: array
18+
tests:
19+
-
20+
name: 'Bitwise AND with Two Integers'
21+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-two-integers'
22+
pipeline:
23+
-
24+
$project:
25+
result:
26+
$bitAnd:
27+
- '$a'
28+
- '$b'
29+
-
30+
name: 'Bitwise AND with a Long and Integer'
31+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-a-long-and-integer'
32+
pipeline:
33+
-
34+
$project:
35+
result:
36+
$bitAnd:
37+
- '$a'
38+
- { "$numberLong": "63" }

generator/config/expression/bitNot.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ arguments:
1414
type:
1515
- resolvesToInt
1616
- resolvesToLong
17+
tests:
18+
-
19+
name: 'Example'
20+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/#example'
21+
pipeline:
22+
-
23+
$project:
24+
result:
25+
$bitNot: '$a'

generator/config/expression/bitOr.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,24 @@ arguments:
1515
- resolvesToInt
1616
- resolvesToLong
1717
variadic: array
18+
tests:
19+
-
20+
name: 'Bitwise OR with Two Integers'
21+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-two-integers'
22+
pipeline:
23+
-
24+
$project:
25+
result:
26+
$bitOr:
27+
- '$a'
28+
- '$b'
29+
-
30+
name: 'Bitwise OR with a Long and Integer'
31+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-a-long-and-integer'
32+
pipeline:
33+
-
34+
$project:
35+
result:
36+
$bitOr:
37+
- '$a'
38+
- { "$numberLong": "63" }

generator/config/expression/bitXor.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ arguments:
1515
- resolvesToInt
1616
- resolvesToLong
1717
variadic: array
18+
tests:
19+
-
20+
name: 'Example'
21+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/#example'
22+
pipeline:
23+
-
24+
$project:
25+
result:
26+
$bitXor:
27+
- '$a'
28+
- '$b'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Expression;
6+
7+
use MongoDB\BSON\Int64;
8+
use MongoDB\Builder\Expression;
9+
use MongoDB\Builder\Pipeline;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
/**
14+
* Test $bitAnd expression
15+
*/
16+
class BitAndOperatorTest extends PipelineTestCase
17+
{
18+
public function testBitwiseANDWithALongAndInteger(): void
19+
{
20+
$pipeline = new Pipeline(
21+
Stage::project(
22+
result: Expression::bitAnd(
23+
Expression::longFieldPath('a'),
24+
new Int64('63'),
25+
),
26+
),
27+
);
28+
29+
$this->assertSamePipeline(Pipelines::BitAndBitwiseANDWithALongAndInteger, $pipeline);
30+
}
31+
32+
public function testBitwiseANDWithTwoIntegers(): void
33+
{
34+
$pipeline = new Pipeline(
35+
Stage::project(
36+
result: Expression::bitAnd(
37+
Expression::intFieldPath('a'),
38+
Expression::intFieldPath('b'),
39+
),
40+
),
41+
);
42+
43+
$this->assertSamePipeline(Pipelines::BitAndBitwiseANDWithTwoIntegers, $pipeline);
44+
}
45+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 $bitNot expression
14+
*/
15+
class BitNotOperatorTest extends PipelineTestCase
16+
{
17+
public function testExample(): void
18+
{
19+
$pipeline = new Pipeline(
20+
Stage::project(
21+
result: Expression::bitNot(
22+
Expression::longFieldPath('a'),
23+
),
24+
),
25+
);
26+
27+
$this->assertSamePipeline(Pipelines::BitNotExample, $pipeline);
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Expression;
6+
7+
use MongoDB\BSON\Int64;
8+
use MongoDB\Builder\Expression;
9+
use MongoDB\Builder\Pipeline;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
/**
14+
* Test $bitOr expression
15+
*/
16+
class BitOrOperatorTest extends PipelineTestCase
17+
{
18+
public function testBitwiseORWithALongAndInteger(): void
19+
{
20+
$pipeline = new Pipeline(
21+
Stage::project(
22+
result: Expression::bitOr(
23+
Expression::longFieldPath('a'),
24+
new Int64('63'),
25+
),
26+
),
27+
);
28+
29+
$this->assertSamePipeline(Pipelines::BitOrBitwiseORWithALongAndInteger, $pipeline);
30+
}
31+
32+
public function testBitwiseORWithTwoIntegers(): void
33+
{
34+
$pipeline = new Pipeline(
35+
Stage::project(
36+
result: Expression::bitOr(
37+
Expression::intFieldPath('a'),
38+
Expression::intFieldPath('b'),
39+
),
40+
),
41+
);
42+
43+
$this->assertSamePipeline(Pipelines::BitOrBitwiseORWithTwoIntegers, $pipeline);
44+
}
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 $bitXor expression
14+
*/
15+
class BitXorOperatorTest extends PipelineTestCase
16+
{
17+
public function testExample(): void
18+
{
19+
$pipeline = new Pipeline(
20+
Stage::project(
21+
result: Expression::bitXor(
22+
Expression::longFieldPath('a'),
23+
Expression::longFieldPath('b'),
24+
),
25+
),
26+
);
27+
28+
$this->assertSamePipeline(Pipelines::BitXorExample, $pipeline);
29+
}
30+
}

tests/Builder/Expression/Pipelines.php

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