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

PHPLIB-1339 Add tests on Bitwise Query Operators #37

Merged
merged 5 commits into from
Jan 22, 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
23 changes: 23 additions & 0 deletions generator/config/query/bitsAllClear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ arguments:
- int
- binData
- array # of int
tests:
-
name: 'Bit Position Array'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array'
pipeline:
-
$match:
a:
$bitsAllClear: [1, 5]
-
name: 'Integer Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask'
pipeline:
- $match:
a:
$bitsAllClear: 35
-
name: 'BinData Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask'
pipeline:
- $match:
a:
$bitsAllClear: !binary 'IA=='
23 changes: 23 additions & 0 deletions generator/config/query/bitsAllSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ arguments:
- int
- binData
- array # of int
tests:
-
name: 'Bit Position Array'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array'
pipeline:
-
$match:
a:
$bitsAllSet: [1, 5]
-
name: 'Integer Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask'
pipeline:
- $match:
a:
$bitsAllSet: 50
-
name: 'BinData Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask'
pipeline:
- $match:
a:
$bitsAllSet: !binary 'MA=='
23 changes: 23 additions & 0 deletions generator/config/query/bitsAnyClear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ arguments:
- int
- binData
- array # of int
tests:
-
name: 'Bit Position Array'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array'
pipeline:
-
$match:
a:
$bitsAnyClear: [1, 5]
-
name: 'Integer Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask'
pipeline:
- $match:
a:
$bitsAnyClear: 35
-
name: 'BinData Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask'
pipeline:
- $match:
a:
$bitsAnyClear: !binary 'MA=='
23 changes: 23 additions & 0 deletions generator/config/query/bitsAnySet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ arguments:
- int
- binData
- array # of int
tests:
-
name: 'Bit Position Array'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array'
pipeline:
-
$match:
a:
$bitsAnySet: [1, 5]
-
name: 'Integer Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask'
pipeline:
- $match:
a:
$bitsAnySet: 35
-
name: 'BinData Bitmask'
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask'
pipeline:
- $match:
a:
$bitsAnySet: !binary 'MA=='
54 changes: 54 additions & 0 deletions tests/Builder/Query/BitsAllClearOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Query;

use MongoDB\BSON\Binary;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Query;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

use function base64_decode;

/**
* Test $bitsAllClear query
*/
class BitsAllClearOperatorTest extends PipelineTestCase
{
public function testBinDataBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllClear(
new Binary(base64_decode('IA==')),
),
),
);

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

public function testBitPositionArray(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllClear([1, 5]),
),
);

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

public function testIntegerBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllClear(35),
),
);

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

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Query;

use MongoDB\BSON\Binary;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Query;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

use function base64_decode;

/**
* Test $bitsAllSet query
*/
class BitsAllSetOperatorTest extends PipelineTestCase
{
public function testBinDataBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllSet(
new Binary(base64_decode('MA==')),
),
),
);

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

public function testBitPositionArray(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllSet([1, 5]),
),
);

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

public function testIntegerBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAllSet(50),
),
);

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

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Query;

use MongoDB\BSON\Binary;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Query;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

use function base64_decode;

/**
* Test $bitsAnyClear query
*/
class BitsAnyClearOperatorTest extends PipelineTestCase
{
public function testBinDataBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnyClear(
new Binary(base64_decode('MA==')),
),
),
);

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

public function testBitPositionArray(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnyClear([1, 5]),
),
);

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

public function testIntegerBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnyClear(35),
),
);

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

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Query;

use MongoDB\BSON\Binary;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Query;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

use function base64_decode;

/**
* Test $bitsAnySet query
*/
class BitsAnySetOperatorTest extends PipelineTestCase
{
public function testBinDataBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnySet(
new Binary(base64_decode('MA==')),
),
),
);

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

public function testBitPositionArray(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnySet([1, 5]),
),
);

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

public function testIntegerBitmask(): void
{
$pipeline = new Pipeline(
Stage::match(
a: Query::bitsAnySet(35),
),
);

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