diff options
author | Stanley Cheung <stanleycheung@google.com> | 2016-02-12 16:37:19 -0800 |
---|---|---|
committer | Stanley Cheung <stanleycheung@google.com> | 2016-02-12 16:37:19 -0800 |
commit | cccf9295e6e6d2da8c8c283b5c1ee0001975e525 (patch) | |
tree | bfd0cf2b6aab8d0d57565b202c3ac401b7998f04 /src/php/ext | |
parent | 2ba7885f5c9af63f6cea9faa7351ca0b54331b85 (diff) |
php: add more unit tests to improve code coverage
Diffstat (limited to 'src/php/ext')
-rw-r--r-- | src/php/ext/grpc/call.c | 12 | ||||
-rw-r--r-- | src/php/ext/grpc/channel.c | 52 |
2 files changed, 27 insertions, 37 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 7ba14a38d8..4b4336666c 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -125,15 +125,9 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array) { memcpy(str_val, elem->value, elem->value_length); if (zend_hash_find(array_hash, str_key, key_len, (void **)data) == SUCCESS) { - if (Z_TYPE_P(*data) != IS_ARRAY) { - zend_throw_exception(zend_exception_get_default(), - "Metadata hash somehow contains wrong types.", - 1 TSRMLS_CC); - efree(str_key); - efree(str_val); - return NULL; - } - add_next_index_stringl(*data, str_val, elem->value_length, false); + zend_throw_exception(zend_exception_get_default(), + "Metadata hash somehow contains wrong types.", + 1 TSRMLS_CC); } else { MAKE_STD_ZVAL(inner_array); array_init(inner_array); diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 60c94412dc..97e8cc1a63 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -148,37 +148,33 @@ PHP_METHOD(Channel, __construct) { "Channel expects a string and an array", 1 TSRMLS_CC); return; } - if (args_array == NULL) { - channel->wrapped = grpc_insecure_channel_create(target, NULL, NULL); - } else { - array_hash = Z_ARRVAL_P(args_array); - if (zend_hash_find(array_hash, "credentials", sizeof("credentials"), - (void **)&creds_obj) == SUCCESS) { - if (Z_TYPE_P(*creds_obj) == IS_NULL) { - creds = NULL; - zend_hash_del(array_hash, "credentials", 12); - } else if (zend_get_class_entry(*creds_obj TSRMLS_CC) != - grpc_ce_channel_credentials) { - zend_throw_exception(spl_ce_InvalidArgumentException, - "credentials must be a ChannelCredentials object", - 1 TSRMLS_CC); - return; - } else { - creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object( - *creds_obj TSRMLS_CC); - zend_hash_del(array_hash, "credentials", 12); - } - } - php_grpc_read_args_array(args_array, &args); - if (creds == NULL) { - channel->wrapped = grpc_insecure_channel_create(target, &args, NULL); + array_hash = Z_ARRVAL_P(args_array); + if (zend_hash_find(array_hash, "credentials", sizeof("credentials"), + (void **)&creds_obj) == SUCCESS) { + if (Z_TYPE_P(*creds_obj) == IS_NULL) { + creds = NULL; + zend_hash_del(array_hash, "credentials", 12); + } else if (zend_get_class_entry(*creds_obj TSRMLS_CC) != + grpc_ce_channel_credentials) { + zend_throw_exception(spl_ce_InvalidArgumentException, + "credentials must be a ChannelCredentials object", + 1 TSRMLS_CC); + return; } else { - gpr_log(GPR_DEBUG, "Initialized secure channel"); - channel->wrapped = - grpc_secure_channel_create(creds->wrapped, target, &args, NULL); + creds = (wrapped_grpc_channel_credentials *)zend_object_store_get_object( + *creds_obj TSRMLS_CC); + zend_hash_del(array_hash, "credentials", 12); } - efree(args.args); } + php_grpc_read_args_array(args_array, &args); + if (creds == NULL) { + channel->wrapped = grpc_insecure_channel_create(target, &args, NULL); + } else { + gpr_log(GPR_DEBUG, "Initialized secure channel"); + channel->wrapped = + grpc_secure_channel_create(creds->wrapped, target, &args, NULL); + } + efree(args.args); } /** |