Skip to content

Commit b72b6c0

Browse files
committed
PHPLIB-539: Sync CRUD spec tests
1 parent f6727da commit b72b6c0

File tree

40 files changed

+5274
-3
lines changed

40 files changed

+5274
-3
lines changed

src/Operation/Delete.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Delete implements Executable, Explainable
4545
private static $wireVersionForCollation = 5;
4646

4747
/** @var int */
48-
private static $wireVersionForHint = 9;
48+
private static $wireVersionForHintServerSideError = 5;
4949

5050
/** @var string */
5151
private $databaseName;
@@ -145,7 +145,10 @@ public function execute(Server $server)
145145
throw UnsupportedException::collationNotSupported();
146146
}
147147

148-
if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHint)) {
148+
/* Server versions >= 3.4.0 raise errors for unknown update
149+
* options. For previous versions, the CRUD spec requires a client-side
150+
* error. */
151+
if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHintServerSideError)) {
149152
throw UnsupportedException::hintNotSupported();
150153
}
151154

tests/SpecTests/CrudSpecTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testCrud(stdClass $test, array $runOn = null, array $data, $data
7373
}
7474

7575
if (isset($test->expectations)) {
76-
$commandExpectations = CommandExpectations::fromCrud($test->expectations);
76+
$commandExpectations = CommandExpectations::fromCrud((array) $test->expectations);
7777
$commandExpectations->startMonitoring();
7878
}
7979

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"runOn": [
3+
{
4+
"maxServerVersion": "3.3.99"
5+
}
6+
],
7+
"data": [
8+
{
9+
"_id": 1,
10+
"x": 11
11+
},
12+
{
13+
"_id": 2,
14+
"x": 22
15+
},
16+
{
17+
"_id": 3,
18+
"x": 33
19+
},
20+
{
21+
"_id": 4,
22+
"x": 44
23+
}
24+
],
25+
"collection_name": "BulkWrite_delete_hint",
26+
"tests": [
27+
{
28+
"description": "BulkWrite deleteOne with hints unsupported (client-side error)",
29+
"operations": [
30+
{
31+
"name": "bulkWrite",
32+
"arguments": {
33+
"requests": [
34+
{
35+
"name": "deleteOne",
36+
"arguments": {
37+
"filter": {
38+
"_id": 1
39+
},
40+
"hint": "_id_"
41+
}
42+
},
43+
{
44+
"name": "deleteOne",
45+
"arguments": {
46+
"filter": {
47+
"_id": 2
48+
},
49+
"hint": {
50+
"_id": 1
51+
}
52+
}
53+
}
54+
],
55+
"options": {
56+
"ordered": true
57+
}
58+
},
59+
"error": true
60+
}
61+
],
62+
"expectations": [],
63+
"outcome": {
64+
"collection": {
65+
"data": [
66+
{
67+
"_id": 1,
68+
"x": 11
69+
},
70+
{
71+
"_id": 2,
72+
"x": 22
73+
},
74+
{
75+
"_id": 3,
76+
"x": 33
77+
},
78+
{
79+
"_id": 4,
80+
"x": 44
81+
}
82+
]
83+
}
84+
}
85+
},
86+
{
87+
"description": "BulkWrite deleteMany with hints unsupported (client-side error)",
88+
"operations": [
89+
{
90+
"name": "bulkWrite",
91+
"arguments": {
92+
"requests": [
93+
{
94+
"name": "deleteMany",
95+
"arguments": {
96+
"filter": {
97+
"_id": {
98+
"$lt": 3
99+
}
100+
},
101+
"hint": "_id_"
102+
}
103+
},
104+
{
105+
"name": "deleteMany",
106+
"arguments": {
107+
"filter": {
108+
"_id": {
109+
"$gte": 4
110+
}
111+
},
112+
"hint": {
113+
"_id": 1
114+
}
115+
}
116+
}
117+
],
118+
"options": {
119+
"ordered": true
120+
}
121+
},
122+
"error": true
123+
}
124+
],
125+
"expectations": [],
126+
"outcome": {
127+
"collection": {
128+
"data": [
129+
{
130+
"_id": 1,
131+
"x": 11
132+
},
133+
{
134+
"_id": 2,
135+
"x": 22
136+
},
137+
{
138+
"_id": 3,
139+
"x": 33
140+
},
141+
{
142+
"_id": 4,
143+
"x": 44
144+
}
145+
]
146+
}
147+
}
148+
}
149+
]
150+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "3.4.0",
5+
"maxServerVersion": "4.3.3"
6+
}
7+
],
8+
"data": [
9+
{
10+
"_id": 1,
11+
"x": 11
12+
},
13+
{
14+
"_id": 2,
15+
"x": 22
16+
},
17+
{
18+
"_id": 3,
19+
"x": 33
20+
},
21+
{
22+
"_id": 4,
23+
"x": 44
24+
}
25+
],
26+
"collection_name": "BulkWrite_delete_hint",
27+
"tests": [
28+
{
29+
"description": "BulkWrite deleteOne with hints unsupported (server-side error)",
30+
"operations": [
31+
{
32+
"name": "bulkWrite",
33+
"arguments": {
34+
"requests": [
35+
{
36+
"name": "deleteOne",
37+
"arguments": {
38+
"filter": {
39+
"_id": 1
40+
},
41+
"hint": "_id_"
42+
}
43+
},
44+
{
45+
"name": "deleteOne",
46+
"arguments": {
47+
"filter": {
48+
"_id": 2
49+
},
50+
"hint": {
51+
"_id": 1
52+
}
53+
}
54+
}
55+
],
56+
"options": {
57+
"ordered": true
58+
}
59+
},
60+
"error": true
61+
}
62+
],
63+
"expectations": [
64+
{
65+
"command_started_event": {
66+
"command": {
67+
"delete": "BulkWrite_delete_hint",
68+
"deletes": [
69+
{
70+
"q": {
71+
"_id": 1
72+
},
73+
"hint": "_id_",
74+
"limit": 1
75+
},
76+
{
77+
"q": {
78+
"_id": 2
79+
},
80+
"hint": {
81+
"_id": 1
82+
},
83+
"limit": 1
84+
}
85+
],
86+
"ordered": true
87+
}
88+
}
89+
}
90+
],
91+
"outcome": {
92+
"collection": {
93+
"data": [
94+
{
95+
"_id": 1,
96+
"x": 11
97+
},
98+
{
99+
"_id": 2,
100+
"x": 22
101+
},
102+
{
103+
"_id": 3,
104+
"x": 33
105+
},
106+
{
107+
"_id": 4,
108+
"x": 44
109+
}
110+
]
111+
}
112+
}
113+
},
114+
{
115+
"description": "BulkWrite deleteMany with hints unsupported (server-side error)",
116+
"operations": [
117+
{
118+
"name": "bulkWrite",
119+
"arguments": {
120+
"requests": [
121+
{
122+
"name": "deleteMany",
123+
"arguments": {
124+
"filter": {
125+
"_id": {
126+
"$lt": 3
127+
}
128+
},
129+
"hint": "_id_"
130+
}
131+
},
132+
{
133+
"name": "deleteMany",
134+
"arguments": {
135+
"filter": {
136+
"_id": {
137+
"$gte": 4
138+
}
139+
},
140+
"hint": {
141+
"_id": 1
142+
}
143+
}
144+
}
145+
],
146+
"options": {
147+
"ordered": true
148+
}
149+
},
150+
"error": true
151+
}
152+
],
153+
"expectations": [
154+
{
155+
"command_started_event": {
156+
"command": {
157+
"delete": "BulkWrite_delete_hint",
158+
"deletes": [
159+
{
160+
"q": {
161+
"_id": {
162+
"$lt": 3
163+
}
164+
},
165+
"hint": "_id_",
166+
"limit": 0
167+
},
168+
{
169+
"q": {
170+
"_id": {
171+
"$gte": 4
172+
}
173+
},
174+
"hint": {
175+
"_id": 1
176+
},
177+
"limit": 0
178+
}
179+
],
180+
"ordered": true
181+
}
182+
}
183+
}
184+
],
185+
"outcome": {
186+
"collection": {
187+
"data": [
188+
{
189+
"_id": 1,
190+
"x": 11
191+
},
192+
{
193+
"_id": 2,
194+
"x": 22
195+
},
196+
{
197+
"_id": 3,
198+
"x": 33
199+
},
200+
{
201+
"_id": 4,
202+
"x": 44
203+
}
204+
]
205+
}
206+
}
207+
}
208+
]
209+
}

0 commit comments

Comments
 (0)