Skip to content

Commit 18bc299

Browse files
committed
PHPC-684: Report bypassDocumentValidation in BulkWrite debug output
1 parent 3ad624e commit 18bc299

File tree

6 files changed

+133
-1
lines changed

6 files changed

+133
-1
lines changed

php_phongo_structs-5.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef struct {
8989
mongoc_bulk_operation_t *bulk;
9090
size_t num_ops;
9191
bool ordered;
92+
int bypass;
9293
char *database;
9394
char *collection;
9495
bool executed;

php_phongo_structs-7.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct {
8888
mongoc_bulk_operation_t *bulk;
8989
size_t num_ops;
9090
bool ordered;
91+
int bypass;
9192
char *database;
9293
char *collection;
9394
bool executed;

src/MongoDB/BulkWrite.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "php_phongo.h"
4747
#include "php_bson.h"
4848

49+
#define BYPASS_UNSET -1
4950

5051
PHONGO_API zend_class_entry *php_phongo_bulkwrite_ce;
5152

@@ -77,10 +78,13 @@ PHP_METHOD(BulkWrite, __construct)
7778

7879
intern->bulk = phongo_bulkwrite_init(ordered);
7980
intern->ordered = ordered;
81+
intern->bypass = BYPASS_UNSET;
8082
intern->num_ops = 0;
8183

8284
if (options && php_array_exists(options, "bypassDocumentValidation")) {
83-
mongoc_bulk_operation_set_bypass_document_validation(intern->bulk, php_array_fetch_bool(options, "bypassDocumentValidation"));
85+
zend_bool bypass = php_array_fetch_bool(options, "bypassDocumentValidation");
86+
mongoc_bulk_operation_set_bypass_document_validation(intern->bulk, bypass);
87+
intern->bypass = bypass;
8488
}
8589
}
8690
/* }}} */
@@ -351,6 +355,13 @@ HashTable *php_phongo_bulkwrite_get_debug_info(zval *object, int *is_temp TSRMLS
351355
}
352356

353357
ADD_ASSOC_BOOL_EX(&retval, "ordered", intern->ordered);
358+
359+
if (intern->bypass != BYPASS_UNSET) {
360+
ADD_ASSOC_BOOL_EX(&retval, "bypassDocumentValidation", intern->bypass);
361+
} else {
362+
ADD_ASSOC_NULL_EX(&retval, "bypassDocumentValidation");
363+
}
364+
354365
ADD_ASSOC_BOOL_EX(&retval, "executed", intern->executed);
355366
ADD_ASSOC_LONG_EX(&retval, "server_id", mongoc_bulk_operation_get_hint(intern->bulk));
356367

tests/bulk/bulkwrite-debug-001.phpt

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWrite debug output before execution
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$tests = [
10+
[],
11+
['ordered' => true],
12+
['ordered' => false],
13+
['bypassDocumentValidation' => true],
14+
['bypassDocumentValidation' => false],
15+
];
16+
17+
foreach ($tests as $options) {
18+
var_dump(new MongoDB\Driver\BulkWrite($options));
19+
}
20+
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECTF--
25+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
26+
["database"]=>
27+
NULL
28+
["collection"]=>
29+
NULL
30+
["ordered"]=>
31+
bool(true)
32+
["bypassDocumentValidation"]=>
33+
NULL
34+
["executed"]=>
35+
bool(false)
36+
["server_id"]=>
37+
int(0)
38+
["write_concern"]=>
39+
NULL
40+
}
41+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
42+
["database"]=>
43+
NULL
44+
["collection"]=>
45+
NULL
46+
["ordered"]=>
47+
bool(true)
48+
["bypassDocumentValidation"]=>
49+
NULL
50+
["executed"]=>
51+
bool(false)
52+
["server_id"]=>
53+
int(0)
54+
["write_concern"]=>
55+
NULL
56+
}
57+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
58+
["database"]=>
59+
NULL
60+
["collection"]=>
61+
NULL
62+
["ordered"]=>
63+
bool(false)
64+
["bypassDocumentValidation"]=>
65+
NULL
66+
["executed"]=>
67+
bool(false)
68+
["server_id"]=>
69+
int(0)
70+
["write_concern"]=>
71+
NULL
72+
}
73+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
74+
["database"]=>
75+
NULL
76+
["collection"]=>
77+
NULL
78+
["ordered"]=>
79+
bool(true)
80+
["bypassDocumentValidation"]=>
81+
bool(true)
82+
["executed"]=>
83+
bool(false)
84+
["server_id"]=>
85+
int(0)
86+
["write_concern"]=>
87+
NULL
88+
}
89+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
90+
["database"]=>
91+
NULL
92+
["collection"]=>
93+
NULL
94+
["ordered"]=>
95+
bool(true)
96+
["bypassDocumentValidation"]=>
97+
bool(false)
98+
["executed"]=>
99+
bool(false)
100+
["server_id"]=>
101+
int(0)
102+
["write_concern"]=>
103+
NULL
104+
}
105+
===DONE===

tests/bulk/write-0001.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
4545
NULL
4646
["ordered"]=>
4747
bool(true)
48+
["bypassDocumentValidation"]=>
49+
NULL
4850
["executed"]=>
4951
bool(false)
5052
["server_id"]=>
@@ -59,6 +61,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
5961
NULL
6062
["ordered"]=>
6163
bool(true)
64+
["bypassDocumentValidation"]=>
65+
NULL
6266
["executed"]=>
6367
bool(false)
6468
["server_id"]=>
@@ -73,6 +77,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
7377
NULL
7478
["ordered"]=>
7579
bool(true)
80+
["bypassDocumentValidation"]=>
81+
NULL
7682
["executed"]=>
7783
bool(false)
7884
["server_id"]=>
@@ -87,6 +93,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
8793
NULL
8894
["ordered"]=>
8995
bool(true)
96+
["bypassDocumentValidation"]=>
97+
NULL
9098
["executed"]=>
9199
bool(false)
92100
["server_id"]=>
@@ -101,6 +109,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
101109
string(15) "bulk_write_0001"
102110
["ordered"]=>
103111
bool(true)
112+
["bypassDocumentValidation"]=>
113+
NULL
104114
["executed"]=>
105115
bool(true)
106116
["server_id"]=>

tests/bulk/write-0002.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
4141
NULL
4242
["ordered"]=>
4343
bool(true)
44+
["bypassDocumentValidation"]=>
45+
NULL
4446
["executed"]=>
4547
bool(false)
4648
["server_id"]=>
@@ -55,6 +57,8 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
5557
string(15) "bulk_write_0002"
5658
["ordered"]=>
5759
bool(true)
60+
["bypassDocumentValidation"]=>
61+
NULL
5862
["executed"]=>
5963
bool(true)
6064
["server_id"]=>

0 commit comments

Comments
 (0)