Skip to content

Commit 7c9a36a

Browse files
authored
PHPLIB-1339 Add tests on Bitwise Query Operators (mongodb#37)
Use the !binary yaml tag
1 parent 149dca6 commit 7c9a36a

File tree

9 files changed

+568
-0
lines changed

9 files changed

+568
-0
lines changed

generator/config/query/bitsAllClear.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ arguments:
1313
- int
1414
- binData
1515
- array # of int
16+
tests:
17+
-
18+
name: 'Bit Position Array'
19+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array'
20+
pipeline:
21+
-
22+
$match:
23+
a:
24+
$bitsAllClear: [1, 5]
25+
-
26+
name: 'Integer Bitmask'
27+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask'
28+
pipeline:
29+
- $match:
30+
a:
31+
$bitsAllClear: 35
32+
-
33+
name: 'BinData Bitmask'
34+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask'
35+
pipeline:
36+
- $match:
37+
a:
38+
$bitsAllClear: !binary 'IA=='

generator/config/query/bitsAllSet.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ arguments:
1313
- int
1414
- binData
1515
- array # of int
16+
tests:
17+
-
18+
name: 'Bit Position Array'
19+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array'
20+
pipeline:
21+
-
22+
$match:
23+
a:
24+
$bitsAllSet: [1, 5]
25+
-
26+
name: 'Integer Bitmask'
27+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask'
28+
pipeline:
29+
- $match:
30+
a:
31+
$bitsAllSet: 50
32+
-
33+
name: 'BinData Bitmask'
34+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask'
35+
pipeline:
36+
- $match:
37+
a:
38+
$bitsAllSet: !binary 'MA=='

generator/config/query/bitsAnyClear.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ arguments:
1313
- int
1414
- binData
1515
- array # of int
16+
tests:
17+
-
18+
name: 'Bit Position Array'
19+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array'
20+
pipeline:
21+
-
22+
$match:
23+
a:
24+
$bitsAnyClear: [1, 5]
25+
-
26+
name: 'Integer Bitmask'
27+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask'
28+
pipeline:
29+
- $match:
30+
a:
31+
$bitsAnyClear: 35
32+
-
33+
name: 'BinData Bitmask'
34+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask'
35+
pipeline:
36+
- $match:
37+
a:
38+
$bitsAnyClear: !binary 'MA=='

generator/config/query/bitsAnySet.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ arguments:
1313
- int
1414
- binData
1515
- array # of int
16+
tests:
17+
-
18+
name: 'Bit Position Array'
19+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array'
20+
pipeline:
21+
-
22+
$match:
23+
a:
24+
$bitsAnySet: [1, 5]
25+
-
26+
name: 'Integer Bitmask'
27+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask'
28+
pipeline:
29+
- $match:
30+
a:
31+
$bitsAnySet: 35
32+
-
33+
name: 'BinData Bitmask'
34+
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask'
35+
pipeline:
36+
- $match:
37+
a:
38+
$bitsAnySet: !binary 'MA=='
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Query;
6+
7+
use MongoDB\BSON\Binary;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Query;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
use function base64_decode;
14+
15+
/**
16+
* Test $bitsAllClear query
17+
*/
18+
class BitsAllClearOperatorTest extends PipelineTestCase
19+
{
20+
public function testBinDataBitmask(): void
21+
{
22+
$pipeline = new Pipeline(
23+
Stage::match(
24+
a: Query::bitsAllClear(
25+
new Binary(base64_decode('IA==')),
26+
),
27+
),
28+
);
29+
30+
$this->assertSamePipeline(Pipelines::BitsAllClearBinDataBitmask, $pipeline);
31+
}
32+
33+
public function testBitPositionArray(): void
34+
{
35+
$pipeline = new Pipeline(
36+
Stage::match(
37+
a: Query::bitsAllClear([1, 5]),
38+
),
39+
);
40+
41+
$this->assertSamePipeline(Pipelines::BitsAllClearBitPositionArray, $pipeline);
42+
}
43+
44+
public function testIntegerBitmask(): void
45+
{
46+
$pipeline = new Pipeline(
47+
Stage::match(
48+
a: Query::bitsAllClear(35),
49+
),
50+
);
51+
52+
$this->assertSamePipeline(Pipelines::BitsAllClearIntegerBitmask, $pipeline);
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Query;
6+
7+
use MongoDB\BSON\Binary;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Query;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
use function base64_decode;
14+
15+
/**
16+
* Test $bitsAllSet query
17+
*/
18+
class BitsAllSetOperatorTest extends PipelineTestCase
19+
{
20+
public function testBinDataBitmask(): void
21+
{
22+
$pipeline = new Pipeline(
23+
Stage::match(
24+
a: Query::bitsAllSet(
25+
new Binary(base64_decode('MA==')),
26+
),
27+
),
28+
);
29+
30+
$this->assertSamePipeline(Pipelines::BitsAllSetBinDataBitmask, $pipeline);
31+
}
32+
33+
public function testBitPositionArray(): void
34+
{
35+
$pipeline = new Pipeline(
36+
Stage::match(
37+
a: Query::bitsAllSet([1, 5]),
38+
),
39+
);
40+
41+
$this->assertSamePipeline(Pipelines::BitsAllSetBitPositionArray, $pipeline);
42+
}
43+
44+
public function testIntegerBitmask(): void
45+
{
46+
$pipeline = new Pipeline(
47+
Stage::match(
48+
a: Query::bitsAllSet(50),
49+
),
50+
);
51+
52+
$this->assertSamePipeline(Pipelines::BitsAllSetIntegerBitmask, $pipeline);
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Query;
6+
7+
use MongoDB\BSON\Binary;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Query;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
use function base64_decode;
14+
15+
/**
16+
* Test $bitsAnyClear query
17+
*/
18+
class BitsAnyClearOperatorTest extends PipelineTestCase
19+
{
20+
public function testBinDataBitmask(): void
21+
{
22+
$pipeline = new Pipeline(
23+
Stage::match(
24+
a: Query::bitsAnyClear(
25+
new Binary(base64_decode('MA==')),
26+
),
27+
),
28+
);
29+
30+
$this->assertSamePipeline(Pipelines::BitsAnyClearBinDataBitmask, $pipeline);
31+
}
32+
33+
public function testBitPositionArray(): void
34+
{
35+
$pipeline = new Pipeline(
36+
Stage::match(
37+
a: Query::bitsAnyClear([1, 5]),
38+
),
39+
);
40+
41+
$this->assertSamePipeline(Pipelines::BitsAnyClearBitPositionArray, $pipeline);
42+
}
43+
44+
public function testIntegerBitmask(): void
45+
{
46+
$pipeline = new Pipeline(
47+
Stage::match(
48+
a: Query::bitsAnyClear(35),
49+
),
50+
);
51+
52+
$this->assertSamePipeline(Pipelines::BitsAnyClearIntegerBitmask, $pipeline);
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Tests\Builder\Query;
6+
7+
use MongoDB\BSON\Binary;
8+
use MongoDB\Builder\Pipeline;
9+
use MongoDB\Builder\Query;
10+
use MongoDB\Builder\Stage;
11+
use MongoDB\Tests\Builder\PipelineTestCase;
12+
13+
use function base64_decode;
14+
15+
/**
16+
* Test $bitsAnySet query
17+
*/
18+
class BitsAnySetOperatorTest extends PipelineTestCase
19+
{
20+
public function testBinDataBitmask(): void
21+
{
22+
$pipeline = new Pipeline(
23+
Stage::match(
24+
a: Query::bitsAnySet(
25+
new Binary(base64_decode('MA==')),
26+
),
27+
),
28+
);
29+
30+
$this->assertSamePipeline(Pipelines::BitsAnySetBinDataBitmask, $pipeline);
31+
}
32+
33+
public function testBitPositionArray(): void
34+
{
35+
$pipeline = new Pipeline(
36+
Stage::match(
37+
a: Query::bitsAnySet([1, 5]),
38+
),
39+
);
40+
41+
$this->assertSamePipeline(Pipelines::BitsAnySetBitPositionArray, $pipeline);
42+
}
43+
44+
public function testIntegerBitmask(): void
45+
{
46+
$pipeline = new Pipeline(
47+
Stage::match(
48+
a: Query::bitsAnySet(35),
49+
),
50+
);
51+
52+
$this->assertSamePipeline(Pipelines::BitsAnySetIntegerBitmask, $pipeline);
53+
}
54+
}

0 commit comments

Comments
 (0)