Skip to content

Commit 557ed02

Browse files
committed
PHPC-146: ReadPreferences swapped
1 parent fd8dbed commit 557ed02

File tree

3 files changed

+363
-3
lines changed

3 files changed

+363
-3
lines changed

src/MongoDB/ReadPreference.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ PHP_MINIT_FUNCTION(ReadPreference)
173173
php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info;
174174

175175
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY"), MONGOC_READ_PRIMARY TSRMLS_CC);
176-
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY_PREFERRED"), MONGOC_READ_SECONDARY TSRMLS_CC);
177-
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY"), MONGOC_READ_PRIMARY_PREFERRED TSRMLS_CC);
176+
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY_PREFERRED"), MONGOC_READ_PRIMARY_PREFERRED TSRMLS_CC);
177+
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY"), MONGOC_READ_SECONDARY TSRMLS_CC);
178178
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY_PREFERRED"), MONGOC_READ_SECONDARY_PREFERRED TSRMLS_CC);
179179
zend_declare_class_constant_long(php_phongo_readpreference_ce, ZEND_STRL("RP_NEAREST"), MONGOC_READ_NEAREST TSRMLS_CC);
180180

tests/readPreference/001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object(MongoDB\Driver\ReadPreference)#%d (%d) {
3939
}
4040
object(MongoDB\Driver\ReadPreference)#%d (%d) {
4141
["mode"]=>
42-
int(5)
42+
int(2)
4343
["tags"]=>
4444
array(1) {
4545
["tag"]=>

tests/readPreference/002.phpt

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
--TEST--
2+
MongoDB\Driver\ReadPreference#002: PHPC-146
3+
--SKIPIF--
4+
<?php require "tests/utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once "tests/utils/basic.inc";
8+
9+
$mc = new MongoDB\Driver\Manager(MONGODB_URI);
10+
$mc->executeInsert(NS, array("my" => "document"));
11+
$rps = array(
12+
MongoDB\Driver\ReadPreference::RP_PRIMARY,
13+
MongoDB\Driver\ReadPreference::RP_PRIMARY_PREFERRED,
14+
MongoDB\Driver\ReadPreference::RP_SECONDARY,
15+
MongoDB\Driver\ReadPreference::RP_SECONDARY_PREFERRED,
16+
MongoDB\Driver\ReadPreference::RP_NEAREST,
17+
);
18+
foreach($rps as $r) {
19+
$rp = new MongoDB\Driver\ReadPreference($r);
20+
$cursor = $mc->executeQuery(NS, new MongoDB\Driver\Query(array("my" => "query")), $rp);
21+
var_dump($cursor);
22+
}
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECTF--
28+
object(MongoDB\Driver\QueryResult)#%d (%d) {
29+
["cursor"]=>
30+
array(18) {
31+
["stamp"]=>
32+
int(0)
33+
["is_command"]=>
34+
bool(false)
35+
["sent"]=>
36+
bool(true)
37+
["done"]=>
38+
bool(true)
39+
["failed"]=>
40+
bool(false)
41+
["end_of_event"]=>
42+
bool(true)
43+
["in_exhaust"]=>
44+
bool(false)
45+
["redir_primary"]=>
46+
bool(false)
47+
["has_fields"]=>
48+
bool(false)
49+
["query"]=>
50+
array(1) {
51+
["$query"]=>
52+
object(stdClass)#%d (%d) {
53+
["my"]=>
54+
string(5) "query"
55+
}
56+
}
57+
["fields"]=>
58+
array(0) {
59+
}
60+
["read_preference"]=>
61+
array(2) {
62+
["mode"]=>
63+
int(1)
64+
["tags"]=>
65+
array(0) {
66+
}
67+
}
68+
["flags"]=>
69+
int(0)
70+
["skip"]=>
71+
int(0)
72+
["limit"]=>
73+
int(0)
74+
["count"]=>
75+
int(1)
76+
["batch_size"]=>
77+
int(0)
78+
["ns"]=>
79+
string(25) "phongo.readPreference_002"
80+
}
81+
["firstBatch"]=>
82+
NULL
83+
["hint"]=>
84+
int(1)
85+
["is_command_cursor"]=>
86+
bool(false)
87+
}
88+
object(MongoDB\Driver\QueryResult)#%d (%d) {
89+
["cursor"]=>
90+
array(18) {
91+
["stamp"]=>
92+
int(0)
93+
["is_command"]=>
94+
bool(false)
95+
["sent"]=>
96+
bool(true)
97+
["done"]=>
98+
bool(true)
99+
["failed"]=>
100+
bool(false)
101+
["end_of_event"]=>
102+
bool(true)
103+
["in_exhaust"]=>
104+
bool(false)
105+
["redir_primary"]=>
106+
bool(false)
107+
["has_fields"]=>
108+
bool(false)
109+
["query"]=>
110+
array(2) {
111+
["$query"]=>
112+
object(stdClass)#%d (%d) {
113+
["my"]=>
114+
string(5) "query"
115+
}
116+
["$readPreference"]=>
117+
object(stdClass)#%d (%d) {
118+
["mode"]=>
119+
string(16) "primaryPreferred"
120+
["tags"]=>
121+
array(0) {
122+
}
123+
}
124+
}
125+
["fields"]=>
126+
array(0) {
127+
}
128+
["read_preference"]=>
129+
array(2) {
130+
["mode"]=>
131+
int(5)
132+
["tags"]=>
133+
array(0) {
134+
}
135+
}
136+
["flags"]=>
137+
int(0)
138+
["skip"]=>
139+
int(0)
140+
["limit"]=>
141+
int(0)
142+
["count"]=>
143+
int(1)
144+
["batch_size"]=>
145+
int(0)
146+
["ns"]=>
147+
string(25) "phongo.readPreference_002"
148+
}
149+
["firstBatch"]=>
150+
NULL
151+
["hint"]=>
152+
int(1)
153+
["is_command_cursor"]=>
154+
bool(false)
155+
}
156+
object(MongoDB\Driver\QueryResult)#%d (%d) {
157+
["cursor"]=>
158+
array(18) {
159+
["stamp"]=>
160+
int(0)
161+
["is_command"]=>
162+
bool(false)
163+
["sent"]=>
164+
bool(true)
165+
["done"]=>
166+
bool(true)
167+
["failed"]=>
168+
bool(false)
169+
["end_of_event"]=>
170+
bool(true)
171+
["in_exhaust"]=>
172+
bool(false)
173+
["redir_primary"]=>
174+
bool(false)
175+
["has_fields"]=>
176+
bool(false)
177+
["query"]=>
178+
array(2) {
179+
["$query"]=>
180+
object(stdClass)#%d (%d) {
181+
["my"]=>
182+
string(5) "query"
183+
}
184+
["$readPreference"]=>
185+
object(stdClass)#%d (%d) {
186+
["mode"]=>
187+
string(9) "secondary"
188+
["tags"]=>
189+
array(0) {
190+
}
191+
}
192+
}
193+
["fields"]=>
194+
array(0) {
195+
}
196+
["read_preference"]=>
197+
array(2) {
198+
["mode"]=>
199+
int(2)
200+
["tags"]=>
201+
array(0) {
202+
}
203+
}
204+
["flags"]=>
205+
int(0)
206+
["skip"]=>
207+
int(0)
208+
["limit"]=>
209+
int(0)
210+
["count"]=>
211+
int(1)
212+
["batch_size"]=>
213+
int(0)
214+
["ns"]=>
215+
string(25) "phongo.readPreference_002"
216+
}
217+
["firstBatch"]=>
218+
NULL
219+
["hint"]=>
220+
int(1)
221+
["is_command_cursor"]=>
222+
bool(false)
223+
}
224+
object(MongoDB\Driver\QueryResult)#%d (%d) {
225+
["cursor"]=>
226+
array(18) {
227+
["stamp"]=>
228+
int(0)
229+
["is_command"]=>
230+
bool(false)
231+
["sent"]=>
232+
bool(true)
233+
["done"]=>
234+
bool(true)
235+
["failed"]=>
236+
bool(false)
237+
["end_of_event"]=>
238+
bool(true)
239+
["in_exhaust"]=>
240+
bool(false)
241+
["redir_primary"]=>
242+
bool(false)
243+
["has_fields"]=>
244+
bool(false)
245+
["query"]=>
246+
array(2) {
247+
["$query"]=>
248+
object(stdClass)#%d (%d) {
249+
["my"]=>
250+
string(5) "query"
251+
}
252+
["$readPreference"]=>
253+
object(stdClass)#%d (%d) {
254+
["mode"]=>
255+
string(18) "secondaryPreferred"
256+
["tags"]=>
257+
array(0) {
258+
}
259+
}
260+
}
261+
["fields"]=>
262+
array(0) {
263+
}
264+
["read_preference"]=>
265+
array(2) {
266+
["mode"]=>
267+
int(6)
268+
["tags"]=>
269+
array(0) {
270+
}
271+
}
272+
["flags"]=>
273+
int(0)
274+
["skip"]=>
275+
int(0)
276+
["limit"]=>
277+
int(0)
278+
["count"]=>
279+
int(1)
280+
["batch_size"]=>
281+
int(0)
282+
["ns"]=>
283+
string(25) "phongo.readPreference_002"
284+
}
285+
["firstBatch"]=>
286+
NULL
287+
["hint"]=>
288+
int(1)
289+
["is_command_cursor"]=>
290+
bool(false)
291+
}
292+
object(MongoDB\Driver\QueryResult)#%d (%d) {
293+
["cursor"]=>
294+
array(18) {
295+
["stamp"]=>
296+
int(0)
297+
["is_command"]=>
298+
bool(false)
299+
["sent"]=>
300+
bool(true)
301+
["done"]=>
302+
bool(true)
303+
["failed"]=>
304+
bool(false)
305+
["end_of_event"]=>
306+
bool(true)
307+
["in_exhaust"]=>
308+
bool(false)
309+
["redir_primary"]=>
310+
bool(false)
311+
["has_fields"]=>
312+
bool(false)
313+
["query"]=>
314+
array(2) {
315+
["$query"]=>
316+
object(stdClass)#%d (%d) {
317+
["my"]=>
318+
string(5) "query"
319+
}
320+
["$readPreference"]=>
321+
object(stdClass)#%d (%d) {
322+
["mode"]=>
323+
string(7) "nearest"
324+
["tags"]=>
325+
array(0) {
326+
}
327+
}
328+
}
329+
["fields"]=>
330+
array(0) {
331+
}
332+
["read_preference"]=>
333+
array(2) {
334+
["mode"]=>
335+
int(10)
336+
["tags"]=>
337+
array(0) {
338+
}
339+
}
340+
["flags"]=>
341+
int(0)
342+
["skip"]=>
343+
int(0)
344+
["limit"]=>
345+
int(0)
346+
["count"]=>
347+
int(1)
348+
["batch_size"]=>
349+
int(0)
350+
["ns"]=>
351+
string(25) "phongo.readPreference_002"
352+
}
353+
["firstBatch"]=>
354+
NULL
355+
["hint"]=>
356+
int(1)
357+
["is_command_cursor"]=>
358+
bool(false)
359+
}
360+
===DONE===

0 commit comments

Comments
 (0)