From 17e1e35671658dd33f70abf6097f24a7cdda0647 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 28 Oct 2025 16:38:44 -0400 Subject: [PATCH 1/6] Do not ignore scripts/*.php files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c5b9a6b81..fbc591860 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ mongocryptd.pid *.out *.mem *.php +!scripts/*php !*.stub.php tests/*/*.sh tests/*/*/*/*.sh From 8d0b9611623a5e27e567b4bab7d6a6c91bcc366c Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 28 Oct 2025 16:39:17 -0400 Subject: [PATCH 2/6] PHPC-2634: BSON binary vector corpus tests --- scripts/convert-bson-binary-vector-tests.php | 225 +++++++++++++++++++ tests/bson-binary-vector/float32-001.phpt | 30 +++ tests/bson-binary-vector/float32-002.phpt | 30 +++ tests/bson-binary-vector/float32-003.phpt | 28 +++ tests/bson-binary-vector/float32-004.phpt | 31 +++ tests/bson-binary-vector/float32-005.phpt | 27 +++ tests/bson-binary-vector/float32-006.phpt | 23 ++ tests/bson-binary-vector/float32-007.phpt | 23 ++ tests/bson-binary-vector/int8-001.phpt | 30 +++ tests/bson-binary-vector/int8-002.phpt | 28 +++ tests/bson-binary-vector/int8-003.phpt | 26 +++ tests/bson-binary-vector/int8-004.phpt | 26 +++ tests/bson-binary-vector/int8-005.phpt | 27 +++ tests/bson-binary-vector/int8-006.phpt | 27 +++ tests/bson-binary-vector/packed_bit-001.phpt | 27 +++ tests/bson-binary-vector/packed_bit-002.phpt | 44 ++++ tests/bson-binary-vector/packed_bit-003.phpt | 41 ++++ tests/bson-binary-vector/packed_bit-004.phpt | 28 +++ tests/bson-binary-vector/packed_bit-005.phpt | 20 ++ tests/bson-binary-vector/packed_bit-006.phpt | 20 ++ tests/bson-binary-vector/packed_bit-007.phpt | 20 ++ tests/bson-binary-vector/packed_bit-008.phpt | 27 +++ tests/bson-binary-vector/packed_bit-009.phpt | 20 ++ tests/bson-binary-vector/poc-valid-001.phpt | 24 ++ 24 files changed, 852 insertions(+) create mode 100644 scripts/convert-bson-binary-vector-tests.php create mode 100644 tests/bson-binary-vector/float32-001.phpt create mode 100644 tests/bson-binary-vector/float32-002.phpt create mode 100644 tests/bson-binary-vector/float32-003.phpt create mode 100644 tests/bson-binary-vector/float32-004.phpt create mode 100644 tests/bson-binary-vector/float32-005.phpt create mode 100644 tests/bson-binary-vector/float32-006.phpt create mode 100644 tests/bson-binary-vector/float32-007.phpt create mode 100644 tests/bson-binary-vector/int8-001.phpt create mode 100644 tests/bson-binary-vector/int8-002.phpt create mode 100644 tests/bson-binary-vector/int8-003.phpt create mode 100644 tests/bson-binary-vector/int8-004.phpt create mode 100644 tests/bson-binary-vector/int8-005.phpt create mode 100644 tests/bson-binary-vector/int8-006.phpt create mode 100644 tests/bson-binary-vector/packed_bit-001.phpt create mode 100644 tests/bson-binary-vector/packed_bit-002.phpt create mode 100644 tests/bson-binary-vector/packed_bit-003.phpt create mode 100644 tests/bson-binary-vector/packed_bit-004.phpt create mode 100644 tests/bson-binary-vector/packed_bit-005.phpt create mode 100644 tests/bson-binary-vector/packed_bit-006.phpt create mode 100644 tests/bson-binary-vector/packed_bit-007.phpt create mode 100644 tests/bson-binary-vector/packed_bit-008.phpt create mode 100644 tests/bson-binary-vector/packed_bit-009.phpt create mode 100644 tests/bson-binary-vector/poc-valid-001.phpt diff --git a/scripts/convert-bson-binary-vector-tests.php b/scripts/convert-bson-binary-vector-tests.php new file mode 100644 index 000000000..b4e93ec16 --- /dev/null +++ b/scripts/convert-bson-binary-vector-tests.php @@ -0,0 +1,225 @@ + 'Document memory leak (PHPC-2648)', + 'Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data with 3 bytes FLOAT32' => 'Document memory leak (PHPC-2648)', + 'Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data with 5 bytes FLOAT32' => 'Document memory leak (PHPC-2648)', + 'Tests of Binary subtype 9, Vectors, with dtype INT8: INT8 with padding' => 'Document memory leak (PHPC-2648)', + 'Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Padding specified with no vector data PACKED_BIT' => 'Document memory leak (PHPC-2648)', + 'Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Exceeding maximum padding PACKED_BIT' => 'Document memory leak (PHPC-2648)', +]; + +$outputPath = realpath(__DIR__ . '/../tests') . '/bson-binary-vector/'; + +if ( ! is_dir($outputPath) && ! mkdir($outputPath, 0755, true)) { + printf("Error creating output path: %s\n", $outputPath); +} + +foreach (array_slice($argv, 1) as $inputFile) { + if ( ! is_readable($inputFile) || ! is_file($inputFile)) { + printf("Error reading %s\n", $inputFile); + continue; + } + + try { + $test = Document::fromJSON(file_get_contents($inputFile))->toPHP(['root' => 'array', 'document' => 'array']); + } catch (UnexpectedValueException $e) { + printf("Error decoding %s: %s\n", $inputFile, $e->getMessage()); + continue; + } + + if ( ! isset($test['description'])) { + printf("Skipping test file without \"description\" field: %s\n", $inputFile); + continue; + } + + if ( ! isset($test['test_key'])) { + printf("Skipping test file without \"test_key\" field: %s\n", $inputFile); + continue; + } + + if ( ! empty($test['tests'])) { + foreach ($test['tests'] as $i => $case) { + $outputFile = sprintf('%s-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1); + try { + $output = renderPhpt(getParamsForTestCase($test, $case), $expectedFailures); + } catch (Exception $e) { + printf("Error processing tests[%d] in %s: %s\n", $i, $inputFile, $e->getMessage()); + continue; + } + + if (false === file_put_contents($outputPath . '/' . $outputFile, $output)) { + printf("Error writing tests[%d] in %s\n", $i, $inputFile); + continue; + } + } + } +} + +function convertVector(array $input, VectorType $vectorType, int $padding): array +{ + if (!array_is_list($input)) { + throw new InvalidArgumentException('Vector is not a list'); + } + + if ($vectorType != VectorType::PackedBit) { + if ($padding !== 0) { + throw new InvalidArgumentException(sprintf('Vector type %s does not support padding: %d', $vectorType->name, $padding)); + } + + return $input; + } + + if ($padding < 0 || $padding > 7) { + throw new InvalidArgumentException(sprintf('Expected padding [0..7], %d given', $padding)); + } + + if (count($input) === 0 && $padding > 0) { + throw new InvalidArgumentException(sprintf('Non-zero padding (%d) given for empty vector', $padding)); + } + + $vector = []; + + foreach ($input as $i => $byte) { + if (!is_int($byte)) { + throw new InvalidArgumentException(sprintf('Expected vector[%d] to be an int, %s given', $i, get_debug_type($byte))); + } + + if ($byte < 0 || $byte > 255) { + throw new InvalidArgumentException(sprintf('Expected vector[%d] to be an unsigned int8, %d given', $i, $byte)); + } + + // decbin() may return fewer than 8 binary digits, so left-pad its output with zeroes + $digits = str_pad(decbin($byte), 8, '0', STR_PAD_LEFT); + + $bits = array_map(intval(...), str_split($digits)); + + array_push($vector, ...$bits); + } + + // Remove trailing zeroes from the final byte's digits according to padding + if ($padding > 0) { + $removed = array_splice($vector, -$padding); + + // Assert that only zeroes were removed + if ($removed !== array_fill(0, $padding, 0)) { + throw new InvalidArgumentException(sprintf('Application of padding %d would remove non-zero digits: %s', $padding, json_encode($removed))); + } + } + + return $vector; +} + +function getParamsForTestCase(array $test, array $case): array +{ + foreach (['description', 'valid', 'dtype_hex'] as $field) { + if (!isset($case[$field])) { + throw new InvalidArgumentException(sprintf('Missing "%s" field', $field)); + } + } + + $code = ''; + $expect = ''; + + $vectorType = match ($case['dtype_hex']) { + '0x27' => VectorType::Float32, + '0x03' => VectorType::Int8, + '0x10' => VectorType::PackedBit, + }; + + $padding = $case['padding'] ?? 0; + + if ($case['valid']) { + $code .= sprintf('// Vector %s with padding %d', json_encode($case['vector']), $padding) . "\n"; + + /* encode a document from the numeric values, dtype, and padding, along + * with the "test_key", and assert this matches the canonical_bson + * string. */ + $vector = convertVector($case['vector'], $vectorType, $padding); + $code .= sprintf('$vector = %s;', var_export($vector, true)) . "\n\n"; + $code .= sprintf('$binary = MongoDB\BSON\Binary::fromVector($vector, %s);', var_export($vectorType, true)) . "\n"; + $code .= sprintf('echo bin2hex((string) MongoDB\BSON\Document::fromPHP([%s => $binary])), "\n";', var_export($test['test_key'], true)) . "\n\n"; + $expect .= strtolower($case['canonical_bson']) . "\n"; + + /* decode the canonical_bson into its binary form, and then assert that + * the numeric values, dtype, and padding all match those provided in + * the JSON. */ + $code .= sprintf('$bson = MongoDB\BSON\Document::fromBSON(hex2bin(%s));', var_export($case['canonical_bson'], true)) . "\n"; + $code .= sprintf('var_dump($binary == $bson[%s]);', var_export($test['test_key'], true)) . "\n"; + $expect .= 'bool(true)' . "\n"; + } else /* not valid */ { + /* if the vector field is present, raise an exception when attempting + * to encode a document from the numeric values, dtype, and padding. */ + if (isset($case['vector'])) { + $code .= sprintf('// Vector %s with padding %d', json_encode($case['vector']), $padding) . "\n"; + + try { + $vector = convertVector($case['vector'], $vectorType, $padding); + + $code .= sprintf('$vector = %s;', var_export($vector, true)) . "\n\n"; + $code .= "throws(function() use (\$vector) {\n"; + $code .= sprintf(" var_dump(MongoDB\BSON\Binary::fromVector(\$vector, %s));\n", var_export($vectorType, true)); + $code .= "}, 'MongoDB\Driver\Exception\InvalidArgumentException');" . "\n\n"; + $expect .= 'OK: Got MongoDB\Driver\Exception\InvalidArgumentException' . "\n"; + } catch (InvalidArgumentException $e) { + $code .= sprintf('echo %s, "\n";', var_export($e->getMessage(), true)) . "\n\n"; + $expect .= $e->getMessage() . "\n"; + } + } + + /* if the canonical_bson field is present, raise an exception when + * attempting to deserialize it into the corresponding numeric values, + * as the field contains corrupted data. */ + if (isset($case['canonical_bson'])) { + $code .= "throws(function() {\n"; + $code .= sprintf(' var_dump(MongoDB\BSON\Document::fromBSON(hex2bin(%s)));', var_export($case['canonical_bson'], true)) . "\n"; + $code .= "}, 'MongoDB\Driver\Exception\InvalidArgumentException');"; + $expect .= 'OK: Got MongoDB\Driver\Exception\InvalidArgumentException' . "\n"; + } + } + + return [ + '%NAME%' => sprintf('%s: %s', trim($test['description']), trim($case['description'])), + '%CODE%' => trim($code), + '%EXPECT%' => trim($expect), + ]; +} + +function renderPhpt(array $params, array $expectedFailures): string +{ + $params['%XFAIL%'] = isset($expectedFailures[$params['%NAME%']]) + ? "--XFAIL--\n" . $expectedFailures[$params['%NAME%']] . "\n" + : ''; + + $params['%SKIPIF%'] = ''; + + $template = <<< 'TEMPLATE' +--TEST-- +%NAME% +%XFAIL%%SKIPIF%--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +%EXPECT% +===DONE=== +TEMPLATE; + + return str_replace(array_keys($params), array_values($params), $template); +} diff --git a/tests/bson-binary-vector/float32-001.phpt b/tests/bson-binary-vector/float32-001.phpt new file mode 100644 index 000000000..79642ef93 --- /dev/null +++ b/tests/bson-binary-vector/float32-001.phpt @@ -0,0 +1,30 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Simple Vector FLOAT32 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 127.0, + 1 => 7.0, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Float32); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1C00000005766563746F72000A0000000927000000FE420000E04000')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1c00000005766563746f72000a0000000927000000fe420000e04000 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-002.phpt b/tests/bson-binary-vector/float32-002.phpt new file mode 100644 index 000000000..b0e07df36 --- /dev/null +++ b/tests/bson-binary-vector/float32-002.phpt @@ -0,0 +1,30 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Vector with decimals and negative value FLOAT32 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 127.7, + 1 => -7.7, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Float32); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1C00000005766563746F72000A0000000927006666FF426666F6C000')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1c00000005766563746f72000a0000000927006666ff426666f6c000 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-003.phpt b/tests/bson-binary-vector/float32-003.phpt new file mode 100644 index 000000000..e200000fe --- /dev/null +++ b/tests/bson-binary-vector/float32-003.phpt @@ -0,0 +1,28 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Empty Vector FLOAT32 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1400000005766563746F72000200000009270000')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1400000005766563746f72000200000009270000 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-004.phpt b/tests/bson-binary-vector/float32-004.phpt new file mode 100644 index 000000000..e63785844 --- /dev/null +++ b/tests/bson-binary-vector/float32-004.phpt @@ -0,0 +1,31 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Infinity Vector FLOAT32 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + -INF, + 1 => 0.0, + 2 => INF, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Float32); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('2000000005766563746F72000E000000092700000080FF000000000000807F00')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +2000000005766563746f72000e000000092700000080ff000000000000807f00 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-005.phpt b/tests/bson-binary-vector/float32-005.phpt new file mode 100644 index 000000000..ab6ab2dee --- /dev/null +++ b/tests/bson-binary-vector/float32-005.phpt @@ -0,0 +1,27 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: FLOAT32 with padding +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Vector type Float32 does not support padding: 3 +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-006.phpt b/tests/bson-binary-vector/float32-006.phpt new file mode 100644 index 000000000..d2d62eb5e --- /dev/null +++ b/tests/bson-binary-vector/float32-006.phpt @@ -0,0 +1,23 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data with 3 bytes FLOAT32 +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/float32-007.phpt b/tests/bson-binary-vector/float32-007.phpt new file mode 100644 index 000000000..eeefaef77 --- /dev/null +++ b/tests/bson-binary-vector/float32-007.phpt @@ -0,0 +1,23 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data with 5 bytes FLOAT32 +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-001.phpt b/tests/bson-binary-vector/int8-001.phpt new file mode 100644 index 000000000..2a642d993 --- /dev/null +++ b/tests/bson-binary-vector/int8-001.phpt @@ -0,0 +1,30 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: Simple Vector INT8 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 127, + 1 => 7, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Int8); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1600000005766563746F7200040000000903007F0700')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1600000005766563746f7200040000000903007f0700 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-002.phpt b/tests/bson-binary-vector/int8-002.phpt new file mode 100644 index 000000000..93b4c6b1f --- /dev/null +++ b/tests/bson-binary-vector/int8-002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: Empty Vector INT8 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1400000005766563746F72000200000009030000')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1400000005766563746f72000200000009030000 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-003.phpt b/tests/bson-binary-vector/int8-003.phpt new file mode 100644 index 000000000..6e8c2a848 --- /dev/null +++ b/tests/bson-binary-vector/int8-003.phpt @@ -0,0 +1,26 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: Overflow Vector INT8 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 128, +); + +throws(function() use ($vector) { + var_dump(MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Int8)); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'); + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-004.phpt b/tests/bson-binary-vector/int8-004.phpt new file mode 100644 index 000000000..15f397e78 --- /dev/null +++ b/tests/bson-binary-vector/int8-004.phpt @@ -0,0 +1,26 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: Underflow Vector INT8 +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + -129, +); + +throws(function() use ($vector) { + var_dump(MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Int8)); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'); + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-005.phpt b/tests/bson-binary-vector/int8-005.phpt new file mode 100644 index 000000000..b0064fd51 --- /dev/null +++ b/tests/bson-binary-vector/int8-005.phpt @@ -0,0 +1,27 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: INT8 with padding +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Vector type Int8 does not support padding: 3 +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/int8-006.phpt b/tests/bson-binary-vector/int8-006.phpt new file mode 100644 index 000000000..8b9f1f440 --- /dev/null +++ b/tests/bson-binary-vector/int8-006.phpt @@ -0,0 +1,27 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: INT8 with float inputs +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 127.77, + 1 => 7.77, +); + +throws(function() use ($vector) { + var_dump(MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::Int8)); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'); + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-001.phpt b/tests/bson-binary-vector/packed_bit-001.phpt new file mode 100644 index 000000000..678d8d859 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Padding specified with no vector data PACKED_BIT +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Non-zero padding (1) given for empty vector +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-002.phpt b/tests/bson-binary-vector/packed_bit-002.phpt new file mode 100644 index 000000000..588a943b4 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-002.phpt @@ -0,0 +1,44 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Simple Vector PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 0, + 1 => 1, + 2 => 1, + 3 => 1, + 4 => 1, + 5 => 1, + 6 => 1, + 7 => 1, + 8 => 0, + 9 => 0, + 10 => 0, + 11 => 0, + 12 => 0, + 13 => 1, + 14 => 1, + 15 => 1, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::PackedBit); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1600000005766563746F7200040000000910007F0700')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1600000005766563746f7200040000000910007f0700 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-003.phpt b/tests/bson-binary-vector/packed_bit-003.phpt new file mode 100644 index 000000000..b374312f3 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-003.phpt @@ -0,0 +1,41 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: PACKED_BIT with padding +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + 0, + 1 => 1, + 2 => 1, + 3 => 1, + 4 => 1, + 5 => 1, + 6 => 1, + 7 => 1, + 8 => 0, + 9 => 0, + 10 => 0, + 11 => 0, + 12 => 1, +); + +$binary = MongoDB\BSON\Binary::fromVector($vector, \MongoDB\BSON\VectorType::PackedBit); +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1600000005766563746F7200040000000910037F0800')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1600000005766563746f7200040000000910037f0800 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-004.phpt b/tests/bson-binary-vector/packed_bit-004.phpt new file mode 100644 index 000000000..fe0399ffb --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-004.phpt @@ -0,0 +1,28 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Empty Vector PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + $binary])), "\n"; + +$bson = MongoDB\BSON\Document::fromBSON(hex2bin('1400000005766563746F72000200000009100000')); +var_dump($binary == $bson['vector']); + +?> +===DONE=== + +--EXPECT-- +1400000005766563746f72000200000009100000 +bool(true) +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-005.phpt b/tests/bson-binary-vector/packed_bit-005.phpt new file mode 100644 index 000000000..34a59e8a8 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-005.phpt @@ -0,0 +1,20 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Overflow Vector PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Expected vector[0] to be an unsigned int8, 256 given +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-006.phpt b/tests/bson-binary-vector/packed_bit-006.phpt new file mode 100644 index 000000000..71d5e4418 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-006.phpt @@ -0,0 +1,20 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Underflow Vector PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Expected vector[0] to be an unsigned int8, -1 given +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-007.phpt b/tests/bson-binary-vector/packed_bit-007.phpt new file mode 100644 index 000000000..2e68b9273 --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-007.phpt @@ -0,0 +1,20 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Vector with float values PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Expected vector[0] to be an int, float given +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-008.phpt b/tests/bson-binary-vector/packed_bit-008.phpt new file mode 100644 index 000000000..585c898fe --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-008.phpt @@ -0,0 +1,27 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Exceeding maximum padding PACKED_BIT +--XFAIL-- +Document memory leak (PHPC-2648) +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Expected padding [0..7], 8 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/packed_bit-009.phpt b/tests/bson-binary-vector/packed_bit-009.phpt new file mode 100644 index 000000000..e81d6812c --- /dev/null +++ b/tests/bson-binary-vector/packed_bit-009.phpt @@ -0,0 +1,20 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Negative padding PACKED_BIT +--DESCRIPTION-- +Generated by scripts/convert-bson-corpus-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + +===DONE=== + +--EXPECT-- +Expected padding [0..7], -1 given +===DONE=== \ No newline at end of file diff --git a/tests/bson-binary-vector/poc-valid-001.phpt b/tests/bson-binary-vector/poc-valid-001.phpt new file mode 100644 index 000000000..baf5a9186 --- /dev/null +++ b/tests/bson-binary-vector/poc-valid-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Tests of Binary subtype 9, Vectors, with dtype INT8: Simple Vector INT8 +--DESCRIPTION-- +Generated by scripts/convert-bson-binary-vector-tests.php + +DO NOT EDIT THIS FILE +--FILE-- + Canonical BSON +echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $vector])), "\n"; + +?> +===DONE=== + +--EXPECT-- +1600000005766563746f7200040000000903007f0700 +===DONE=== From d6f289e94384c1c1acd3b4567a0e76f5184328e2 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 3 Nov 2025 00:06:58 -0500 Subject: [PATCH 3/6] Add prose tests and remove POC test --- tests/bson-binary-vector/poc-valid-001.phpt | 24 ----------------- tests/bson-binary-vector/prose_test-001.phpt | 27 +++++++++++++++++++ tests/bson-binary-vector/prose_test-003.phpt | 28 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 24 deletions(-) delete mode 100644 tests/bson-binary-vector/poc-valid-001.phpt create mode 100644 tests/bson-binary-vector/prose_test-001.phpt create mode 100644 tests/bson-binary-vector/prose_test-003.phpt diff --git a/tests/bson-binary-vector/poc-valid-001.phpt b/tests/bson-binary-vector/poc-valid-001.phpt deleted file mode 100644 index baf5a9186..000000000 --- a/tests/bson-binary-vector/poc-valid-001.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Tests of Binary subtype 9, Vectors, with dtype INT8: Simple Vector INT8 ---DESCRIPTION-- -Generated by scripts/convert-bson-binary-vector-tests.php - -DO NOT EDIT THIS FILE ---FILE-- - Canonical BSON -echo bin2hex((string) MongoDB\BSON\Document::fromPHP(['vector' => $vector])), "\n"; - -?> -===DONE=== - ---EXPECT-- -1600000005766563746f7200040000000903007f0700 -===DONE=== diff --git a/tests/bson-binary-vector/prose_test-001.phpt b/tests/bson-binary-vector/prose_test-001.phpt new file mode 100644 index 000000000..eb06cb80a --- /dev/null +++ b/tests/bson-binary-vector/prose_test-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Binary vector: Encoding PackedBit vector with non-zero, padded bits fails +--DESCRIPTION-- +Binary vector prose test #1 +https://github.com/mongodb/specifications/blob/master/source/bson-binary-vector/tests/README.md#prose-tests +--FILE-- + +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Binary vector data is invalid +===DONE=== diff --git a/tests/bson-binary-vector/prose_test-003.phpt b/tests/bson-binary-vector/prose_test-003.phpt new file mode 100644 index 000000000..cb070ad56 --- /dev/null +++ b/tests/bson-binary-vector/prose_test-003.phpt @@ -0,0 +1,28 @@ +--TEST-- +Binary vector: PackedBit vector comparisons +--DESCRIPTION-- +Binary vector prose test #3 +https://github.com/mongodb/specifications/blob/master/source/bson-binary-vector/tests/README.md#prose-tests +--FILE-- +toArray() === $b2->toArray()); + +?> +===DONE=== + +--EXPECT-- +bool(true) +bool(true) +===DONE=== \ No newline at end of file From 04f5362e0be7d589c6bfd9141b686c092fb16c25 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 12 Nov 2025 14:26:52 -0500 Subject: [PATCH 4/6] Fix script name --- scripts/convert-bson-binary-vector-tests.php | 2 +- tests/bson-binary-vector/float32-001.phpt | 2 +- tests/bson-binary-vector/float32-002.phpt | 2 +- tests/bson-binary-vector/float32-003.phpt | 2 +- tests/bson-binary-vector/float32-004.phpt | 2 +- tests/bson-binary-vector/float32-005.phpt | 2 +- tests/bson-binary-vector/float32-006.phpt | 2 +- tests/bson-binary-vector/float32-007.phpt | 2 +- tests/bson-binary-vector/int8-001.phpt | 2 +- tests/bson-binary-vector/int8-002.phpt | 2 +- tests/bson-binary-vector/int8-003.phpt | 2 +- tests/bson-binary-vector/int8-004.phpt | 2 +- tests/bson-binary-vector/int8-005.phpt | 2 +- tests/bson-binary-vector/int8-006.phpt | 2 +- tests/bson-binary-vector/packed_bit-001.phpt | 2 +- tests/bson-binary-vector/packed_bit-002.phpt | 2 +- tests/bson-binary-vector/packed_bit-003.phpt | 2 +- tests/bson-binary-vector/packed_bit-004.phpt | 2 +- tests/bson-binary-vector/packed_bit-005.phpt | 2 +- tests/bson-binary-vector/packed_bit-006.phpt | 2 +- tests/bson-binary-vector/packed_bit-007.phpt | 2 +- tests/bson-binary-vector/packed_bit-008.phpt | 2 +- tests/bson-binary-vector/packed_bit-009.phpt | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/convert-bson-binary-vector-tests.php b/scripts/convert-bson-binary-vector-tests.php index b4e93ec16..edd597c4f 100644 --- a/scripts/convert-bson-binary-vector-tests.php +++ b/scripts/convert-bson-binary-vector-tests.php @@ -203,7 +203,7 @@ function renderPhpt(array $params, array $expectedFailures): string --TEST-- %NAME% %XFAIL%%SKIPIF%--DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-001.phpt b/tests/bson-binary-vector/float32-001.phpt index 79642ef93..d82dc474b 100644 --- a/tests/bson-binary-vector/float32-001.phpt +++ b/tests/bson-binary-vector/float32-001.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Simple Vector FLOAT32 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-002.phpt b/tests/bson-binary-vector/float32-002.phpt index b0e07df36..dfc5ff13d 100644 --- a/tests/bson-binary-vector/float32-002.phpt +++ b/tests/bson-binary-vector/float32-002.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Vector with decimals and negative value FLOAT32 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-003.phpt b/tests/bson-binary-vector/float32-003.phpt index e200000fe..dfbb83714 100644 --- a/tests/bson-binary-vector/float32-003.phpt +++ b/tests/bson-binary-vector/float32-003.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Empty Vector FLOAT32 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-004.phpt b/tests/bson-binary-vector/float32-004.phpt index e63785844..af32dea7f 100644 --- a/tests/bson-binary-vector/float32-004.phpt +++ b/tests/bson-binary-vector/float32-004.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Infinity Vector FLOAT32 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-005.phpt b/tests/bson-binary-vector/float32-005.phpt index ab6ab2dee..df9644393 100644 --- a/tests/bson-binary-vector/float32-005.phpt +++ b/tests/bson-binary-vector/float32-005.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype FLOAT32: FLOAT32 with padding --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-006.phpt b/tests/bson-binary-vector/float32-006.phpt index d2d62eb5e..194fc992a 100644 --- a/tests/bson-binary-vector/float32-006.phpt +++ b/tests/bson-binary-vector/float32-006.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/float32-007.phpt b/tests/bson-binary-vector/float32-007.phpt index eeefaef77..6e707f9fb 100644 --- a/tests/bson-binary-vector/float32-007.phpt +++ b/tests/bson-binary-vector/float32-007.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype FLOAT32: Insufficient vector data --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-001.phpt b/tests/bson-binary-vector/int8-001.phpt index 2a642d993..3942e5e93 100644 --- a/tests/bson-binary-vector/int8-001.phpt +++ b/tests/bson-binary-vector/int8-001.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype INT8: Simple Vector INT8 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-002.phpt b/tests/bson-binary-vector/int8-002.phpt index 93b4c6b1f..069f9e9c3 100644 --- a/tests/bson-binary-vector/int8-002.phpt +++ b/tests/bson-binary-vector/int8-002.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype INT8: Empty Vector INT8 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-003.phpt b/tests/bson-binary-vector/int8-003.phpt index 6e8c2a848..d4f2ce48e 100644 --- a/tests/bson-binary-vector/int8-003.phpt +++ b/tests/bson-binary-vector/int8-003.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype INT8: Overflow Vector INT8 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-004.phpt b/tests/bson-binary-vector/int8-004.phpt index 15f397e78..362c11f80 100644 --- a/tests/bson-binary-vector/int8-004.phpt +++ b/tests/bson-binary-vector/int8-004.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype INT8: Underflow Vector INT8 --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-005.phpt b/tests/bson-binary-vector/int8-005.phpt index b0064fd51..d7c52b929 100644 --- a/tests/bson-binary-vector/int8-005.phpt +++ b/tests/bson-binary-vector/int8-005.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype INT8: INT8 with padding --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/int8-006.phpt b/tests/bson-binary-vector/int8-006.phpt index 8b9f1f440..b0193d0ff 100644 --- a/tests/bson-binary-vector/int8-006.phpt +++ b/tests/bson-binary-vector/int8-006.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype INT8: INT8 with float inputs --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-001.phpt b/tests/bson-binary-vector/packed_bit-001.phpt index 678d8d859..c2abaa61a 100644 --- a/tests/bson-binary-vector/packed_bit-001.phpt +++ b/tests/bson-binary-vector/packed_bit-001.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Padding specified wit --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-002.phpt b/tests/bson-binary-vector/packed_bit-002.phpt index 588a943b4..9fd7139f1 100644 --- a/tests/bson-binary-vector/packed_bit-002.phpt +++ b/tests/bson-binary-vector/packed_bit-002.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Simple Vector PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-003.phpt b/tests/bson-binary-vector/packed_bit-003.phpt index b374312f3..b5761f9d7 100644 --- a/tests/bson-binary-vector/packed_bit-003.phpt +++ b/tests/bson-binary-vector/packed_bit-003.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: PACKED_BIT with padding --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-004.phpt b/tests/bson-binary-vector/packed_bit-004.phpt index fe0399ffb..579b5a676 100644 --- a/tests/bson-binary-vector/packed_bit-004.phpt +++ b/tests/bson-binary-vector/packed_bit-004.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Empty Vector PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-005.phpt b/tests/bson-binary-vector/packed_bit-005.phpt index 34a59e8a8..b5386752b 100644 --- a/tests/bson-binary-vector/packed_bit-005.phpt +++ b/tests/bson-binary-vector/packed_bit-005.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Overflow Vector PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-006.phpt b/tests/bson-binary-vector/packed_bit-006.phpt index 71d5e4418..5f766c39d 100644 --- a/tests/bson-binary-vector/packed_bit-006.phpt +++ b/tests/bson-binary-vector/packed_bit-006.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Underflow Vector PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-007.phpt b/tests/bson-binary-vector/packed_bit-007.phpt index 2e68b9273..e87902cb6 100644 --- a/tests/bson-binary-vector/packed_bit-007.phpt +++ b/tests/bson-binary-vector/packed_bit-007.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Vector with float values PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-008.phpt b/tests/bson-binary-vector/packed_bit-008.phpt index 585c898fe..2b72b5f6f 100644 --- a/tests/bson-binary-vector/packed_bit-008.phpt +++ b/tests/bson-binary-vector/packed_bit-008.phpt @@ -3,7 +3,7 @@ Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Exceeding maximum pad --XFAIL-- Document memory leak (PHPC-2648) --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- diff --git a/tests/bson-binary-vector/packed_bit-009.phpt b/tests/bson-binary-vector/packed_bit-009.phpt index e81d6812c..8c59fbfbc 100644 --- a/tests/bson-binary-vector/packed_bit-009.phpt +++ b/tests/bson-binary-vector/packed_bit-009.phpt @@ -1,7 +1,7 @@ --TEST-- Tests of Binary subtype 9, Vectors, with dtype PACKED_BIT: Negative padding PACKED_BIT --DESCRIPTION-- -Generated by scripts/convert-bson-corpus-tests.php +Generated by scripts/convert-bson-binary-vector-tests.php DO NOT EDIT THIS FILE --FILE-- From 56323ede1b30cf04733fa8215d07052bf938ab27 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 12 Nov 2025 14:27:19 -0500 Subject: [PATCH 5/6] Revise prose test structure --- tests/bson-binary-vector/prose_test-001.phpt | 7 +++---- tests/bson-binary-vector/prose_test-003.phpt | 11 ++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/bson-binary-vector/prose_test-001.phpt b/tests/bson-binary-vector/prose_test-001.phpt index eb06cb80a..34cbee878 100644 --- a/tests/bson-binary-vector/prose_test-001.phpt +++ b/tests/bson-binary-vector/prose_test-001.phpt @@ -9,14 +9,13 @@ https://github.com/mongodb/specifications/blob/master/source/bson-binary-vector/ require_once __DIR__ . '/../utils/basic.inc'; // PackedBit vector with padding:7 and non-zero bits is invalid - +echo throws(function() { + var_dump(new MongoDB\BSON\Binary("\x10\x07\xff", MongoDB\BSON\Binary::TYPE_VECTOR)); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; /* PHPC does not allow constructing a PackedBit vector with non-zero, padded * bits. As a result, the corresponding decoding test (i.e. prose test #2) * cannot be implemented. */ -echo throws(function() { - var_dump(new MongoDB\BSON\Binary("\x10\x07\xff", MongoDB\BSON\Binary::TYPE_VECTOR)); -}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; ?> ===DONE=== diff --git a/tests/bson-binary-vector/prose_test-003.phpt b/tests/bson-binary-vector/prose_test-003.phpt index cb070ad56..b77dc0622 100644 --- a/tests/bson-binary-vector/prose_test-003.phpt +++ b/tests/bson-binary-vector/prose_test-003.phpt @@ -11,13 +11,18 @@ require_once __DIR__ . '/../utils/basic.inc'; /* Although PHPC does not allow constructing a vector with non-zero, padded * bits, we can still test comparisons between two valid vector objects * constructed from raw data and a PHP array, respectively. */ + +// PackedBit vector with padding:7 and all-zero bits $b1 = new MongoDB\BSON\Binary("\x10\x07\x80", MongoDB\BSON\Binary::TYPE_VECTOR); +$v1 = $b1->toArray(); // PackedBit vector with padding:7 and all-zero bits (constructed from PHP array) -$b2 = MongoDB\BSON\Binary::fromVector([1], MongoDB\BSON\VectorType::PackedBit); +$b3 = MongoDB\BSON\Binary::fromVector([1], MongoDB\BSON\VectorType::PackedBit); +$v3 = $b3->toArray(); -var_dump($b1 == $b2); -var_dump($b1->toArray() === $b2->toArray()); +// Assert that both Binary and array representations are equal +var_dump($b1 == $b3); +var_dump($b1 === $v3); ?> ===DONE=== From e589e4a841343b333c9bc439c5d285c3f01bde59 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 12 Nov 2025 14:35:13 -0500 Subject: [PATCH 6/6] Fix variable reference --- tests/bson-binary-vector/prose_test-003.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bson-binary-vector/prose_test-003.phpt b/tests/bson-binary-vector/prose_test-003.phpt index b77dc0622..84d42ac98 100644 --- a/tests/bson-binary-vector/prose_test-003.phpt +++ b/tests/bson-binary-vector/prose_test-003.phpt @@ -22,7 +22,7 @@ $v3 = $b3->toArray(); // Assert that both Binary and array representations are equal var_dump($b1 == $b3); -var_dump($b1 === $v3); +var_dump($v1 === $v3); ?> ===DONE===