Skip to content

Commit 8149880

Browse files
committed
PHPC-2571 Import BulkWrite tests for Client BulkWriteCommand
1 parent 3929480 commit 8149880

35 files changed

+1883
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWrite debug output before execution
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+
$tests = [
12+
[],
13+
['ordered' => true],
14+
['ordered' => false],
15+
['bypassDocumentValidation' => true],
16+
['bypassDocumentValidation' => false],
17+
['comment' => ['foo' => 1]],
18+
['let' => ['id' => 1, 'x' => 'foo']],
19+
];
20+
21+
foreach ($tests as $options) {
22+
var_dump(new MongoDB\Driver\BulkWriteCommand($options));
23+
}
24+
25+
?>
26+
===DONE===
27+
<?php exit(0); ?>
28+
--EXPECTF--
29+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
30+
["database"]=>
31+
NULL
32+
["collection"]=>
33+
NULL
34+
["ordered"]=>
35+
bool(true)
36+
["bypassDocumentValidation"]=>
37+
NULL
38+
["executed"]=>
39+
bool(false)
40+
["server_id"]=>
41+
int(0)
42+
["session"]=>
43+
NULL
44+
["write_concern"]=>
45+
NULL
46+
}
47+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
48+
["database"]=>
49+
NULL
50+
["collection"]=>
51+
NULL
52+
["ordered"]=>
53+
bool(true)
54+
["bypassDocumentValidation"]=>
55+
NULL
56+
["executed"]=>
57+
bool(false)
58+
["server_id"]=>
59+
int(0)
60+
["session"]=>
61+
NULL
62+
["write_concern"]=>
63+
NULL
64+
}
65+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
66+
["database"]=>
67+
NULL
68+
["collection"]=>
69+
NULL
70+
["ordered"]=>
71+
bool(false)
72+
["bypassDocumentValidation"]=>
73+
NULL
74+
["executed"]=>
75+
bool(false)
76+
["server_id"]=>
77+
int(0)
78+
["session"]=>
79+
NULL
80+
["write_concern"]=>
81+
NULL
82+
}
83+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
84+
["database"]=>
85+
NULL
86+
["collection"]=>
87+
NULL
88+
["ordered"]=>
89+
bool(true)
90+
["bypassDocumentValidation"]=>
91+
bool(true)
92+
["executed"]=>
93+
bool(false)
94+
["server_id"]=>
95+
int(0)
96+
["session"]=>
97+
NULL
98+
["write_concern"]=>
99+
NULL
100+
}
101+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
102+
["database"]=>
103+
NULL
104+
["collection"]=>
105+
NULL
106+
["ordered"]=>
107+
bool(true)
108+
["bypassDocumentValidation"]=>
109+
bool(false)
110+
["executed"]=>
111+
bool(false)
112+
["server_id"]=>
113+
int(0)
114+
["session"]=>
115+
NULL
116+
["write_concern"]=>
117+
NULL
118+
}
119+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
120+
["database"]=>
121+
NULL
122+
["collection"]=>
123+
NULL
124+
["ordered"]=>
125+
bool(true)
126+
["bypassDocumentValidation"]=>
127+
NULL
128+
["comment"]=>
129+
object(stdClass)#%d (%d) {
130+
["foo"]=>
131+
int(1)
132+
}
133+
["executed"]=>
134+
bool(false)
135+
["server_id"]=>
136+
int(0)
137+
["session"]=>
138+
NULL
139+
["write_concern"]=>
140+
NULL
141+
}
142+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
143+
["database"]=>
144+
NULL
145+
["collection"]=>
146+
NULL
147+
["ordered"]=>
148+
bool(true)
149+
["bypassDocumentValidation"]=>
150+
NULL
151+
["let"]=>
152+
object(stdClass)#%d (%d) {
153+
["id"]=>
154+
int(1)
155+
["x"]=>
156+
string(3) "foo"
157+
}
158+
["executed"]=>
159+
bool(false)
160+
["server_id"]=>
161+
int(0)
162+
["session"]=>
163+
NULL
164+
["write_concern"]=>
165+
NULL
166+
}
167+
===DONE===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWrite debug output after execution
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+
$manager = create_test_manager();
13+
14+
$tests = [
15+
[],
16+
['session' => $manager->startSession()],
17+
];
18+
19+
foreach ($tests as $options) {
20+
$bulk = new MongoDB\Driver\BulkWriteCommand();
21+
$bulk->insertOne(NS, ['foo' => 'bar']);
22+
$manager->executeBulkWriteCommand($bulk, $options);
23+
var_dump($bulk);
24+
}
25+
26+
?>
27+
===DONE===
28+
<?php exit(0); ?>
29+
--EXPECTF--
30+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
31+
["database"]=>
32+
%s
33+
["collection"]=>
34+
%s
35+
["ordered"]=>
36+
bool(true)
37+
["bypassDocumentValidation"]=>
38+
NULL
39+
["executed"]=>
40+
bool(true)
41+
["server_id"]=>
42+
int(%d)
43+
["session"]=>
44+
NULL
45+
["write_concern"]=>
46+
NULL
47+
}
48+
object(MongoDB\Driver\BulkWrite)#%d (%d) {
49+
["database"]=>
50+
%s
51+
["collection"]=>
52+
%s
53+
["ordered"]=>
54+
bool(true)
55+
["bypassDocumentValidation"]=>
56+
NULL
57+
["executed"]=>
58+
bool(true)
59+
["server_id"]=>
60+
int(%d)
61+
["session"]=>
62+
object(MongoDB\Driver\Session)#%d (%d) {
63+
%a
64+
}
65+
["write_concern"]=>
66+
NULL
67+
}
68+
===DONE===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommand::insertOne() 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+
$bulk = new MongoDB\Driver\BulkWriteCommand();
41+
$bulk->insertOne(NS, new MyClass('foo', new MyClass('bar', new MyClass('baz'))));
42+
$result = $manager->executeBulkWriteCommand($bulk);
43+
printf("Inserted %d document(s)\n", $result->getInsertedCount());
44+
45+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([]));
46+
var_dump($cursor->toArray());
47+
48+
?>
49+
===DONE===
50+
<?php exit(0); ?>
51+
--EXPECTF--
52+
Inserted 1 document(s)
53+
array(1) {
54+
[0]=>
55+
object(MyClass)#%d (%d) {
56+
["id":"MyClass":private]=>
57+
string(3) "foo"
58+
["child":"MyClass":private]=>
59+
object(MyClass)#%d (%d) {
60+
["id":"MyClass":private]=>
61+
string(3) "bar"
62+
["child":"MyClass":private]=>
63+
object(MyClass)#%d (%d) {
64+
["id":"MyClass":private]=>
65+
string(3) "baz"
66+
["child":"MyClass":private]=>
67+
NULL
68+
}
69+
}
70+
}
71+
}
72+
===DONE===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommand::insertOne() $document is MongoDB\BSON\Document
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+
$document = MongoDB\BSON\Document::fromJSON('{ "_id": 2 }');
16+
17+
$bulk = new MongoDB\Driver\BulkWriteCommand();
18+
$insertedId = $bulk->insertOne(NS, $document);
19+
$result = $manager->executeBulkWriteCommand($bulk);
20+
21+
var_dump($insertedId);
22+
var_dump($result->getInsertedCount());
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
int(2)
29+
int(1)
30+
===DONE===

0 commit comments

Comments
 (0)