From 6eaa791e346d4f4f95d3a247bd67c9789c54a449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 7 May 2025 13:59:13 +0200 Subject: [PATCH] Add tests on client buk write replaceOne, updateMany and deleteMany --- .../bulkwritecommand-deleteMany-001.phpt | 68 +++++++++++ .../bulkwritecommand-deleteMany-002.phpt | 55 +++++++++ .../bulkwritecommand-deleteMany-003.phpt | 34 ++++++ ...bulkwritecommand-deleteMany_error-001.phpt | 27 +++++ ...bulkwritecommand-deleteMany_error-002.phpt | 27 +++++ ...bulkwritecommand-deleteMany_error-003.phpt | 55 +++++++++ ...bulkwritecommand-deleteMany_error-004.phpt | 32 +++++ .../bulkwritecommand-deleteOne_error-004.phpt | 1 - .../bulkwritecommand-replaceOne-001.phpt | 109 ++++++++++++++++++ .../bulkwritecommand-replaceOne-004.phpt | 55 +++++++++ .../bulkwritecommand-replaceOne-008.phpt | 81 +++++++++++++ ...bulkwritecommand-replaceOne_error-003.phpt | 34 ++++++ ...bulkwritecommand-replaceOne_error-004.phpt | 41 +++++++ ...bulkwritecommand-replaceOne_error-005.phpt | 76 ++++++++++++ ...bulkwritecommand-replaceOne_error-006.phpt | 31 +++++ ...t => bulkwritecommand-updateMany-002.phpt} | 2 +- ...t => bulkwritecommand-updateMany-003.phpt} | 0 ...t => bulkwritecommand-updateMany-005.phpt} | 2 +- ...t => bulkwritecommand-updateMany-007.phpt} | 2 +- 19 files changed, 728 insertions(+), 4 deletions(-) create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany-001.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany-002.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany-003.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany_error-001.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany_error-002.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany_error-003.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-deleteMany_error-004.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne-001.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne-004.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne-008.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne_error-003.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne_error-004.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne_error-005.phpt create mode 100644 tests/bulkwritecommand/bulkwritecommand-replaceOne_error-006.phpt rename tests/bulkwritecommand/{bulkwritecommand-updateOne-002.phpt => bulkwritecommand-updateMany-002.phpt} (95%) rename tests/bulkwritecommand/{bulkwritecommand-updateOne-003.phpt => bulkwritecommand-updateMany-003.phpt} (100%) rename tests/bulkwritecommand/{bulkwritecommand-updateOne-005.phpt => bulkwritecommand-updateMany-005.phpt} (90%) rename tests/bulkwritecommand/{bulkwritecommand-updateOne-007.phpt => bulkwritecommand-updateMany-007.phpt} (95%) diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany-001.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany-001.phpt new file mode 100644 index 000000000..b3ccb5869 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany-001.phpt @@ -0,0 +1,68 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() should always encode __pclass for Persistable objects +--SKIPIF-- + + + + +--FILE-- +id = $id; + $this->child = $child; + } + + public function bsonSerialize(): array + { + return [ + '_id' => $this->id, + 'child' => $this->child, + ]; + } + + public function bsonUnserialize(array $data): void + { + $this->id = $data['_id']; + $this->child = $data['child']; + } +} + +$manager = create_test_manager(); + +$document = new MyClass('foo', new MyClass('bar', new MyClass('baz'))); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->insertOne(NS, $document); +$bulk->insertOne(NS, new MyClass('foo2', new MyClass('bar', new MyClass('baz')))); +$bulk->insertOne(NS, new MyClass('foo3', new MyClass('bar', new MyClass('baz')))); +$result = $manager->executeBulkWriteCommand($bulk); +printf("Inserted %d document(s)\n", $result->getInsertedCount()); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); +var_dump(count($cursor->toArray())); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->deleteMany(NS, $document); +$result = $manager->executeBulkWriteCommand($bulk); +printf("Deleted %d document(s)\n", $result->getDeletedCount()); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); +var_dump(count($cursor->toArray())); + +?> +===DONE=== + +--EXPECTF-- +Inserted 3 document(s) +int(3) +Deleted 1 document(s) +int(2) +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany-002.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany-002.phpt new file mode 100644 index 000000000..f7ff39812 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany-002.phpt @@ -0,0 +1,55 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() with hint option +--SKIPIF-- + + + + +--FILE-- +getCommandName() !== 'bulkWrite') { + return; + } + + printf("delete included hint: %s\n", json_encode($event->getCommand()->ops[0]->hint)); + } + + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void + { + } + + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void + { + } +} + +$manager = create_test_manager(); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->insertOne(NS, ['x' => 1]); +$bulk->insertOne(NS, ['x' => 2]); +$manager->executeBulkWriteCommand($bulk); + +MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->deleteMany(NS, ['_id' => 1], ['hint' => '_id_']); +$manager->executeBulkWriteCommand($bulk); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->deleteMany(NS, ['_id' => 2], ['hint' => ['_id' => 1]]); +$manager->executeBulkWriteCommand($bulk); + +?> +===DONE=== + +--EXPECTF-- +delete included hint: "_id_" +delete included hint: {"_id":1} +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany-003.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany-003.phpt new file mode 100644 index 000000000..5ef0a10bf --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany-003.phpt @@ -0,0 +1,34 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() $filter is MongoDB\BSON\Document +--SKIPIF-- + + + + +--FILE-- +insertOne(NS, ['_id' => 1]); +$bulk->insertOne(NS, ['_id' => 2]); +$bulk->insertOne(NS, ['_id' => 3]); +$manager->executeBulkWriteCommand($bulk); + +$filter = MongoDB\BSON\Document::fromJSON('{ "_id": { "$gt": 1 } }'); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->deleteMany(NS, $filter); +$result = $manager->executeBulkWriteCommand($bulk); + +var_dump($result->getDeletedCount()); + +?> +===DONE=== + +--EXPECT-- +int(2) +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-001.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-001.phpt new file mode 100644 index 000000000..fa172733d --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() with invalid options +--FILE-- +deleteMany(NS, ['x' => 1], ['collation' => 1]); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ['x' => 1], ['hint' => 1]); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "collation" option to be array or object, int given + +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "hint" option to be string, array, or object, int given +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-002.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-002.phpt new file mode 100644 index 000000000..4ad615501 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-002.phpt @@ -0,0 +1,27 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() with BSON encoding error (invalid UTF-8 string) +--FILE-- +deleteMany(NS, ['x' => "\xc3\x28"]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ['x' => 1], ['collation' => ['locale' => "\xc3\x28"]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; + +?> +===DONE=== + +--EXPECTF-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "x": %s + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "locale": %s +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-003.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-003.phpt new file mode 100644 index 000000000..73d10f7b5 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-003.phpt @@ -0,0 +1,55 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() with BSON encoding error (null bytes in keys) +--FILE-- +deleteMany(NS, ["\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ["x\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ["\0\0\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ['x' => 1], ['collation' => ["\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ['x' => 1], ['collation' => ["x\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, ['x' => 1], ['collation' => ["\0\0\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "x". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "x". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-004.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-004.phpt new file mode 100644 index 000000000..828da6e11 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-deleteMany_error-004.phpt @@ -0,0 +1,32 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::deleteMany() prohibits PackedArray for document values +--FILE-- +deleteMany(NS, MongoDB\BSON\PackedArray::fromPHP([])); +}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n"; + +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, [], ['collation' => MongoDB\BSON\PackedArray::fromPHP([])]); +}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n"; + +// Expected "hint" option to yield string or document but got "array" +echo throws(function() use ($bulk) { + $bulk->deleteMany(NS, [], ['hint' => MongoDB\BSON\PackedArray::fromPHP([])]); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +MongoDB\BSON\PackedArray cannot be serialized as a root document +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +MongoDB\BSON\PackedArray cannot be serialized as a root document +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "hint" option to yield string or document but got "array" +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-deleteOne_error-004.phpt b/tests/bulkwritecommand/bulkwritecommand-deleteOne_error-004.phpt index 52abea739..c971e6e07 100644 --- a/tests/bulkwritecommand/bulkwritecommand-deleteOne_error-004.phpt +++ b/tests/bulkwritecommand/bulkwritecommand-deleteOne_error-004.phpt @@ -14,7 +14,6 @@ echo throws(function() use ($bulk) { $bulk->deleteOne(NS, [], ['collation' => MongoDB\BSON\PackedArray::fromPHP([])]); }, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n"; -// @TODO: ALMOST: Got MongoDB\Driver\Exception\InvalidArgumentException - expected MongoDB\Driver\Exception\UnexpectedValueException // Expected "hint" option to yield string or document but got "array" echo throws(function() use ($bulk) { $bulk->deleteOne(NS, [], ['hint' => MongoDB\BSON\PackedArray::fromPHP([])]); diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne-001.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne-001.phpt new file mode 100644 index 000000000..3f5625e87 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne-001.phpt @@ -0,0 +1,109 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() should always encode __pclass for Persistable objects +--SKIPIF-- + + + + +--FILE-- +id = $id; + $this->child = $child; + } + + public function bsonSerialize(): array + { + return [ + '_id' => $this->id, + 'child' => $this->child, + ]; + } + + public function bsonUnserialize(array $data): void + { + $this->id = $data['_id']; + $this->child = $data['child']; + } +} + +$manager = create_test_manager(); + +$document = new MyClass('foo', new MyClass('bar', new MyClass('baz'))); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->replaceOne(NS, + ['_id' => 'foo'], + $document, + ['upsert' => true] +); +$result = $manager->executeBulkWriteCommand($bulk); +printf("Upserted %d document(s)\n", $result->getUpsertedCount()); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); +var_dump($cursor->toArray()); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->replaceOne(NS, + $document, + ['child' => new MyClass('yip', new MyClass('yap'))] +); +$result = $manager->executeBulkWriteCommand($bulk); +printf("Modified %d document(s)\n", $result->getModifiedCount()); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); +var_dump($cursor->toArray()); + +?> +===DONE=== + +--EXPECTF-- +Upserted 1 document(s) +array(1) { + [0]=> + object(MyClass)#%d (%d) { + ["id":"MyClass":private]=> + string(3) "foo" + ["child":"MyClass":private]=> + object(MyClass)#%d (%d) { + ["id":"MyClass":private]=> + string(3) "bar" + ["child":"MyClass":private]=> + object(MyClass)#%d (%d) { + ["id":"MyClass":private]=> + string(3) "baz" + ["child":"MyClass":private]=> + NULL + } + } + } +} +Modified 1 document(s) +array(1) { + [0]=> + object(stdClass)#%d (%d) { + ["_id"]=> + string(3) "foo" + ["child"]=> + object(MyClass)#%d (%d) { + ["id":"MyClass":private]=> + string(3) "yip" + ["child":"MyClass":private]=> + object(MyClass)#%d (%d) { + ["id":"MyClass":private]=> + string(3) "yap" + ["child":"MyClass":private]=> + NULL + } + } + } +} +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne-004.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne-004.phpt new file mode 100644 index 000000000..0f5581cfe --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne-004.phpt @@ -0,0 +1,55 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() with hint option +--SKIPIF-- + + + + +--FILE-- +getCommandName() !== 'bulkWrite') { + return; + } + + printf("replace included hint: %s\n", json_encode($event->getCommand()->ops[0]->hint)); + } + + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void + { + } + + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void + { + } +} + +$manager = create_test_manager(); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->insertOne(NS, ['x' => 1]); +$bulk->insertOne(NS, ['x' => 2]); +$manager->executeBulkWriteCommand($bulk); + +MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->replaceOne(NS, ['_id' => 1], ['x' => 11], ['hint' => '_id_']); +$manager->executeBulkWriteCommand($bulk); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->replaceOne(NS, ['_id' => 2], ['x' => 22], ['hint' => ['_id' => 1]]); +$manager->executeBulkWriteCommand($bulk); + +?> +===DONE=== + +--EXPECTF-- +replace included hint: "_id_" +replace included hint: {"_id":1} +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne-008.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne-008.phpt new file mode 100644 index 000000000..d8b23fde5 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne-008.phpt @@ -0,0 +1,81 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() with sort option +--SKIPIF-- + + + + +--FILE-- +getCommandName() !== 'bulkWrite') { + return; + } + + printf("update included sort: %s\n", json_encode($event->getCommand()->ops[0]->sort)); + } + + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void + { + } + + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void + { + } +} + +$manager = create_test_manager(); + +$bulk = new MongoDB\Driver\BulkWriteCommand(); +$bulk->insertOne(NS, ['_id' => 1]); +$bulk->insertOne(NS, ['_id' => 2]); +$bulk->insertOne(NS, ['_id' => 3]); +$manager->executeBulkWriteCommand($bulk); + +MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->replaceOne(NS, ['_id' => ['$gt' => 1]], ['x' => 11], ['sort' => ['_id' => 1]]); +$manager->executeBulkWriteCommand($bulk); + +$bulk = new MongoDB\Driver\BulkWriteCommand; +$bulk->replaceOne(NS, ['_id' => ['$gt' => 1]], ['x' => 22], ['sort' => ['_id' => -1]]); +$manager->executeBulkWriteCommand($bulk); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); + +var_dump($cursor->toArray()); + +?> +===DONE=== + +--EXPECTF-- +update included sort: {"_id":1} +update included sort: {"_id":-1} +array(3) { + [0]=> + object(stdClass)#%d (%d) { + ["_id"]=> + int(1) + } + [1]=> + object(stdClass)#%d (%d) { + ["_id"]=> + int(2) + ["x"]=> + int(11) + } + [2]=> + object(stdClass)#%d (%d) { + ["_id"]=> + int(3) + ["x"]=> + int(22) + } +} +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-003.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-003.phpt new file mode 100644 index 000000000..30141b12b --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-003.phpt @@ -0,0 +1,34 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() with invalid options +--FILE-- +replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => 1]); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => 1]); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['hint' => 1]); +}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "collation" option to be array or object, int given + +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "collation" option to be array or object, int given + +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "hint" option to be string, array, or object, int given +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-004.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-004.phpt new file mode 100644 index 000000000..80210b61f --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-004.phpt @@ -0,0 +1,41 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() with BSON encoding error (invalid UTF-8 string) +--FILE-- +replaceOne(NS, ['x' => "\xc3\x28"], ['x' => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['x' => "\xc3\x28"]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['$set' => ['x' => "\xc3\x28"]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => ['locale' => "\xc3\x28"]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; + +?> +===DONE=== + +--EXPECTF-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "x": %s + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "x": %s + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "$set.x": %s + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +Detected invalid UTF-8 for field path "locale": %s +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-005.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-005.phpt new file mode 100644 index 000000000..53f89960b --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-005.phpt @@ -0,0 +1,76 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() with BSON encoding error (null bytes in keys) +--FILE-- +replaceOne(NS, ["\0" => 1], ['x' => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ["x\0" => 1], ['x' => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ["\0\0\0" => 1], ['x' => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ["\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ["x\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ["\0\0\0" => 1]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => ["\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => ["x\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, ['x' => 1], ['y' => 1], ['collation' => ["\0\0\0" => 1]]); +}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "x". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "x". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "x". + +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +BSON keys cannot contain null bytes. Unexpected null byte after "". +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-006.phpt b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-006.phpt new file mode 100644 index 000000000..c858a1172 --- /dev/null +++ b/tests/bulkwritecommand/bulkwritecommand-replaceOne_error-006.phpt @@ -0,0 +1,31 @@ +--TEST-- +MongoDB\Driver\BulkWriteCommand::replaceOne() prohibits PackedArray for document values +--FILE-- +replaceOne(NS, MongoDB\BSON\PackedArray::fromPHP([]), []); +}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, [], [], ['collation' => MongoDB\BSON\PackedArray::fromPHP([])]); +}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n"; + +echo throws(function() use ($bulk) { + $bulk->replaceOne(NS, [], [], ['hint' => MongoDB\BSON\PackedArray::fromPHP([])]); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +MongoDB\BSON\PackedArray cannot be serialized as a root document +OK: Got MongoDB\Driver\Exception\UnexpectedValueException +MongoDB\BSON\PackedArray cannot be serialized as a root document +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected "hint" option to yield string or document but got "array" +===DONE=== diff --git a/tests/bulkwritecommand/bulkwritecommand-updateOne-002.phpt b/tests/bulkwritecommand/bulkwritecommand-updateMany-002.phpt similarity index 95% rename from tests/bulkwritecommand/bulkwritecommand-updateOne-002.phpt rename to tests/bulkwritecommand/bulkwritecommand-updateMany-002.phpt index 9a5d147e9..948a75780 100644 --- a/tests/bulkwritecommand/bulkwritecommand-updateOne-002.phpt +++ b/tests/bulkwritecommand/bulkwritecommand-updateMany-002.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\Driver\BulkWriteCommand::updateOne() with arrayFilters option +MongoDB\Driver\BulkWriteCommand::updateMany() with arrayFilters option --SKIPIF-- diff --git a/tests/bulkwritecommand/bulkwritecommand-updateOne-003.phpt b/tests/bulkwritecommand/bulkwritecommand-updateMany-003.phpt similarity index 100% rename from tests/bulkwritecommand/bulkwritecommand-updateOne-003.phpt rename to tests/bulkwritecommand/bulkwritecommand-updateMany-003.phpt diff --git a/tests/bulkwritecommand/bulkwritecommand-updateOne-005.phpt b/tests/bulkwritecommand/bulkwritecommand-updateMany-005.phpt similarity index 90% rename from tests/bulkwritecommand/bulkwritecommand-updateOne-005.phpt rename to tests/bulkwritecommand/bulkwritecommand-updateMany-005.phpt index ab01dc0d0..4681b8dd1 100644 --- a/tests/bulkwritecommand/bulkwritecommand-updateOne-005.phpt +++ b/tests/bulkwritecommand/bulkwritecommand-updateMany-005.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\Driver\BulkWriteCommand::updateOne() $filter and $newObj are MongoDB\BSON\Document +MongoDB\Driver\BulkWriteCommand::updateMany() $filter and $newObj are MongoDB\BSON\Document --SKIPIF-- diff --git a/tests/bulkwritecommand/bulkwritecommand-updateOne-007.phpt b/tests/bulkwritecommand/bulkwritecommand-updateMany-007.phpt similarity index 95% rename from tests/bulkwritecommand/bulkwritecommand-updateOne-007.phpt rename to tests/bulkwritecommand/bulkwritecommand-updateMany-007.phpt index 984e1234b..880cd8633 100644 --- a/tests/bulkwritecommand/bulkwritecommand-updateOne-007.phpt +++ b/tests/bulkwritecommand/bulkwritecommand-updateMany-007.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\Driver\BulkWriteCommand::updateOne() PackedArray for arrayFilters option +MongoDB\Driver\BulkWriteCommand::updateMany() PackedArray for arrayFilters option --SKIPIF--