|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\BulkWriteCommand::__construct() bypassDocumentValidation=false |
| 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 | + |
| 11 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 12 | + |
| 13 | +$manager = create_test_manager(); |
| 14 | + |
| 15 | +$manager->executeWriteCommand(DATABASE_NAME, new MongoDB\Driver\Command([ |
| 16 | + 'create' => COLLECTION_NAME, |
| 17 | + 'validator' => [ |
| 18 | + '$jsonSchema' => [ |
| 19 | + 'bsonType' => 'object', |
| 20 | + 'required' => ['x'], |
| 21 | + ], |
| 22 | + ], |
| 23 | +])); |
| 24 | + |
| 25 | +$bulk = new MongoDB\Driver\BulkWriteCommand(['bypassDocumentValidation' => false]); |
| 26 | +/* Include a successful write operation to ensure that mongoc_bulkwriteresult_t |
| 27 | + * is populated (CDRIVER-5856). */ |
| 28 | +$bulk->insertOne(NS, ['_id' => 1, 'x' => 1]); |
| 29 | +$bulk->insertOne(NS, ['_id' => 2]); |
| 30 | + |
| 31 | +try { |
| 32 | + $manager->executeBulkWriteCommand($bulk); |
| 33 | +} catch (MongoDB\Driver\Exception\BulkWriteCommandException $e) { |
| 34 | + printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage()); |
| 35 | + var_dump($e->getBulkWriteCommandResult()); |
| 36 | +} |
| 37 | + |
| 38 | +?> |
| 39 | +===DONE=== |
| 40 | +<?php exit(0); ?> |
| 41 | +--EXPECTF-- |
| 42 | +MongoDB\Driver\Exception\BulkWriteCommandException(0): Bulk write failed |
| 43 | +object(MongoDB\Driver\BulkWriteCommandResult)#%d (%d) { |
| 44 | + ["isAcknowledged"]=> |
| 45 | + bool(true) |
| 46 | + ["insertedCount"]=> |
| 47 | + int(1) |
| 48 | + ["matchedCount"]=> |
| 49 | + int(0) |
| 50 | + ["modifiedCount"]=> |
| 51 | + int(0) |
| 52 | + ["upsertedCount"]=> |
| 53 | + int(0) |
| 54 | + ["deletedCount"]=> |
| 55 | + int(0) |
| 56 | + ["insertResults"]=> |
| 57 | + NULL |
| 58 | + ["updateResults"]=> |
| 59 | + NULL |
| 60 | + ["deleteResults"]=> |
| 61 | + NULL |
| 62 | + ["writeErrors"]=> |
| 63 | + array(1) { |
| 64 | + [1]=> |
| 65 | + object(MongoDB\Driver\WriteError)#%d (%d) { |
| 66 | + ["message"]=> |
| 67 | + string(26) "Document failed validation" |
| 68 | + ["code"]=> |
| 69 | + int(121) |
| 70 | + ["index"]=> |
| 71 | + int(1) |
| 72 | + ["info"]=> |
| 73 | + object(stdClass)#%d (%d) { |
| 74 | + ["failingDocumentId"]=> |
| 75 | + int(2) |
| 76 | + ["details"]=> |
| 77 | + object(stdClass)#%d (%d) { |
| 78 | + ["operatorName"]=> |
| 79 | + string(11) "$jsonSchema" |
| 80 | + ["schemaRulesNotSatisfied"]=> |
| 81 | + array(1) { |
| 82 | + [0]=> |
| 83 | + object(stdClass)#%d (%d) { |
| 84 | + ["operatorName"]=> |
| 85 | + string(8) "required" |
| 86 | + ["specifiedAs"]=> |
| 87 | + object(stdClass)#%d (%d) { |
| 88 | + ["required"]=> |
| 89 | + array(1) { |
| 90 | + [0]=> |
| 91 | + string(1) "x" |
| 92 | + } |
| 93 | + } |
| 94 | + ["missingProperties"]=> |
| 95 | + array(1) { |
| 96 | + [0]=> |
| 97 | + string(1) "x" |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + ["writeConcernErrors"]=> |
| 106 | + array(0) { |
| 107 | + } |
| 108 | + ["errorReply"]=> |
| 109 | + NULL |
| 110 | + ["server"]=> |
| 111 | + object(MongoDB\Driver\Server)#%d (%d) {%A |
| 112 | + } |
| 113 | +} |
| 114 | +===DONE=== |
0 commit comments