Skip to content

Commit ea529e1

Browse files
committed
Merge pull request #1119
* phpc-1561: PHPC-1561: Allow hinting for delete Fix update spec test for server-side error Fix tests for new tls option incompatibilities Update to latest libmongoc version
2 parents 0f7fb93 + 36cf304 commit ea529e1

9 files changed

+100
-6
lines changed

src/LIBMONGOC_VERSION_CURRENT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.17.0-20200309+git49ccff2845
1+
1.17.0-20200330+git1b9ce0d3d3

src/MongoDB/BulkWrite.c

+4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ static bool php_phongo_bulkwrite_delete_apply_options(bson_t* boptions, zval* zo
297297
PHONGO_BULKWRITE_APPEND_INT32("limit", limit);
298298
PHONGO_BULKWRITE_OPT_DOCUMENT("collation");
299299

300+
if (!php_phongo_bulkwrite_opt_hint(boptions, zoptions)) {
301+
return false;
302+
}
303+
300304
return true;
301305
} /* }}} */
302306

src/libmongoc

Submodule libmongoc updated 173 files

tests/bulk/bulkwrite-delete-002.phpt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWrite::delete() with hint option
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
<?php skip_if_server_version('<', '4.3.4'); ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
class CommandLogger implements MongoDB\Driver\Monitoring\CommandSubscriber
13+
{
14+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
15+
{
16+
if ($event->getCommandName() !== 'delete') {
17+
return;
18+
}
19+
20+
printf("delete included hint: %s\n", json_encode($event->getCommand()->deletes[0]->hint));
21+
}
22+
23+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
24+
{
25+
}
26+
27+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
28+
{
29+
}
30+
}
31+
32+
$manager = new MongoDB\Driver\Manager(URI);
33+
34+
$bulk = new MongoDB\Driver\BulkWrite();
35+
$bulk->insert(['x' => 1]);
36+
$bulk->insert(['x' => 2]);
37+
$manager->executeBulkWrite(NS, $bulk);
38+
39+
MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger);
40+
41+
$bulk = new MongoDB\Driver\BulkWrite;
42+
$bulk->delete(['_id' => 1], ['hint' => '_id_']);
43+
$manager->executeBulkWrite(NS, $bulk);
44+
45+
$bulk = new MongoDB\Driver\BulkWrite;
46+
$bulk->delete(['_id' => 2], ['hint' => ['_id' => 1]]);
47+
$manager->executeBulkWrite(NS, $bulk);
48+
49+
?>
50+
===DONE===
51+
<?php exit(0); ?>
52+
--EXPECTF--
53+
delete included hint: "_id_"
54+
delete included hint: {"_id":1}
55+
===DONE===

tests/bulk/bulkwrite-delete_error-001.phpt

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ $bulk = new MongoDB\Driver\BulkWrite;
99

1010
echo throws(function() use ($bulk) {
1111
$bulk->delete(['x' => 1], ['collation' => 1]);
12+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n";
13+
14+
echo throws(function() use ($bulk) {
15+
$bulk->delete(['x' => 1], ['hint' => 1]);
1216
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1317

1418
?>
@@ -17,4 +21,7 @@ echo throws(function() use ($bulk) {
1721
--EXPECTF--
1822
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
1923
Expected "collation" option to be array or object, int%S given
24+
25+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
26+
Expected "hint" option to be string, array, or object, int%S given
2027
===DONE===
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWrite::delete() hint option requires MongoDB 4.4 (server-side error)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
<?php skip_if_server_version('>=', '4.3.4'); ?>
7+
<?php skip_if_server_version('<=', '3.6.0'); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$manager = new MongoDB\Driver\Manager(URI);
13+
14+
$bulk = new MongoDB\Driver\BulkWrite;
15+
$bulk->delete(['_id' => 1], ['hint' => '_id_']);
16+
17+
echo throws(function() use ($manager, $bulk) {
18+
$manager->executeBulkWrite(NS, $bulk);
19+
}, 'MongoDB\Driver\Exception\BulkWriteException'), "\n";
20+
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECT--
25+
OK: Got MongoDB\Driver\Exception\BulkWriteException
26+
BSON field 'delete.deletes.hint' is an unknown field.
27+
===DONE===

tests/bulk/bulkwrite-update_error-008.phpt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
--TEST--
2-
MongoDB\Driver\BulkWrite::update() hint option requires MongoDB 4.2
2+
MongoDB\Driver\BulkWrite::update() hint option requires MongoDB 4.2 (server-side error)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_live(); ?>
66
<?php skip_if_server_version('>=', '4.2'); ?>
7+
<?php skip_if_server_version('<=', '3.6.0'); ?>
78
--FILE--
89
<?php
910
require_once __DIR__ . "/../utils/basic.inc";
@@ -22,5 +23,5 @@ echo throws(function() use ($manager, $bulk) {
2223
<?php exit(0); ?>
2324
--EXPECT--
2425
OK: Got MongoDB\Driver\Exception\BulkWriteException
25-
Bulk write failed due to previous MongoDB\Driver\Exception\RuntimeException: The selected server does not support hint for update
26+
BSON field 'update.updates.hint' is an unknown field.
2627
===DONE===

tests/manager/manager-ctor-tls-error-001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ echo throws(function() {
2626
<?php exit(0); ?>
2727
--EXPECT--
2828
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29-
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidHostnames=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidHostnames=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3030
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3131
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException

tests/manager/manager-ctor-tls-error-002.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ echo throws(function() {
2626
<?php exit(0); ?>
2727
--EXPECT--
2828
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29-
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidCertificates=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidCertificates=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3030
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3131
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException

0 commit comments

Comments
 (0)