Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7542cba

Browse files
committed
wip BulkWriteCommand tests
1 parent 61912ed commit 7542cba

8 files changed

+773
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommand::__construct() bypassDocumentValidation=true
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' => true]);
26+
$bulk->insertOne(NS, ['_id' => 1]);
27+
28+
$result = $manager->executeBulkWriteCommand($bulk);
29+
30+
var_dump($result);
31+
32+
?>
33+
===DONE===
34+
<?php exit(0); ?>
35+
--EXPECTF--
36+
object(MongoDB\Driver\BulkWriteCommandResult)#%d (%d) {
37+
["isAcknowledged"]=>
38+
bool(true)
39+
["insertedCount"]=>
40+
int(1)
41+
["matchedCount"]=>
42+
int(0)
43+
["modifiedCount"]=>
44+
int(0)
45+
["upsertedCount"]=>
46+
int(0)
47+
["deletedCount"]=>
48+
int(0)
49+
["insertResults"]=>
50+
NULL
51+
["updateResults"]=>
52+
NULL
53+
["deleteResults"]=>
54+
NULL
55+
["writeErrors"]=>
56+
array(0) {
57+
}
58+
["writeConcernErrors"]=>
59+
array(0) {
60+
}
61+
["errorReply"]=>
62+
NULL
63+
["server"]=>
64+
object(MongoDB\Driver\Server)#%d (%d) {%A
65+
}
66+
}
67+
===DONE===
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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===
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommand::__construct() let
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+
$let = [
16+
'targetFlavor' => 'cherry',
17+
'newFlavor' => 'orange',
18+
];
19+
20+
$bulk = new MongoDB\Driver\BulkWriteCommand(['let' => $let]);
21+
22+
$bulk->insertOne(NS, ['_id' => 1, 'flavor' => 'chocolate']);
23+
$bulk->insertOne(NS, ['_id' => 2, 'flavor' => 'strawberry']);
24+
$bulk->insertOne(NS, ['_id' => 3, 'flavor' => 'cherry']);
25+
26+
$bulk->updateMany(
27+
NS,
28+
['$expr' => ['$eq' => ['$flavor', '$$targetFlavor']]],
29+
['$set' => ['flavor' => '$$newFlavor']],
30+
);
31+
32+
$result = $manager->executeBulkWriteCommand($bulk);
33+
34+
var_dump($result);
35+
36+
?>
37+
===DONE===
38+
<?php exit(0); ?>
39+
--EXPECTF--
40+
object(MongoDB\Driver\BulkWriteCommandResult)#%d (%d) {
41+
["isAcknowledged"]=>
42+
bool(true)
43+
["insertedCount"]=>
44+
int(3)
45+
["matchedCount"]=>
46+
int(1)
47+
["modifiedCount"]=>
48+
int(1)
49+
["upsertedCount"]=>
50+
int(0)
51+
["deletedCount"]=>
52+
int(0)
53+
["insertResults"]=>
54+
NULL
55+
["updateResults"]=>
56+
NULL
57+
["deleteResults"]=>
58+
NULL
59+
["writeErrors"]=>
60+
array(0) {
61+
}
62+
["writeConcernErrors"]=>
63+
array(0) {
64+
}
65+
["errorReply"]=>
66+
NULL
67+
["server"]=>
68+
object(MongoDB\Driver\Server)#%d (%d) {%A
69+
}
70+
}
71+
===DONE===
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommand::__construct() ordered=true
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+
$bulk = new MongoDB\Driver\BulkWriteCommand(['ordered' => true]);
16+
$bulk->insertOne(NS, ['_id' => 1]);
17+
$bulk->insertOne(NS, ['_id' => 1]);
18+
$bulk->insertOne(NS, ['_id' => 2]);
19+
20+
try {
21+
$manager->executeBulkWriteCommand($bulk);
22+
} catch (MongoDB\Driver\Exception\BulkWriteCommandException $e) {
23+
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
24+
var_dump($e->getBulkWriteCommandResult());
25+
}
26+
27+
?>
28+
===DONE===
29+
<?php exit(0); ?>
30+
--EXPECTF--
31+
MongoDB\Driver\Exception\BulkWriteCommandException(0): Bulk write failed
32+
object(MongoDB\Driver\BulkWriteCommandResult)#%d (%d) {
33+
["isAcknowledged"]=>
34+
bool(true)
35+
["insertedCount"]=>
36+
int(1)
37+
["matchedCount"]=>
38+
int(0)
39+
["modifiedCount"]=>
40+
int(0)
41+
["upsertedCount"]=>
42+
int(0)
43+
["deletedCount"]=>
44+
int(0)
45+
["insertResults"]=>
46+
NULL
47+
["updateResults"]=>
48+
NULL
49+
["deleteResults"]=>
50+
NULL
51+
["writeErrors"]=>
52+
array(1) {
53+
[1]=>
54+
object(MongoDB\Driver\WriteError)#%d (%d) {
55+
["message"]=>
56+
string(128) "E11000 duplicate key error collection: phongo.bulkwritecommand_bulkwritecommand_ctor_ordered_001 index: _id_ dup key: { _id: 1 }"
57+
["code"]=>
58+
int(11000)
59+
["index"]=>
60+
int(1)
61+
["info"]=>
62+
object(stdClass)#%d (%d) {
63+
}
64+
}
65+
}
66+
["writeConcernErrors"]=>
67+
array(0) {
68+
}
69+
["errorReply"]=>
70+
NULL
71+
["server"]=>
72+
object(MongoDB\Driver\Server)#%d (%d) {%A
73+
}
74+
}
75+
===DONE===

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /