Skip to content

Commit f8d3781

Browse files
committed
Merged pull request #928
2 parents 0022839 + ff41c31 commit f8d3781

File tree

8 files changed

+56
-27
lines changed

8 files changed

+56
-27
lines changed

.travis.scripts/atlas-uris.txt.enc

1.36 KB
Binary file not shown.

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ env:
1616

1717
matrix:
1818
include:
19+
- php: 7.2
20+
env:
21+
- TESTS=tests/atlas.phpt
22+
- TEST_PHP_ARGS="-q -s output.txt -x --show-diff"
1923
- php: 5.5
2024
- php: 5.6
2125
- php: 7.0
@@ -57,6 +61,7 @@ matrix:
5761
- SERVER_VERSION=3.6.5
5862

5963
before_install:
64+
- openssl aes-256-cbc -K $encrypted_b354efda2943_key -iv $encrypted_b354efda2943_iv -in .travis.scripts/atlas-uris.txt.enc -out .travis.scripts/atlas-uris.txt -d || true
6065
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
6166
- .travis.scripts/before_install.sh
6267
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-${SERVER_VERSION}.tgz

php_phongo.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ bool phongo_cursor_advance_and_check_for_error(mongoc_cursor_t* cursor TSRMLS_DC
760760
bool phongo_execute_query(mongoc_client_t* client, const char* namespace, zval* zquery, zval* options, uint32_t server_id, zval* return_value, int return_value_used TSRMLS_DC) /* {{{ */
761761
{
762762
const php_phongo_query_t* query;
763+
bson_t opts = BSON_INITIALIZER;
763764
mongoc_cursor_t* cursor;
764765
char* dbname;
765766
char* collname;
@@ -777,30 +778,36 @@ bool phongo_execute_query(mongoc_client_t* client, const char* namespace, zval*
777778

778779
query = Z_QUERY_OBJ_P(zquery);
779780

781+
bson_copy_to(query->opts, &opts);
782+
780783
if (query->read_concern) {
781784
mongoc_collection_set_read_concern(collection, query->read_concern);
782785
}
783786

784787
if (!phongo_parse_read_preference(options, &zreadPreference TSRMLS_CC)) {
785788
/* Exception should already have been thrown */
786789
mongoc_collection_destroy(collection);
790+
bson_destroy(&opts);
787791
return false;
788792
}
789793

790-
if (!phongo_parse_session(options, client, query->opts, &zsession TSRMLS_CC)) {
794+
if (!phongo_parse_session(options, client, &opts, &zsession TSRMLS_CC)) {
791795
/* Exception should already have been thrown */
792796
mongoc_collection_destroy(collection);
797+
bson_destroy(&opts);
793798
return false;
794799
}
795800

796-
if (!BSON_APPEND_INT32(query->opts, "serverId", server_id)) {
801+
if (!BSON_APPEND_INT32(&opts, "serverId", server_id)) {
797802
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"serverId\" option");
798803
mongoc_collection_destroy(collection);
804+
bson_destroy(&opts);
799805
return false;
800806
}
801807

802-
cursor = mongoc_collection_find_with_opts(collection, query->filter, query->opts, phongo_read_preference_from_zval(zreadPreference TSRMLS_CC));
808+
cursor = mongoc_collection_find_with_opts(collection, query->filter, &opts, phongo_read_preference_from_zval(zreadPreference TSRMLS_CC));
803809
mongoc_collection_destroy(collection);
810+
bson_destroy(&opts);
804811

805812
/* maxAwaitTimeMS must be set before the cursor is sent */
806813
if (query->max_await_time_ms) {

tests/atlas.phpt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Atlas Connectivity Tests
3+
--SKIPIF--
4+
<?php
5+
if (!file_exists('.travis.scripts/atlas-uris.txt')) { echo "skip Atlas URIs not found\n"; }
6+
if (filesize('.travis.scripts/atlas-uris.txt') < 10) { echo "skip Atlas URI file empty\n"; }
7+
if ($_ENV['TESTS'] !== 'tests/atlas.phpt') { echo "skip Atlas tests not wanted\n"; }
8+
?>
9+
--FILE--
10+
<?php
11+
$urls = explode("\n", file_get_contents('.travis.scripts/atlas-uris.txt'));
12+
13+
$isMasterCmd = new \MongoDB\Driver\Command(['isMaster' => 1]);
14+
$query = new \MongoDB\Driver\Query([]);
15+
16+
foreach ($urls as $url) {
17+
$url = trim($url);
18+
if ($url == '') {
19+
continue;
20+
}
21+
22+
try {
23+
$m = new \MongoDB\Driver\Manager($url);
24+
$m->executeCommand('admin', $isMasterCmd);
25+
iterator_to_array($m->executeQuery('test.test', $query));
26+
echo "PASS\n";
27+
} catch(Exception $e) {
28+
echo "FAIL: ", $e->getMessage(), "\n";
29+
}
30+
}
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECTF--
35+
PASS
36+
PASS
37+
PASS
38+
PASS
39+
PASS
40+
FAIL: %s
41+
===DONE===

tests/manager/manager-executeQuery-001.phpt

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
5656
["y"]=>
5757
int(1)
5858
}
59-
["serverId"]=>
60-
int(%d)
6159
}
6260
["readConcern"]=>
6361
NULL

tests/manager/manager-executeQuery-002.phpt

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
5555
["y"]=>
5656
int(1)
5757
}
58-
["serverId"]=>
59-
int(%d)
6058
}
6159
["readConcern"]=>
6260
NULL

tests/readPreference/bug0146-001.phpt

-10
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
4646
}
4747
["options"]=>
4848
object(stdClass)#%d (%d) {
49-
["serverId"]=>
50-
int(%d)
5149
}
5250
["readConcern"]=>
5351
NULL
@@ -86,8 +84,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
8684
}
8785
["options"]=>
8886
object(stdClass)#%d (%d) {
89-
["serverId"]=>
90-
int(%d)
9187
}
9288
["readConcern"]=>
9389
NULL
@@ -126,8 +122,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
126122
}
127123
["options"]=>
128124
object(stdClass)#%d (%d) {
129-
["serverId"]=>
130-
int(%d)
131125
}
132126
["readConcern"]=>
133127
NULL
@@ -166,8 +160,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
166160
}
167161
["options"]=>
168162
object(stdClass)#%d (%d) {
169-
["serverId"]=>
170-
int(%d)
171163
}
172164
["readConcern"]=>
173165
NULL
@@ -206,8 +198,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
206198
}
207199
["options"]=>
208200
object(stdClass)#%d (%d) {
209-
["serverId"]=>
210-
int(%d)
211201
}
212202
["readConcern"]=>
213203
NULL

tests/readPreference/bug0146-002.phpt

-10
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
4646
}
4747
["options"]=>
4848
object(stdClass)#%d (%d) {
49-
["serverId"]=>
50-
int(%d)
5149
}
5250
["readConcern"]=>
5351
NULL
@@ -86,8 +84,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
8684
}
8785
["options"]=>
8886
object(stdClass)#%d (%d) {
89-
["serverId"]=>
90-
int(%d)
9187
}
9288
["readConcern"]=>
9389
NULL
@@ -126,8 +122,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
126122
}
127123
["options"]=>
128124
object(stdClass)#%d (%d) {
129-
["serverId"]=>
130-
int(%d)
131125
}
132126
["readConcern"]=>
133127
NULL
@@ -166,8 +160,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
166160
}
167161
["options"]=>
168162
object(stdClass)#%d (%d) {
169-
["serverId"]=>
170-
int(%d)
171163
}
172164
["readConcern"]=>
173165
NULL
@@ -206,8 +198,6 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
206198
}
207199
["options"]=>
208200
object(stdClass)#%d (%d) {
209-
["serverId"]=>
210-
int(%d)
211201
}
212202
["readConcern"]=>
213203
NULL

0 commit comments

Comments
 (0)