Skip to content

Commit 30a8434

Browse files
committed
Merge pull request #954
2 parents 4cab9ee + c81c593 commit 30a8434

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/MongoDB/ReadPreference.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,43 @@ static bool php_phongo_readpreference_init_from_hash(php_phongo_readpreference_t
6363
php_phongo_zval_to_bson(tagSets, PHONGO_BSON_NONE, (bson_t*) tags, NULL TSRMLS_CC);
6464

6565
if (!php_phongo_read_preference_tags_are_valid(tags)) {
66-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to have zero or more documents", ZSTR_VAL(php_phongo_writeconcern_ce->name));
66+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to have zero or more documents", ZSTR_VAL(php_phongo_readpreference_ce->name));
6767
bson_destroy(tags);
6868
goto failure;
6969
}
7070

7171
if (!bson_empty(tags) && (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY)) {
72-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_writeconcern_ce->name));
72+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
7373
bson_destroy(tags);
7474
goto failure;
7575
}
7676

7777
mongoc_read_prefs_set_tags(intern->read_preference, tags);
7878
bson_destroy(tags);
7979
} else {
80-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" field to be array", ZSTR_VAL(php_phongo_writeconcern_ce->name));
80+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" field to be array", ZSTR_VAL(php_phongo_readpreference_ce->name));
8181
goto failure;
8282
}
8383
}
8484

8585
if ((maxStalenessSeconds = zend_hash_str_find(props, "maxStalenessSeconds", sizeof("maxStalenessSeconds") - 1))) {
8686
if (Z_TYPE_P(maxStalenessSeconds) == IS_LONG) {
8787
if (Z_LVAL_P(maxStalenessSeconds) < MONGOC_SMALLEST_MAX_STALENESS_SECONDS) {
88-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_writeconcern_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
88+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_readpreference_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
8989
goto failure;
9090
}
9191
if (Z_LVAL_P(maxStalenessSeconds) > INT32_MAX) {
92-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_writeconcern_ce->name), INT32_MAX);
92+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_readpreference_ce->name), INT32_MAX);
9393
goto failure;
9494
}
9595
if (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY) {
96-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_writeconcern_ce->name));
96+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
9797
goto failure;
9898
}
9999

100100
mongoc_read_prefs_set_max_staleness_seconds(intern->read_preference, Z_LVAL_P(maxStalenessSeconds));
101101
} else {
102-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" field to be integer", ZSTR_VAL(php_phongo_writeconcern_ce->name));
102+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" field to be integer", ZSTR_VAL(php_phongo_readpreference_ce->name));
103103
goto failure;
104104
}
105105
}
@@ -134,43 +134,43 @@ static bool php_phongo_readpreference_init_from_hash(php_phongo_readpreference_t
134134
php_phongo_zval_to_bson(*tagSets, PHONGO_BSON_NONE, (bson_t*) tags, NULL TSRMLS_CC);
135135

136136
if (!php_phongo_read_preference_tags_are_valid(tags)) {
137-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to have zero or more documents", ZSTR_VAL(php_phongo_writeconcern_ce->name));
137+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to have zero or more documents", ZSTR_VAL(php_phongo_readpreference_ce->name));
138138
bson_destroy(tags);
139139
goto failure;
140140
}
141141

142142
if (!bson_empty(tags) && (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY)) {
143-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_writeconcern_ce->name));
143+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
144144
bson_destroy(tags);
145145
goto failure;
146146
}
147147

148148
mongoc_read_prefs_set_tags(intern->read_preference, tags);
149149
bson_destroy(tags);
150150
} else {
151-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" field to be array", ZSTR_VAL(php_phongo_writeconcern_ce->name));
151+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"tags\" field to be array", ZSTR_VAL(php_phongo_readpreference_ce->name));
152152
goto failure;
153153
}
154154
}
155155

156156
if (zend_hash_find(props, "maxStalenessSeconds", sizeof("maxStalenessSeconds"), (void**) &maxStalenessSeconds) == SUCCESS) {
157157
if (Z_TYPE_PP(maxStalenessSeconds) == IS_LONG) {
158158
if (Z_LVAL_PP(maxStalenessSeconds) < MONGOC_SMALLEST_MAX_STALENESS_SECONDS) {
159-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_writeconcern_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
159+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_readpreference_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
160160
goto failure;
161161
}
162162
if (Z_LVAL_PP(maxStalenessSeconds) > INT32_MAX) {
163-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_writeconcern_ce->name), INT32_MAX);
163+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_readpreference_ce->name), INT32_MAX);
164164
goto failure;
165165
}
166166
if (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY) {
167-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_writeconcern_ce->name));
167+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
168168
goto failure;
169169
}
170170

171171
mongoc_read_prefs_set_max_staleness_seconds(intern->read_preference, Z_LVAL_PP(maxStalenessSeconds));
172172
} else {
173-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" field to be integer", ZSTR_VAL(php_phongo_writeconcern_ce->name));
173+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"maxStalenessSeconds\" field to be integer", ZSTR_VAL(php_phongo_readpreference_ce->name));
174174
goto failure;
175175
}
176176
}

tests/readPreference/readpreference-set_state_error-001.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ MongoDB\Driver\ReadPreference initialization requires specific values for "mode"
4444
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
4545
MongoDB\Driver\ReadPreference initialization requires "mode" field to be string
4646
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
47-
MongoDB\Driver\WriteConcern initialization requires "tags" field to be array
47+
MongoDB\Driver\ReadPreference initialization requires "tags" field to be array
4848
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
49-
MongoDB\Driver\WriteConcern initialization requires "tags" array field to have zero or more documents
49+
MongoDB\Driver\ReadPreference initialization requires "tags" array field to have zero or more documents
5050
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
51-
MongoDB\Driver\WriteConcern initialization requires "tags" array field to not be present with "primary" mode
51+
MongoDB\Driver\ReadPreference initialization requires "tags" array field to not be present with "primary" mode
5252
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
53-
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" integer field to be >= 90
53+
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" integer field to be >= 90
5454
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
55-
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" array field to not be present with "primary" mode
55+
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" array field to not be present with "primary" mode
5656
===DONE===

tests/readPreference/readpreference-set_state_error-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ MongoDB\Driver\ReadPreference::__set_state() requires correct data types and val
88
require_once __DIR__ . '/../utils/tools.php';
99

1010
echo throws(function() {
11-
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'maxStalenessSeconds' => pow(2, 32) + 1]);
11+
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'maxStalenessSeconds' => 2147483648]);
1212
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1313

1414
?>
1515
===DONE===
1616
<?php exit(0); ?>
1717
--EXPECT--
1818
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
19-
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" integer field to be <= 2147483647
19+
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" integer field to be <= 2147483647
2020
===DONE===

0 commit comments

Comments
 (0)