|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\BulkWriteCommand::deleteOne() should always encode __pclass for Persistable objects |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php skip_if_not_live(); ?> |
| 6 | +<?php skip_if_server_version('<', '8.0'); ?> |
| 7 | +<?php skip_if_not_clean(); ?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 11 | + |
| 12 | +class MyClass implements MongoDB\BSON\Persistable |
| 13 | +{ |
| 14 | + private $id; |
| 15 | + private $child; |
| 16 | + |
| 17 | + public function __construct($id, ?MyClass $child = null) |
| 18 | + { |
| 19 | + $this->id = $id; |
| 20 | + $this->child = $child; |
| 21 | + } |
| 22 | + |
| 23 | + public function bsonSerialize(): array |
| 24 | + { |
| 25 | + return [ |
| 26 | + '_id' => $this->id, |
| 27 | + 'child' => $this->child, |
| 28 | + ]; |
| 29 | + } |
| 30 | + |
| 31 | + public function bsonUnserialize(array $data): void |
| 32 | + { |
| 33 | + $this->id = $data['_id']; |
| 34 | + $this->child = $data['child']; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +$manager = create_test_manager(); |
| 39 | + |
| 40 | +$document = new MyClass('foo', new MyClass('bar', new MyClass('baz'))); |
| 41 | + |
| 42 | +$bulk = new MongoDB\Driver\BulkWriteCommand(); |
| 43 | +$bulk->insertOne(NS, $document); |
| 44 | +$result = $manager->executeBulkWriteCommand($bulk); |
| 45 | +printf("Inserted %d document(s)\n", $result->getInsertedCount()); |
| 46 | + |
| 47 | +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); |
| 48 | +var_dump($cursor->toArray()); |
| 49 | + |
| 50 | +$bulk = new MongoDB\Driver\BulkWriteCommand(); |
| 51 | +$bulk->deleteOne(NS, $document); |
| 52 | +$result = $manager->executeBulkWriteCommand($bulk); |
| 53 | +printf("Deleted %d document(s)\n", $result->getDeletedCount()); |
| 54 | + |
| 55 | +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); |
| 56 | +var_dump($cursor->toArray()); |
| 57 | + |
| 58 | +?> |
| 59 | +===DONE=== |
| 60 | +<?php exit(0); ?> |
| 61 | +--EXPECTF-- |
| 62 | +Inserted 1 document(s) |
| 63 | +array(1) { |
| 64 | + [0]=> |
| 65 | + object(MyClass)#%d (%d) { |
| 66 | + ["id":"MyClass":private]=> |
| 67 | + string(3) "foo" |
| 68 | + ["child":"MyClass":private]=> |
| 69 | + object(MyClass)#%d (%d) { |
| 70 | + ["id":"MyClass":private]=> |
| 71 | + string(3) "bar" |
| 72 | + ["child":"MyClass":private]=> |
| 73 | + object(MyClass)#%d (%d) { |
| 74 | + ["id":"MyClass":private]=> |
| 75 | + string(3) "baz" |
| 76 | + ["child":"MyClass":private]=> |
| 77 | + NULL |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +Deleted 1 document(s) |
| 83 | +array(0) { |
| 84 | +} |
| 85 | +===DONE=== |
0 commit comments