Skip to content

Commit d6f289e

Browse files
committed
Add prose tests and remove POC test
1 parent 8d0b961 commit d6f289e

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

tests/bson-binary-vector/poc-valid-001.phpt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Binary vector: Encoding PackedBit vector with non-zero, padded bits fails
3+
--DESCRIPTION--
4+
Binary vector prose test #1
5+
https://github.com/mongodb/specifications/blob/master/source/bson-binary-vector/tests/README.md#prose-tests
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/basic.inc';
10+
11+
// PackedBit vector with padding:7 and non-zero bits is invalid
12+
13+
14+
/* PHPC does not allow constructing a PackedBit vector with non-zero, padded
15+
* bits. As a result, the corresponding decoding test (i.e. prose test #2)
16+
* cannot be implemented. */
17+
echo throws(function() {
18+
var_dump(new MongoDB\BSON\Binary("\x10\x07\xff", MongoDB\BSON\Binary::TYPE_VECTOR));
19+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
20+
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECT--
25+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
26+
Binary vector data is invalid
27+
===DONE===
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Binary vector: PackedBit vector comparisons
3+
--DESCRIPTION--
4+
Binary vector prose test #3
5+
https://github.com/mongodb/specifications/blob/master/source/bson-binary-vector/tests/README.md#prose-tests
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/basic.inc';
10+
11+
/* Although PHPC does not allow constructing a vector with non-zero, padded
12+
* bits, we can still test comparisons between two valid vector objects
13+
* constructed from raw data and a PHP array, respectively. */
14+
$b1 = new MongoDB\BSON\Binary("\x10\x07\x80", MongoDB\BSON\Binary::TYPE_VECTOR);
15+
16+
// PackedBit vector with padding:7 and all-zero bits (constructed from PHP array)
17+
$b2 = MongoDB\BSON\Binary::fromVector([1], MongoDB\BSON\VectorType::PackedBit);
18+
19+
var_dump($b1 == $b2);
20+
var_dump($b1->toArray() === $b2->toArray());
21+
22+
?>
23+
===DONE===
24+
<?php exit(0); ?>
25+
--EXPECT--
26+
bool(true)
27+
bool(true)
28+
===DONE===

0 commit comments

Comments
 (0)