Skip to content

Commit 0b98798

Browse files
committed
PHPC-283: UnexpectedValueException for invalid bsonSerialize() return value
1 parent b8b41a5 commit 0b98798

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/bson.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
619619
}
620620

621621
if (Z_TYPE_P(obj_data) != IS_ARRAY) {
622-
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Expected %s() to return an array, %s given", BSON_SERIALIZE_FUNC_NAME, zend_get_type_by_const(Z_TYPE_P(obj_data)));
622+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Expected %s() to return an array, %s given", BSON_SERIALIZE_FUNC_NAME, zend_get_type_by_const(Z_TYPE_P(obj_data)));
623623
zval_ptr_dtor(&obj_data);
624624

625625
return;
@@ -781,7 +781,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
781781
}
782782

783783
if (Z_TYPE_P(obj_data) != IS_ARRAY) {
784-
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Expected %s() to return an array, %s given", BSON_SERIALIZE_FUNC_NAME, zend_get_type_by_const(Z_TYPE_P(obj_data)));
784+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Expected %s() to return an array, %s given", BSON_SERIALIZE_FUNC_NAME, zend_get_type_by_const(Z_TYPE_P(obj_data)));
785785
zval_ptr_dtor(&obj_data);
786786

787787
return;

tests/bson/bson-encode_error-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $invalidValues = array(new stdClass, 'foo', 1, true);
2626
foreach ($invalidValues as $invalidValue) {
2727
try {
2828
BSON\fromArray(new MyClass($invalidValue));
29-
} catch (MongoDB\Driver\Exception\RuntimeException $e) {
29+
} catch (MongoDB\Driver\Exception\UnexpectedValueException $e) {
3030
echo $e->getMessage(), "\n";
3131
}
3232
}

tests/bson/bson-encode_error-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $invalidValues = array(new stdClass, 'foo', 1, true);
2626
foreach ($invalidValues as $invalidValue) {
2727
try {
2828
$bson = BSON\fromArray(array('embed' => new MyClass($invalidValue)));
29-
} catch (MongoDB\Driver\Exception\RuntimeException $e) {
29+
} catch (MongoDB\Driver\Exception\UnexpectedValueException $e) {
3030
echo $e->getMessage(), "\n";
3131
}
3232
}

0 commit comments

Comments
 (0)