Skip to content

Commit 21fd5a6

Browse files
authored
PHPC-1942: BSON Binary subtype 0x07 (column) (#1281)
Defines new Binary::TYPE_COLUMN constant. BSON corpus spec tests synced with mongodb/specifications@b3b74c9
1 parent 8a4670b commit 21fd5a6

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

src/BSON/Binary.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) /* {{{ */
479479
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_UUID"), BSON_SUBTYPE_UUID);
480480
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_MD5"), BSON_SUBTYPE_MD5);
481481
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_ENCRYPTED"), BSON_SUBTYPE_ENCRYPTED);
482+
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_COLUMN"), BSON_SUBTYPE_COLUMN);
482483
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_USER_DEFINED"), BSON_SUBTYPE_USER);
483484
} /* }}} */
484485

tests/bson-corpus/binary-valid-010.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Binary type: subtype 0x80
2+
Binary type: subtype 0x07
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/basic.inc';
1111

12-
$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
13-
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';
12+
$canonicalBson = hex2bin('1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400');
13+
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "07"}}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
0f0000000578000200000080ffff00
29-
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
30-
0f0000000578000200000080ffff00
28+
1d000000057800100000000773ffd26444b34c6990e8e7d1dfc035d400
29+
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"07"}}}
30+
1d000000057800100000000773ffd26444b34c6990e8e7d1dfc035d400
3131
===DONE===

tests/bson-corpus/binary-valid-011.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
2+
Binary type: subtype 0x80
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/basic.inc';
1111

12-
$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
13-
$canonicalExtJson = '{"x" : { "$type" : "string"}}';
12+
$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
13+
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
1f000000037800170000000224747970650007000000737472696e67000000
29-
{"x":{"$type":"string"}}
30-
1f000000037800170000000224747970650007000000737472696e67000000
28+
0f0000000578000200000080ffff00
29+
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
30+
0f0000000578000200000080ffff00
3131
===DONE===

tests/bson-corpus/binary-valid-012.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE
99

1010
require_once __DIR__ . '/../utils/basic.inc';
1111

12-
$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
13-
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
12+
$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
13+
$canonicalExtJson = '{"x" : { "$type" : "string"}}';
1414

1515
// Canonical BSON -> Native -> Canonical BSON
1616
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
@@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECT--
28-
180000000378001000000010247479706500020000000000
29-
{"x":{"$type":{"$numberInt":"2"}}}
30-
180000000378001000000010247479706500020000000000
28+
1f000000037800170000000224747970650007000000737472696e67000000
29+
{"x":{"$type":"string"}}
30+
1f000000037800170000000224747970650007000000737472696e67000000
3131
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
13+
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
14+
15+
// Canonical BSON -> Native -> Canonical BSON
16+
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
17+
18+
// Canonical BSON -> Canonical extJSON
19+
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
20+
21+
// Canonical extJSON -> Canonical BSON
22+
echo bin2hex(fromJSON($canonicalExtJson)), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
180000000378001000000010247479706500020000000000
29+
{"x":{"$type":{"$numberInt":"2"}}}
30+
180000000378001000000010247479706500020000000000
31+
===DONE===

tests/bson/bson-binary-001.phpt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $types = array(
1313
MongoDB\BSON\Binary::TYPE_UUID,
1414
MongoDB\BSON\Binary::TYPE_MD5,
1515
MongoDB\BSON\Binary::TYPE_ENCRYPTED,
16+
MongoDB\BSON\Binary::TYPE_COLUMN,
1617
MongoDB\BSON\Binary::TYPE_USER_DEFINED,
1718
MongoDB\BSON\Binary::TYPE_USER_DEFINED+5,
1819
);
@@ -55,6 +56,8 @@ bool(true)
5556
bool(true)
5657
bool(true)
5758
bool(true)
59+
bool(true)
60+
bool(true)
5861
Test#0 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "00" } }
5962
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "00" } }"
6063
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "00" } }"
@@ -83,11 +86,15 @@ Test#6 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "06" } }
8386
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "06" } }"
8487
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "06" } }"
8588
bool(true)
86-
Test#7 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "80" } }
89+
Test#7 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "07" } }
90+
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "07" } }"
91+
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "07" } }"
92+
bool(true)
93+
Test#8 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "80" } }
8794
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "80" } }"
8895
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "80" } }"
8996
bool(true)
90-
Test#8 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "85" } }
97+
Test#9 { "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "85" } }
9198
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "85" } }"
9299
string(73) "{ "binary" : { "$binary" : "cmFuZG9tQmluYXJ5RGF0YQ==", "$type" : "85" } }"
93100
bool(true)

0 commit comments

Comments
 (0)