diff --git a/.circleci/config.yml b/.circleci/config.yml index bc3473969..7a7f8ec2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,13 +64,13 @@ unit-config: &unit-config - run: name: PHP unit tests - command: vendor/bin/phpunit + command: XDEBUG_MODE=coverage vendor/bin/phpunit - run: name: PHP unit tests with extension command: | if [ $RUN_EXTENSION_TESTS -eq "1" ]; then - php -d extension=opencensus.so vendor/bin/phpunit + XDEBUG_MODE=coverage php -d extension=opencensus.so vendor/bin/phpunit else echo "Skipping units tests with extension" fi @@ -107,29 +107,30 @@ jobs: docker: - image: circleci/php:7.3-zts-node - php71-32bit: + php74: <<: *unit-config docker: - - image: gcr.io/php-stackdriver/php71-32bit - environment: - TEST_PHP_ARGS: -q - REPORT_EXIT_STATUS: 1 - RUN_EXTENSION_TESTS: 1 - SUDO_CMD: "" + - image: circleci/php:7.4-node - php71-debug: + php74-zts: <<: *unit-config docker: - - image: gcr.io/php-stackdriver/php71-debug - environment: - TEST_PHP_ARGS: -q - REPORT_EXIT_STATUS: 1 - RUN_EXTENSION_TESTS: 1 - SUDO_CMD: "" + - image: circleci/php:7.4-zts-node - integration: + php80: + <<: *unit-config docker: - - image: circleci/php:7.2-node + - image: circleci/php:8.0-node + + php80-zts: + <<: *unit-config + docker: + - image: circleci/php:8.0-zts-node + + # Integration tests running on PHP 7.4. When updating these, please also update `integration-8.0` further down. + integration-7.4: + docker: + - image: circleci/php:7.4-node - image: memcached - image: mysql:5.7 environment: @@ -202,11 +203,13 @@ jobs: - run: name: Pgsql test command: tests/integration/pgsql/test.sh - - run: - name: Symfony 4 test - command: tests/integration/symfony4/test.sh - environment: - DATABASE_URL: mysql://mysql:mysql@127.0.0.1:3306/mysqldb +# Skipped due to a dependency incompatibility between "cache/adapter-common" and "psr/cache". +# TODO(mrmage): Re-enable this step once "cache/adapter-common" supports "psr/cache" v2.0/v3.0. +# - run: +# name: Symfony 4 test +# command: tests/integration/symfony4/test.sh +# environment: +# DATABASE_URL: mysql://mysql:mysql@127.0.0.1:3306/mysqldb - run: name: Wordpress test command: tests/integration/wordpress/test.sh @@ -216,6 +219,100 @@ jobs: DB_PASSWORD: mysql DB_DATABASE: mysqldb + # Integration tests running on PHP 8.0. When updating these, please also update `integration-7.4` further down. + integration-8.0: + docker: + - image: circleci/php:8.0-node + - image: memcached + - image: mysql:5.7 + environment: + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + MYSQL_DATABASE: mysqldb + MYSQL_RANDOM_ROOT_PASSWORD: yes + - image: postgres:9.6 + environment: + POSTGRES_PASSWORD: pgsql + POSTGRES_USER: postgres + steps: + - checkout + - run: + name: Install build tools + command: | + sudo apt-get update -y + sudo apt-get install -y -q --no-install-recommends \ + build-essential \ + g++ \ + gcc \ + libc-dev \ + libpqxx-dev \ + make \ + autoconf \ + git \ + unzip + - run: + name: Install opencensus extension + command: | + cd ext + phpize + ./configure --enable-opencensus + sudo make install + sudo docker-php-ext-enable opencensus + - run: + name: Install memcached extension + command: | + sudo apt-get install -y -q --no-install-recommends \ + libmemcached11 libmemcached-dev zlib1g-dev zlib1g + sudo pecl install memcached <<<'' + sudo docker-php-ext-enable memcached + - run: + name: Install pdo_mysql extension + command: sudo docker-php-ext-install pdo_mysql + - run: + name: Install mysqli extension + command: sudo docker-php-ext-install mysqli + - run: + name: Install pgsql extension + command: sudo docker-php-ext-install pgsql + - run: + name: Install pcntl extension + command: sudo docker-php-ext-install pcntl + - run: + name: Curl test + command: tests/integration/curl/test.sh + - run: + name: Guzzle 5 test + command: tests/integration/guzzle5/test.sh + - run: + name: Guzzle 6 test + command: tests/integration/guzzle6/test.sh + - run: + name: Laravel test + command: tests/integration/laravel/test.sh + - run: + name: Memcached test + command: tests/integration/memcached/test.sh + - run: + name: Pgsql test + command: tests/integration/pgsql/test.sh +# Skipped due to a dependency incompatibility between "cache/adapter-common" and "psr/cache". +# TODO(mrmage): Re-enable this step once "cache/adapter-common" supports "psr/cache" v2.0/v3.0. +# - run: +# name: Symfony 4 test +# command: tests/integration/symfony4/test.sh +# environment: +# DATABASE_URL: mysql://mysql:mysql@127.0.0.1:3306/mysqldb +# Skipped because "wp-cli" is currently not compatible with PHP 8 (see https://github.com/wp-cli/wp-cli/issues/5452). +# TODO(mrmage): Re-enable this step once "wp-cli" supports PHP 8. +# - run: +# name: Wordpress test +# command: tests/integration/wordpress/test.sh + environment: + DB_HOST: 127.0.0.1 + DB_USERNAME: mysql + DB_PASSWORD: mysql + DB_DATABASE: mysqldb + workflows: version: 2 units: @@ -226,6 +323,9 @@ workflows: - php72-zts - php73 - php73-zts - - php71-32bit - - php71-debug - - integration \ No newline at end of file + - php74 + - php74-zts + - php80 + - php80-zts + - integration-7.4 + - integration-8.0 \ No newline at end of file diff --git a/composer.json b/composer.json index 52c257382..4e7012301 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ "minimum-stability": "stable", "require": { "php": ">=7.1", - "ramsey/uuid": "~3", + "ramsey/uuid": "^3.0 || ^4.0", "psr/log": "^1.0", - "psr/cache": "^1.0", + "psr/cache": "^1.0 || ^2.0 || ^3.0", "cache/adapter-common": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^5.0", - "squizlabs/php_codesniffer": "2.*", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "squizlabs/php_codesniffer": "^3.0", "twig/twig": "~2.0 || ~1.35", "symfony/yaml": "~3.3", "guzzlehttp/guzzle": "~5.3", diff --git a/examples/symfony/web/app.php b/examples/symfony/web/app.php index 943d0898f..3427e133e 100644 --- a/examples/symfony/web/app.php +++ b/examples/symfony/web/app.php @@ -3,14 +3,8 @@ use Symfony\Component\HttpFoundation\Request; require __DIR__.'/../vendor/autoload.php'; -if (PHP_VERSION_ID < 70000) { - include_once __DIR__.'/../var/bootstrap.php.cache'; -} $kernel = new AppKernel('prod', false); -if (PHP_VERSION_ID < 70000) { - $kernel->loadClassCache(); -} //$kernel = new AppCache($kernel); // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter diff --git a/examples/symfony/web/app_dev.php b/examples/symfony/web/app_dev.php index d2ff583b2..57e1a433f 100644 --- a/examples/symfony/web/app_dev.php +++ b/examples/symfony/web/app_dev.php @@ -22,9 +22,6 @@ Debug::enable(); $kernel = new AppKernel('dev', true); -if (PHP_VERSION_ID < 70000) { - $kernel->loadClassCache(); -} $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); diff --git a/ext/opencensus.c b/ext/opencensus.c index fa524bfed..b2f69dfdd 100644 --- a/ext/opencensus.c +++ b/ext/opencensus.c @@ -70,6 +70,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opencensus_trace_add_message_event, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0) ZEND_ARG_ARRAY_INFO(0, options, 0) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /* }}} */ static PHP_MINFO_FUNCTION(opencensus); @@ -85,16 +89,16 @@ PHP_FUNCTION(opencensus_version); /* {{{ opencensus_functions[] */ static zend_function_entry opencensus_functions[] = { - PHP_FE(opencensus_version, NULL) + PHP_FE(opencensus_version, arginfo_void) PHP_FE(opencensus_core_send_to_daemonclient, arginfo_opencensus_core_send_to_daemon) PHP_FE(opencensus_trace_function, arginfo_opencensus_trace_function) PHP_FE(opencensus_trace_method, arginfo_opencensus_trace_method) - PHP_FE(opencensus_trace_list, NULL) + PHP_FE(opencensus_trace_list, arginfo_void) PHP_FE(opencensus_trace_begin, arginfo_opencensus_trace_begin) - PHP_FE(opencensus_trace_finish, NULL) - PHP_FE(opencensus_trace_clear, NULL) + PHP_FE(opencensus_trace_finish, arginfo_void) + PHP_FE(opencensus_trace_clear, arginfo_void) PHP_FE(opencensus_trace_set_context, arginfo_opencensus_trace_set_context) - PHP_FE(opencensus_trace_context, NULL) + PHP_FE(opencensus_trace_context, arginfo_void) PHP_FE(opencensus_trace_add_attribute, arginfo_opencensus_trace_add_attribute) PHP_FE(opencensus_trace_add_annotation, arginfo_opencensus_trace_add_annotation) PHP_FE(opencensus_trace_add_link, arginfo_opencensus_trace_add_link) @@ -122,9 +126,6 @@ zend_module_entry opencensus_module_entry = { }; #ifdef COMPILE_DL_OPENCENSUS -#ifdef ZTS -ZEND_TSRMLS_CACHE_DEFINE() -#endif ZEND_GET_MODULE(opencensus) #endif @@ -149,9 +150,6 @@ PHP_MINFO_FUNCTION(opencensus) */ PHP_GINIT_FUNCTION(opencensus) { -#if defined(COMPILE_DL_OPENCENSUS) && defined(ZTS) - ZEND_TSRMLS_CACHE_UPDATE() -#endif opencensus_trace_ginit(); } /* }}} */ @@ -168,9 +166,6 @@ PHP_GSHUTDOWN_FUNCTION(opencensus) */ PHP_MINIT_FUNCTION(opencensus) { -#if defined(COMPILE_DL_OPENCENSUS) && defined(ZTS) - ZEND_TSRMLS_CACHE_UPDATE() -#endif REGISTER_INI_ENTRIES(); #ifndef PHP_WIN32 diff --git a/ext/opencensus_trace.c b/ext/opencensus_trace.c index 9072e1822..7852233ab 100644 --- a/ext/opencensus_trace.c +++ b/ext/opencensus_trace.c @@ -70,7 +70,7 @@ void opencensus_trace_rshutdown() FREE_HASHTABLE(OPENCENSUS_G(user_traced_functions)); /* cleanup recorded spans */ - opencensus_trace_clear(0 TSRMLS_CC); + opencensus_trace_clear(0); } @@ -96,7 +96,11 @@ static zend_string *span_id_from_options(HashTable *options) str = zval_get_string(val); break; case IS_LONG: +#if PHP_MAJOR_VERSION < 8 str = _php_math_longtobase(val, 16); +#else + str = _php_math_longtobase(Z_LVAL_P(val), 16); +#endif break; } @@ -140,7 +144,7 @@ PHP_FUNCTION(opencensus_trace_add_attribute) opencensus_trace_span_t *span; zval *options = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|a", &k, &v, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|a", &k, &v, &options) == FAILURE) { RETURN_FALSE; } @@ -173,7 +177,7 @@ PHP_FUNCTION(opencensus_trace_add_annotation) opencensus_trace_span_t *span; zval *options = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|a", &description, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|a", &description, &options) == FAILURE) { RETURN_FALSE; } @@ -207,7 +211,7 @@ PHP_FUNCTION(opencensus_trace_add_link) opencensus_trace_span_t *span; zval *options = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|a", &trace_id, &span_id, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|a", &trace_id, &span_id, &options) == FAILURE) { RETURN_FALSE; } @@ -241,7 +245,7 @@ PHP_FUNCTION(opencensus_trace_add_message_event) opencensus_trace_span_t *span; zval *options = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|a", &type, &id, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|a", &type, &id, &options) == FAILURE) { RETURN_FALSE; } @@ -291,9 +295,9 @@ static void opencensus_free_args(zval *args, int num_args) * Call the provided callback with the provided parameters to the traced * function. The callback must return an array or an E_WARNING is raised. */ -static int opencensus_trace_call_user_function_callback(zval *args, int num_args, zend_execute_data *execute_data, opencensus_trace_span_t *span, zval *callback, zval *callback_result TSRMLS_DC) +static int opencensus_trace_call_user_function_callback(zval *args, int num_args, zend_execute_data *execute_data, opencensus_trace_span_t *span, zval *callback, zval *callback_result) { - if (call_user_function_ex(EG(function_table), NULL, callback, callback_result, num_args, args, 0, NULL) != SUCCESS) { + if (call_user_function(EG(function_table), NULL, callback, callback_result, num_args, args) != SUCCESS) { return FAILURE; } @@ -320,22 +324,21 @@ static int opencensus_trace_call_user_function_callback(zval *args, int num_args */ static zend_string *generate_span_id() { +#if PHP_VERSION_ID < 80000 zval zv; -#if PHP_VERSION_ID < 70100 - if (!BG(mt_rand_is_seeded)) { - php_mt_srand(GENERATE_SEED()); - } -#endif - ZVAL_LONG(&zv, ((uint32_t) php_mt_rand()) >> 1); return _php_math_longtobase(&zv, 16); +#else + zend_long random_int = ((uint32_t) php_mt_rand()) >> 1; + return _php_math_longtobase(random_int, 16); +#endif } /** * Start a new trace span. Inherit the parent span id from the current trace * context */ -static opencensus_trace_span_t *opencensus_trace_begin(zend_string *name, zend_execute_data *execute_data, zend_string *span_id TSRMLS_DC) +static opencensus_trace_span_t *opencensus_trace_begin(zend_string *name, zend_execute_data *execute_data, zend_string *span_id) { opencensus_trace_span_t *span = opencensus_trace_span_alloc(); @@ -426,18 +429,18 @@ PHP_FUNCTION(opencensus_trace_begin) zval *span_options = NULL, default_span_options; opencensus_trace_span_t *span; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|a", &function_name, &span_options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|a", &function_name, &span_options) == FAILURE) { RETURN_FALSE; } if (span_options == NULL) { array_init(&default_span_options); - span = opencensus_trace_begin(function_name, execute_data, NULL TSRMLS_CC); + span = opencensus_trace_begin(function_name, execute_data, NULL); opencensus_trace_span_apply_span_options(span, &default_span_options); zval_dtor(&default_span_options); } else { span_id = span_id_from_options(Z_ARR_P(span_options)); - span = opencensus_trace_begin(function_name, execute_data, span_id TSRMLS_CC); + span = opencensus_trace_begin(function_name, execute_data, span_id); if (span_id != NULL) { zend_string_release(span_id); } @@ -471,7 +474,7 @@ void span_dtor(zval *zv) * Reset the list of spans and free any allocated memory used. * If reset is set, reallocate request globals so we can start capturing spans. */ -void opencensus_trace_clear(int reset TSRMLS_DC) +void opencensus_trace_clear(int reset) { /* free the hashtable */ zend_hash_destroy(OPENCENSUS_G(spans)); @@ -502,7 +505,7 @@ void opencensus_trace_clear(int reset TSRMLS_DC) */ PHP_FUNCTION(opencensus_trace_clear) { - opencensus_trace_clear(1 TSRMLS_CC); + opencensus_trace_clear(1); RETURN_TRUE; } @@ -515,7 +518,7 @@ PHP_FUNCTION(opencensus_trace_clear) PHP_FUNCTION(opencensus_trace_set_context) { zend_string *trace_id = NULL, *parent_span_id = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &trace_id, &parent_span_id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &trace_id, &parent_span_id) == FAILURE) { RETURN_FALSE; } @@ -538,12 +541,12 @@ PHP_FUNCTION(opencensus_trace_context) object_init_ex(return_value, opencensus_trace_context_ce); if (span) { - zend_update_property_str(opencensus_trace_context_ce, return_value, "spanId", sizeof("spanId") - 1, span->span_id); + zend_update_property_str(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(return_value), "spanId", sizeof("spanId") - 1, span->span_id); } else if (OPENCENSUS_G(trace_parent_span_id)) { - zend_update_property_str(opencensus_trace_context_ce, return_value, "spanId", sizeof("spanId") - 1, OPENCENSUS_G(trace_parent_span_id)); + zend_update_property_str(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(return_value), "spanId", sizeof("spanId") - 1, OPENCENSUS_G(trace_parent_span_id)); } if (OPENCENSUS_G(trace_id)) { - zend_update_property_str(opencensus_trace_context_ce, return_value, "traceId", sizeof("traceId") - 1, OPENCENSUS_G(trace_id)); + zend_update_property_str(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(return_value), "traceId", sizeof("traceId") - 1, OPENCENSUS_G(trace_id)); } } @@ -552,7 +555,7 @@ PHP_FUNCTION(opencensus_trace_context) * calls to user space code. The original zend_execute_ex method is moved to * opencensus_original_zend_execute_ex */ -void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) { +void opencensus_trace_execute_ex (zend_execute_data *execute_data) { zend_string *function_name = opencensus_trace_add_scope_name( EG(current_execute_data)->func->common.function_name, EG(current_execute_data)->func->common.scope @@ -563,7 +566,7 @@ void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) { /* Some functions have no names - just execute them */ if (function_name == NULL) { - opencensus_original_zend_execute_ex(execute_data TSRMLS_CC); + opencensus_original_zend_execute_ex(execute_data); return; } @@ -571,12 +574,12 @@ void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) { /* Function is not registered for execution - continue normal execution */ if (trace_handler == NULL) { - opencensus_original_zend_execute_ex(execute_data TSRMLS_CC); + opencensus_original_zend_execute_ex(execute_data); zend_string_release(function_name); return; } - span = opencensus_trace_begin(function_name, execute_data, NULL TSRMLS_CC); + span = opencensus_trace_begin(function_name, execute_data, NULL); zend_string_release(function_name); if (zend_is_callable(trace_handler, 0, &callback_name)) { @@ -584,15 +587,15 @@ void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC) { zval callback_result, *args; int num_args; opencensus_copy_args(execute_data, &args, &num_args); - opencensus_original_zend_execute_ex(execute_data TSRMLS_CC); - if (opencensus_trace_call_user_function_callback(args, num_args, execute_data, span, trace_handler, &callback_result TSRMLS_CC) == SUCCESS) { + opencensus_original_zend_execute_ex(execute_data); + if (opencensus_trace_call_user_function_callback(args, num_args, execute_data, span, trace_handler, &callback_result) == SUCCESS) { opencensus_trace_span_apply_span_options(span, &callback_result); } opencensus_free_args(args, num_args); zval_dtor(&callback_result); } else { /* Registered handler is span options array */ - opencensus_original_zend_execute_ex(execute_data TSRMLS_CC); + opencensus_original_zend_execute_ex(execute_data); if (Z_TYPE_P(trace_handler) == IS_ARRAY) { opencensus_trace_span_apply_span_options(span, trace_handler); } @@ -643,7 +646,7 @@ void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS) return; } - span = opencensus_trace_begin(function_name, execute_data, NULL TSRMLS_CC); + span = opencensus_trace_begin(function_name, execute_data, NULL); zend_string_release(function_name); if (zend_is_callable(trace_handler, 0, &callback_name)) { @@ -652,7 +655,7 @@ void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS) int num_args; opencensus_copy_args(execute_data, &args, &num_args); resume_execute_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (opencensus_trace_call_user_function_callback(args, num_args, execute_data, span, trace_handler, &callback_result TSRMLS_CC) == SUCCESS) { + if (opencensus_trace_call_user_function_callback(args, num_args, execute_data, span, trace_handler, &callback_result) == SUCCESS) { opencensus_trace_span_apply_span_options(span, &callback_result); } opencensus_free_args(args, num_args); @@ -681,7 +684,7 @@ PHP_FUNCTION(opencensus_trace_function) zval *handler = NULL; zval h; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &function_name, &handler) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &function_name, &handler) == FAILURE) { RETURN_FALSE; } @@ -710,7 +713,7 @@ PHP_FUNCTION(opencensus_trace_method) zval *handler = NULL; zval h; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z", &class_name, &function_name, &handler) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|z", &class_name, &function_name, &handler) == FAILURE) { RETURN_FALSE; } @@ -743,7 +746,7 @@ PHP_FUNCTION(opencensus_trace_list) ZEND_HASH_FOREACH_PTR(OPENCENSUS_G(spans), trace_span) { zval span; opencensus_trace_span_to_zval(trace_span, &span); - add_next_index_zval(return_value, &span TSRMLS_CC); + add_next_index_zval(return_value, &span); } ZEND_HASH_FOREACH_END(); } diff --git a/ext/opencensus_trace.h b/ext/opencensus_trace.h index 730c0cc2e..b3f68a146 100644 --- a/ext/opencensus_trace.h +++ b/ext/opencensus_trace.h @@ -42,8 +42,8 @@ void opencensus_trace_ginit(); void opencensus_trace_gshutdown(); void opencensus_trace_rinit(); void opencensus_trace_rshutdown(); -void opencensus_trace_clear(int reset TSRMLS_DC); -void opencensus_trace_execute_ex (zend_execute_data *execute_data TSRMLS_DC); +void opencensus_trace_clear(int reset); +void opencensus_trace_execute_ex (zend_execute_data *execute_data); void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS); void span_dtor(zval *zv); diff --git a/ext/opencensus_trace_annotation.c b/ext/opencensus_trace_annotation.c index d42738132..c248077f4 100644 --- a/ext/opencensus_trace_annotation.c +++ b/ext/opencensus_trace_annotation.c @@ -48,6 +48,9 @@ zend_class_entry* opencensus_trace_annotation_ce = NULL; +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /** * Fetch the annotation description * @@ -60,7 +63,7 @@ static PHP_METHOD(OpenCensusTraceAnnotation, description) { return; } - val = zend_read_property(opencensus_trace_annotation_ce, getThis(), "description", sizeof("description") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(getThis()), "description", sizeof("description") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -77,7 +80,7 @@ static PHP_METHOD(OpenCensusTraceAnnotation, time) { return; } - val = zend_read_property(opencensus_trace_annotation_ce, getThis(), "time", sizeof("time") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(getThis()), "time", sizeof("time") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -94,16 +97,16 @@ static PHP_METHOD(OpenCensusTraceAnnotation, options) { return; } - val = zend_read_property(opencensus_trace_annotation_ce, getThis(), "options", sizeof("options") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(getThis()), "options", sizeof("options") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } /* Declare method entries for the OpenCensus\Trace\Ext\Annotation class */ static zend_function_entry opencensus_trace_annotation_methods[] = { - PHP_ME(OpenCensusTraceAnnotation, description, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceAnnotation, time, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceAnnotation, options, NULL, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceAnnotation, description, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceAnnotation, time, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceAnnotation, options, arginfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -115,9 +118,9 @@ int opencensus_trace_annotation_minit(INIT_FUNC_ARGS) INIT_CLASS_ENTRY(ce, "OpenCensus\\Trace\\Ext\\Annotation", opencensus_trace_annotation_methods); opencensus_trace_annotation_ce = zend_register_internal_class(&ce); - zend_declare_property_null(opencensus_trace_annotation_ce, "description", sizeof("description") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_annotation_ce, "time", sizeof("time") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_annotation_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(opencensus_trace_annotation_ce, "description", sizeof("description") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_annotation_ce, "time", sizeof("time") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_annotation_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED); return SUCCESS; } @@ -152,8 +155,8 @@ void opencensus_trace_annotation_free(opencensus_trace_annotation_t *annotation) int opencensus_trace_annotation_to_zval(opencensus_trace_annotation_t *annotation, zval *zv) { object_init_ex(zv, opencensus_trace_annotation_ce); - zend_update_property_str(opencensus_trace_annotation_ce, zv, "description", sizeof("description") - 1, annotation->description); - zend_update_property_double(opencensus_trace_annotation_ce, zv, "time", sizeof("time") - 1, annotation->time_event.time); - zend_update_property(opencensus_trace_annotation_ce, zv, "options", sizeof("options") - 1, &annotation->options); + zend_update_property_str(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(zv), "description", sizeof("description") - 1, annotation->description); + zend_update_property_double(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(zv), "time", sizeof("time") - 1, annotation->time_event.time); + zend_update_property(opencensus_trace_annotation_ce, OPENCENSUS_OBJ_P(zv), "options", sizeof("options") - 1, &annotation->options); return SUCCESS; } diff --git a/ext/opencensus_trace_context.c b/ext/opencensus_trace_context.c index 4c877b976..aa20901f0 100644 --- a/ext/opencensus_trace_context.c +++ b/ext/opencensus_trace_context.c @@ -43,6 +43,7 @@ * } */ +#include "php_opencensus.h" #include "opencensus_trace_context.h" zend_class_entry* opencensus_trace_context_ce = NULL; @@ -51,6 +52,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_OpenCensusTraceContext_construct, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, contextOptions, 0) ZEND_END_ARG_INFO(); +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /** * Initializer for OpenCensus\Trace\SpanContext * @@ -61,12 +65,12 @@ static PHP_METHOD(OpenCensusTraceContext, __construct) { zend_string *k; HashTable *context_options; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "h", &context_options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &context_options) == FAILURE) { return; } ZEND_HASH_FOREACH_STR_KEY_VAL(context_options, k, v) { - zend_update_property(opencensus_trace_context_ce, getThis(), ZSTR_VAL(k), strlen(ZSTR_VAL(k)), v); + zend_update_property(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(getThis()), ZSTR_VAL(k), strlen(ZSTR_VAL(k)), v); } ZEND_HASH_FOREACH_END(); } @@ -82,7 +86,7 @@ static PHP_METHOD(OpenCensusTraceContext, spanId) { return; } - val = zend_read_property(opencensus_trace_context_ce, getThis(), "spanId", sizeof("spanId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(getThis()), "spanId", sizeof("spanId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -99,7 +103,7 @@ static PHP_METHOD(OpenCensusTraceContext, traceId) { return; } - val = zend_read_property(opencensus_trace_context_ce, getThis(), "traceId", sizeof("traceId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_context_ce, OPENCENSUS_OBJ_P(getThis()), "traceId", sizeof("traceId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -107,8 +111,8 @@ static PHP_METHOD(OpenCensusTraceContext, traceId) { /* Declare method entries for the OpenCensus\Trace\SpanContext class */ static zend_function_entry opencensus_trace_context_methods[] = { PHP_ME(OpenCensusTraceContext, __construct, arginfo_OpenCensusTraceContext_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(OpenCensusTraceContext, spanId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceContext, traceId, NULL, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceContext, spanId, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceContext, traceId, arginfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -119,8 +123,8 @@ int opencensus_trace_context_minit(INIT_FUNC_ARGS) { INIT_CLASS_ENTRY(ce, "OpenCensus\\Trace\\Ext\\SpanContext", opencensus_trace_context_methods); opencensus_trace_context_ce = zend_register_internal_class(&ce); - zend_declare_property_null(opencensus_trace_context_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_context_ce, "traceId", sizeof("traceId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(opencensus_trace_context_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_context_ce, "traceId", sizeof("traceId") - 1, ZEND_ACC_PROTECTED); return SUCCESS; } diff --git a/ext/opencensus_trace_link.c b/ext/opencensus_trace_link.c index d9cb89c24..c0a709012 100644 --- a/ext/opencensus_trace_link.c +++ b/ext/opencensus_trace_link.c @@ -48,6 +48,9 @@ zend_class_entry* opencensus_trace_link_ce = NULL; +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /** * Fetch the link traceId * @@ -60,7 +63,7 @@ static PHP_METHOD(OpenCensusTraceLink, traceId) { return; } - val = zend_read_property(opencensus_trace_link_ce, getThis(), "traceId", sizeof("traceId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(getThis()), "traceId", sizeof("traceId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -77,7 +80,7 @@ static PHP_METHOD(OpenCensusTraceLink, spanId) { return; } - val = zend_read_property(opencensus_trace_link_ce, getThis(), "spanId", sizeof("spanId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(getThis()), "spanId", sizeof("spanId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -94,16 +97,16 @@ static PHP_METHOD(OpenCensusTraceLink, options) { return; } - val = zend_read_property(opencensus_trace_link_ce, getThis(), "options", sizeof("options") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(getThis()), "options", sizeof("options") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } /* Declare method entries for the OpenCensus\Trace\Ext\Link class */ static zend_function_entry opencensus_trace_link_methods[] = { - PHP_ME(OpenCensusTraceLink, traceId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceLink, spanId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceLink, options, NULL, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceLink, traceId, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceLink, spanId, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceLink, options, arginfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -115,9 +118,9 @@ int opencensus_trace_link_minit(INIT_FUNC_ARGS) INIT_CLASS_ENTRY(ce, "OpenCensus\\Trace\\Ext\\Link", opencensus_trace_link_methods); opencensus_trace_link_ce = zend_register_internal_class(&ce); - zend_declare_property_null(opencensus_trace_link_ce, "traceId", sizeof("traceId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_link_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_link_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(opencensus_trace_link_ce, "traceId", sizeof("traceId") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_link_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_link_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED); return SUCCESS; } @@ -155,8 +158,8 @@ void opencensus_trace_link_free(opencensus_trace_link_t *link) int opencensus_trace_link_to_zval(opencensus_trace_link_t *link, zval *zv) { object_init_ex(zv, opencensus_trace_link_ce); - zend_update_property_str(opencensus_trace_link_ce, zv, "traceId", sizeof("traceId") - 1, link->trace_id); - zend_update_property_str(opencensus_trace_link_ce, zv, "spanId", sizeof("spanId") - 1, link->span_id); - zend_update_property(opencensus_trace_link_ce, zv, "options", sizeof("options") - 1, &link->options); + zend_update_property_str(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(zv), "traceId", sizeof("traceId") - 1, link->trace_id); + zend_update_property_str(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(zv), "spanId", sizeof("spanId") - 1, link->span_id); + zend_update_property(opencensus_trace_link_ce, OPENCENSUS_OBJ_P(zv), "options", sizeof("options") - 1, &link->options); return SUCCESS; } diff --git a/ext/opencensus_trace_message_event.c b/ext/opencensus_trace_message_event.c index a035db10c..4178383fd 100644 --- a/ext/opencensus_trace_message_event.c +++ b/ext/opencensus_trace_message_event.c @@ -54,6 +54,9 @@ zend_class_entry* opencensus_trace_message_event_ce = NULL; +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /** * Fetch the message_event type * @@ -66,7 +69,7 @@ static PHP_METHOD(OpenCensusTraceMessageEvent, type) { return; } - val = zend_read_property(opencensus_trace_message_event_ce, getThis(), "type", sizeof("type") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(getThis()), "type", sizeof("type") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -83,7 +86,7 @@ static PHP_METHOD(OpenCensusTraceMessageEvent, id) { return; } - val = zend_read_property(opencensus_trace_message_event_ce, getThis(), "id", sizeof("id") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(getThis()), "id", sizeof("id") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -100,7 +103,7 @@ static PHP_METHOD(OpenCensusTraceMessageEvent, time) { return; } - val = zend_read_property(opencensus_trace_message_event_ce, getThis(), "time", sizeof("time") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(getThis()), "time", sizeof("time") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -117,17 +120,17 @@ static PHP_METHOD(OpenCensusTraceMessageEvent, options) { return; } - val = zend_read_property(opencensus_trace_message_event_ce, getThis(), "options", sizeof("options") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(getThis()), "options", sizeof("options") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } /* Declare method entries for the OpenCensus\Trace\Ext\MessageEvent class */ static zend_function_entry opencensus_trace_message_event_methods[] = { - PHP_ME(OpenCensusTraceMessageEvent, type, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceMessageEvent, id, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceMessageEvent, time, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceMessageEvent, options, NULL, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceMessageEvent, type, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceMessageEvent, id, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceMessageEvent, time, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceMessageEvent, options, arginfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -139,10 +142,10 @@ int opencensus_trace_message_event_minit(INIT_FUNC_ARGS) INIT_CLASS_ENTRY(ce, "OpenCensus\\Trace\\Ext\\MessageEvent", opencensus_trace_message_event_methods); opencensus_trace_message_event_ce = zend_register_internal_class(&ce); - zend_declare_property_null(opencensus_trace_message_event_ce, "type", sizeof("type") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_message_event_ce, "id", sizeof("id") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_message_event_ce, "time", sizeof("time") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_message_event_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(opencensus_trace_message_event_ce, "type", sizeof("type") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_message_event_ce, "id", sizeof("id") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_message_event_ce, "time", sizeof("time") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_message_event_ce, "options", sizeof("options") - 1, ZEND_ACC_PROTECTED); return SUCCESS; } @@ -181,9 +184,9 @@ void opencensus_trace_message_event_free(opencensus_trace_message_event_t *messa int opencensus_trace_message_event_to_zval(opencensus_trace_message_event_t *message_event, zval *zv) { object_init_ex(zv, opencensus_trace_message_event_ce); - zend_update_property_str(opencensus_trace_message_event_ce, zv, "type", sizeof("type") - 1, message_event->type); - zend_update_property_str(opencensus_trace_message_event_ce, zv, "id", sizeof("id") - 1, message_event->id); - zend_update_property_double(opencensus_trace_message_event_ce, zv, "time", sizeof("time") - 1, message_event->time_event.time); - zend_update_property(opencensus_trace_message_event_ce, zv, "options", sizeof("options") - 1, &message_event->options); + zend_update_property_str(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(zv), "type", sizeof("type") - 1, message_event->type); + zend_update_property_str(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(zv), "id", sizeof("id") - 1, message_event->id); + zend_update_property_double(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(zv), "time", sizeof("time") - 1, message_event->time_event.time); + zend_update_property(opencensus_trace_message_event_ce, OPENCENSUS_OBJ_P(zv), "options", sizeof("options") - 1, &message_event->options); return SUCCESS; } diff --git a/ext/opencensus_trace_span.c b/ext/opencensus_trace_span.c index 0519fcb42..937f3a184 100644 --- a/ext/opencensus_trace_span.c +++ b/ext/opencensus_trace_span.c @@ -105,6 +105,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_OpenCensusTraceSpan_construct, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, spanOptions, 0) ZEND_END_ARG_INFO(); +ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) +ZEND_END_ARG_INFO(); + /** * Initializer for OpenCensus\Trace\Span * @@ -112,26 +115,26 @@ ZEND_END_ARG_INFO(); */ static PHP_METHOD(OpenCensusTraceSpan, __construct) { zval *zval_span_options, *v; - ulong idx; + unsigned long idx; zend_string *k; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zval_span_options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zval_span_options) == FAILURE) { return; } zend_array *span_options = Z_ARR_P(zval_span_options); ZEND_HASH_FOREACH_KEY_VAL(span_options, idx, k, v) { - zend_update_property(opencensus_trace_span_ce, getThis(), ZSTR_VAL(k), strlen(ZSTR_VAL(k)), v); + zend_update_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), ZSTR_VAL(k), strlen(ZSTR_VAL(k)), v); } ZEND_HASH_FOREACH_END(); } static PHP_METHOD(OpenCensusTraceSpan, __destruct) { zval val, *zv; - zv = zend_read_property(opencensus_trace_span_ce, getThis(), "attributes", sizeof("attributes") - 1, 0, &val TSRMLS_CC); + zv = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "attributes", sizeof("attributes") - 1, 0, &val); zval_dtor(zv); - zv = zend_read_property(opencensus_trace_span_ce, getThis(), "links", sizeof("links") - 1, 0, &val TSRMLS_CC); + zv = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "links", sizeof("links") - 1, 0, &val); zval_dtor(zv); - zv = zend_read_property(opencensus_trace_span_ce, getThis(), "timeEvents", sizeof("timeEvents") - 1, 0, &val TSRMLS_CC); + zv = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "timeEvents", sizeof("timeEvents") - 1, 0, &val); zval_dtor(zv); } @@ -147,7 +150,7 @@ static PHP_METHOD(OpenCensusTraceSpan, name) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "name", sizeof("name") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "name", sizeof("name") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -164,7 +167,7 @@ static PHP_METHOD(OpenCensusTraceSpan, spanId) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "spanId", sizeof("spanId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "spanId", sizeof("spanId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -181,7 +184,7 @@ static PHP_METHOD(OpenCensusTraceSpan, parentSpanId) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "parentSpanId", sizeof("parentSpanId") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "parentSpanId", sizeof("parentSpanId") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -198,7 +201,7 @@ static PHP_METHOD(OpenCensusTraceSpan, attributes) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "attributes", sizeof("attributes") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "attributes", sizeof("attributes") - 1, 1, &rv); if (ZVAL_IS_NULL(val)) { array_init(return_value); return; @@ -219,7 +222,7 @@ static PHP_METHOD(OpenCensusTraceSpan, links) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "links", sizeof("links") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "links", sizeof("links") - 1, 1, &rv); if (ZVAL_IS_NULL(val)) { array_init(return_value); return; @@ -240,7 +243,7 @@ static PHP_METHOD(OpenCensusTraceSpan, timeEvents) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "timeEvents", sizeof("timeEvents") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "timeEvents", sizeof("timeEvents") - 1, 1, &rv); if (ZVAL_IS_NULL(val)) { array_init(return_value); return; @@ -261,7 +264,7 @@ static PHP_METHOD(OpenCensusTraceSpan, startTime) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "startTime", sizeof("startTime") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "startTime", sizeof("startTime") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -278,7 +281,7 @@ static PHP_METHOD(OpenCensusTraceSpan, endTime) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "endTime", sizeof("endTime") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "endTime", sizeof("endTime") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -295,7 +298,7 @@ static PHP_METHOD(OpenCensusTraceSpan, stackTrace) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "stackTrace", sizeof("stackTrace") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "stackTrace", sizeof("stackTrace") - 1, 1, &rv); if (ZVAL_IS_NULL(val)) { array_init(return_value); return; @@ -316,7 +319,7 @@ static PHP_METHOD(OpenCensusTraceSpan, kind) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "kind", sizeof("kind") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "kind", sizeof("kind") - 1, 1, &rv); RETURN_ZVAL(val, 1, 0); } @@ -333,31 +336,31 @@ static PHP_METHOD(OpenCensusTraceSpan, sameProcessAsParentSpan) { return; } - val = zend_read_property(opencensus_trace_span_ce, getThis(), "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, 1, &rv); + val = zend_read_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(getThis()), "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, 1, &rv); switch (Z_TYPE_P(val)) { case IS_FALSE: RETURN_FALSE; case IS_TRUE: default: - RETURN_TRUE + RETURN_TRUE; } } /* Declare method entries for the OpenCensus\Trace\Span class */ static zend_function_entry opencensus_trace_span_methods[] = { - PHP_ME(OpenCensusTraceSpan, __construct, arginfo_OpenCensusTraceSpan_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(OpenCensusTraceSpan, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR) - PHP_ME(OpenCensusTraceSpan, name, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, spanId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, parentSpanId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, attributes, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, startTime, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, endTime, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, stackTrace, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, links, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, timeEvents, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, kind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(OpenCensusTraceSpan, sameProcessAsParentSpan, NULL, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, __construct, arginfo_OpenCensusTraceSpan_construct, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, __destruct, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, name, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, spanId, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, parentSpanId, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, attributes, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, startTime, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, endTime, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, stackTrace, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, links, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, timeEvents, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, kind, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(OpenCensusTraceSpan, sameProcessAsParentSpan, arginfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -369,18 +372,18 @@ int opencensus_trace_span_minit(INIT_FUNC_ARGS) { opencensus_trace_span_ce = zend_register_internal_class(&ce); zend_declare_property_string( - opencensus_trace_span_ce, "name", sizeof("name") - 1, "unknown", ZEND_ACC_PROTECTED TSRMLS_CC + opencensus_trace_span_ce, "name", sizeof("name") - 1, "unknown", ZEND_ACC_PROTECTED ); - zend_declare_property_null(opencensus_trace_span_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "parentSpanId", sizeof("parentSpanId") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "startTime", sizeof("startTime") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "endTime", sizeof("endTime") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "attributes", sizeof("attributes") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "stackTrace", sizeof("stackTrace") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "links", sizeof("links") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "timeEvents", sizeof("timeEvents") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "kind", sizeof("kind") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(opencensus_trace_span_ce, "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(opencensus_trace_span_ce, "spanId", sizeof("spanId") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "parentSpanId", sizeof("parentSpanId") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "startTime", sizeof("startTime") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "endTime", sizeof("endTime") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "attributes", sizeof("attributes") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "stackTrace", sizeof("stackTrace") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "links", sizeof("links") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "timeEvents", sizeof("timeEvents") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "kind", sizeof("kind") - 1, ZEND_ACC_PROTECTED); + zend_declare_property_null(opencensus_trace_span_ce, "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, ZEND_ACC_PROTECTED); return SUCCESS; } @@ -632,38 +635,38 @@ static int opencensus_trace_update_links(opencensus_trace_span_t *span, zval *re } /* Fill the provided span with the provided data from the internal span representation */ -int opencensus_trace_span_to_zval(opencensus_trace_span_t *trace_span, zval *span TSRMLS_DC) +int opencensus_trace_span_to_zval(opencensus_trace_span_t *trace_span, zval *span) { zval attributes, links, time_events; object_init_ex(span, opencensus_trace_span_ce); - zend_update_property_str(opencensus_trace_span_ce, span, "spanId", sizeof("spanId") - 1, trace_span->span_id); + zend_update_property_str(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "spanId", sizeof("spanId") - 1, trace_span->span_id); if (trace_span->parent) { - zend_update_property_str(opencensus_trace_span_ce, span, "parentSpanId", sizeof("parentSpanId") - 1, trace_span->parent->span_id); + zend_update_property_str(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "parentSpanId", sizeof("parentSpanId") - 1, trace_span->parent->span_id); } else if (OPENCENSUS_G(trace_parent_span_id)) { - zend_update_property_str(opencensus_trace_span_ce, span, "parentSpanId", sizeof("parentSpanId") - 1, OPENCENSUS_G(trace_parent_span_id)); + zend_update_property_str(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "parentSpanId", sizeof("parentSpanId") - 1, OPENCENSUS_G(trace_parent_span_id)); } - zend_update_property_str(opencensus_trace_span_ce, span, "name", sizeof("name") - 1, trace_span->name); - zend_update_property_double(opencensus_trace_span_ce, span, "startTime", sizeof("startTime") - 1, trace_span->start); - zend_update_property_double(opencensus_trace_span_ce, span, "endTime", sizeof("endTime") - 1, trace_span->stop); + zend_update_property_str(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "name", sizeof("name") - 1, trace_span->name); + zend_update_property_double(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "startTime", sizeof("startTime") - 1, trace_span->start); + zend_update_property_double(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "endTime", sizeof("endTime") - 1, trace_span->stop); array_init(&attributes); zend_hash_copy(Z_ARRVAL(attributes), trace_span->attributes, zval_add_ref); - zend_update_property(opencensus_trace_span_ce, span, "attributes", sizeof("attributes") - 1, &attributes); + zend_update_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "attributes", sizeof("attributes") - 1, &attributes); - zend_update_property(opencensus_trace_span_ce, span, "stackTrace", sizeof("stackTrace") - 1, &trace_span->stackTrace); + zend_update_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "stackTrace", sizeof("stackTrace") - 1, &trace_span->stackTrace); array_init(&links); opencensus_trace_update_links(trace_span, &links); - zend_update_property(opencensus_trace_span_ce, span, "links", sizeof("links") - 1, &links); + zend_update_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "links", sizeof("links") - 1, &links); array_init(&time_events); opencensus_trace_update_time_events(trace_span, &time_events); - zend_update_property(opencensus_trace_span_ce, span, "timeEvents", sizeof("timeEvents") - 1, &time_events); + zend_update_property(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "timeEvents", sizeof("timeEvents") - 1, &time_events); if (trace_span->kind) { - zend_update_property_str(opencensus_trace_span_ce, span, "kind", sizeof("kind") - 1, trace_span->kind); + zend_update_property_str(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "kind", sizeof("kind") - 1, trace_span->kind); } - zend_update_property_bool(opencensus_trace_span_ce, span, "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, trace_span->same_process_as_parent_span); + zend_update_property_bool(opencensus_trace_span_ce, OPENCENSUS_OBJ_P(span), "sameProcessAsParentSpan", sizeof("sameProcessAsParentSpan") - 1, trace_span->same_process_as_parent_span); return SUCCESS; } diff --git a/ext/php_opencensus.h b/ext/php_opencensus.h index e6dd70f2b..5ae256f33 100644 --- a/ext/php_opencensus.h +++ b/ext/php_opencensus.h @@ -31,7 +31,7 @@ #include #endif -#define PHP_OPENCENSUS_VERSION "0.3.0" +#define PHP_OPENCENSUS_VERSION "0.7.0" #define PHP_OPENCENSUS_EXTNAME "opencensus" extern zend_module_entry opencensus_module_entry; @@ -53,6 +53,13 @@ ZEND_END_MODULE_GLOBALS(opencensus) ZEND_EXTERN_MODULE_GLOBALS(opencensus) #define OPENCENSUS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(opencensus, v) +// Compatibility macro to account for a few method signature changes in PHP 8. +#if PHP_MAJOR_VERSION < 8 +#define OPENCENSUS_OBJ_P(v) (v) +#else +#define OPENCENSUS_OBJ_P(v) Z_OBJ_P(v) +#endif + double opencensus_now(); #endif /* PHP_OPENCENSUS_H */ diff --git a/ext/tests/name_uncastable_object.phpt b/ext/tests/name_uncastable_object.phpt index 26f47511b..2babeef2b 100644 --- a/ext/tests/name_uncastable_object.phpt +++ b/ext/tests/name_uncastable_object.phpt @@ -1,5 +1,9 @@ --TEST-- OpenCensus Trace: Providing integer as name +--SKIPIF-- +=')) die("skip this test is for PHP versions < 7.4; see name_uncastable_object_php74.phpt for the PHP 7.4+ equivalent"); +?> --FILE-- name()); ?> --EXPECTF-- -%s fatal error: Object of class UncastableObject could not be converted to string in %s/name_uncastable_object.php on line %d +%s fatal error: Object of class UncastableObject could not be converted to string in %s/name_uncastable_object.php on line %d \ No newline at end of file diff --git a/ext/tests/name_uncastable_object_php74.phpt b/ext/tests/name_uncastable_object_php74.phpt new file mode 100644 index 000000000..79e5e3eba --- /dev/null +++ b/ext/tests/name_uncastable_object_php74.phpt @@ -0,0 +1,30 @@ +--TEST-- +OpenCensus Trace: Providing integer as name +--SKIPIF-- += 7.4; see name_uncastable_object_php74.phpt for the PHP 7.4+ equivalent"); +?> +--FILE-- + $obj]); +opencensus_trace_finish(); +$spans = opencensus_trace_list(); + +echo 'Number of spans: ' . count($spans) . PHP_EOL; +$span = $spans[0]; +var_dump($span->name()); + +?> +--EXPECTF-- +Fatal error: Uncaught Error: Object of class UncastableObject could not be converted to string in %sname_uncastable_object_php74.php:%d +Stack trace: +#0 %sname_uncastable_object_php74.php(%d): opencensus_trace_begin('foo', Array) +#1 {main} + thrown in %sname_uncastable_object_php74.php on line %d \ No newline at end of file diff --git a/tests/integration/curl/composer.json b/tests/integration/curl/composer.json index 7b9d7e535..74310c97f 100644 --- a/tests/integration/curl/composer.json +++ b/tests/integration/curl/composer.json @@ -1,11 +1,11 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "ext-opencensus": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "repositories": [ { diff --git a/tests/integration/curl/tests/CurlTest.php b/tests/integration/curl/tests/CurlTest.php index fd1b335ea..6f749fd30 100644 --- a/tests/integration/curl/tests/CurlTest.php +++ b/tests/integration/curl/tests/CurlTest.php @@ -27,12 +27,12 @@ */ class CurlTest extends TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { Curl::load(); } - public function setUp() + protected function setUp(): void { if (!extension_loaded('opencensus')) { $this->markTestSkipped('Please enable the opencensus extension.'); diff --git a/tests/integration/guzzle5/composer.json b/tests/integration/guzzle5/composer.json index aa92cef81..c10f6457a 100644 --- a/tests/integration/guzzle5/composer.json +++ b/tests/integration/guzzle5/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "guzzlehttp/guzzle": "^5.0", "ext-opencensus": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.0", "jcchavezs/httptest": "~0.2" }, "repositories": { diff --git a/tests/integration/guzzle5/tests/Guzzle5Test.php b/tests/integration/guzzle5/tests/Guzzle5Test.php index 4c377fd75..26a65079c 100644 --- a/tests/integration/guzzle5/tests/Guzzle5Test.php +++ b/tests/integration/guzzle5/tests/Guzzle5Test.php @@ -33,9 +33,8 @@ class Guzzle5Test extends TestCase { private $client; - public function setUp() + protected function setUp(): void { - parent::setUp(); $this->client = new Client(); $subscriber = new EventSubscriber(); $this->client->getEmitter()->attach($subscriber); diff --git a/tests/integration/guzzle6/composer.json b/tests/integration/guzzle6/composer.json index 8f0256dff..ca541da5a 100644 --- a/tests/integration/guzzle6/composer.json +++ b/tests/integration/guzzle6/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "guzzlehttp/guzzle": "^6.0", "ext-opencensus": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.0", "jcchavezs/httptest": "~0.2" }, "repositories": { diff --git a/tests/integration/guzzle6/tests/Guzzle6Test.php b/tests/integration/guzzle6/tests/Guzzle6Test.php index bb30e7b0f..ff0bde392 100644 --- a/tests/integration/guzzle6/tests/Guzzle6Test.php +++ b/tests/integration/guzzle6/tests/Guzzle6Test.php @@ -34,9 +34,8 @@ class Guzzle6Test extends TestCase { private $client; - public function setUp() + protected function setUp(): void { - parent::setUp(); $stack = new HandlerStack(); $stack->setHandler(\GuzzleHttp\choose_handler()); $stack->push(new Middleware()); diff --git a/tests/integration/laravel/test.sh b/tests/integration/laravel/test.sh index 5415b759e..caa597bb7 100755 --- a/tests/integration/laravel/test.sh +++ b/tests/integration/laravel/test.sh @@ -25,10 +25,10 @@ pushd laravel composer config repositories.opencensus git ${REPO} composer require opencensus/opencensus:dev-${BRANCH} -composer require --dev phpunit/phpunit:^7.0 guzzlehttp/guzzle:~6.0 +composer require --dev phpunit/phpunit:^9.0 guzzlehttp/guzzle:~6.0 php artisan migrate -vendor/bin/phpunit --config=phpunit.xml.dist +vendor/bin/phpunit popd popd diff --git a/tests/integration/laravel/tests/integration/LaravelTest.php b/tests/integration/laravel/tests/integration/LaravelTest.php index 780d0ea16..635199eec 100644 --- a/tests/integration/laravel/tests/integration/LaravelTest.php +++ b/tests/integration/laravel/tests/integration/LaravelTest.php @@ -25,7 +25,7 @@ class LaravelTest extends TestCase private static $outputFile; private static $client; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$outputFile = sys_get_temp_dir() . '/spans.json'; self::$client = new Client([ @@ -33,9 +33,8 @@ public static function setUpBeforeClass() ]); } - public function setUp() + protected function setUp(): void { - parent::setUp(); $this->clearSpans(); } diff --git a/tests/integration/memcached/composer.json b/tests/integration/memcached/composer.json index 1c37b278a..4a70da599 100644 --- a/tests/integration/memcached/composer.json +++ b/tests/integration/memcached/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "ext-opencensus": "*", "ext-memcached": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "repositories": [ { diff --git a/tests/integration/memcached/tests/MemcachedTest.php b/tests/integration/memcached/tests/MemcachedTest.php index acc4f8efc..466c73da9 100644 --- a/tests/integration/memcached/tests/MemcachedTest.php +++ b/tests/integration/memcached/tests/MemcachedTest.php @@ -29,14 +29,14 @@ class MemcachedTest extends TestCase private static $memcachedHost; private static $memcachedPort; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { MemcachedIntegration::load(); self::$memcachedHost = getenv('MEMCACHED_HOST') ?: '127.0.0.1'; self::$memcachedPort = (int) (getenv('MEMCACHED_PORT') ?: 11211); } - public function setUp() + protected function setUp(): void { if (!extension_loaded('opencensus')) { $this->markTestSkipped('Please enable the opencensus extension.'); diff --git a/tests/integration/pgsql/composer.json b/tests/integration/pgsql/composer.json index 5ecd15633..873733931 100644 --- a/tests/integration/pgsql/composer.json +++ b/tests/integration/pgsql/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "ext-opencensus": "*", "ext-pgsql": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "repositories": [ { diff --git a/tests/integration/pgsql/tests/PgsqlTest.php b/tests/integration/pgsql/tests/PgsqlTest.php index ac8e76f22..edf3b47f0 100644 --- a/tests/integration/pgsql/tests/PgsqlTest.php +++ b/tests/integration/pgsql/tests/PgsqlTest.php @@ -27,7 +27,7 @@ class PgsqlTest extends TestCase private $tracer; private static $postgresConnectionString; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { Postgres::load(); $postgresHost = getenv('POSTGRES_HOST') ?: '127.0.0.1'; @@ -46,7 +46,7 @@ public static function setUpBeforeClass() ); } - public function setUp() + protected function setUp(): void { if (!extension_loaded('opencensus')) { $this->markTestSkipped('Please enable the opencensus extension.'); diff --git a/tests/integration/symfony4/test.sh b/tests/integration/symfony4/test.sh index 8ba6656e1..febfc93ed 100755 --- a/tests/integration/symfony4/test.sh +++ b/tests/integration/symfony4/test.sh @@ -25,7 +25,7 @@ pushd symfony composer config repositories.opencensus git ${REPO} composer require opencensus/opencensus:dev-${BRANCH} doctrine -composer require --dev phpunit/phpunit:^7.0 guzzlehttp/guzzle:~6.0 +composer require --dev phpunit/phpunit:^9.0 guzzlehttp/guzzle:~6.0 bin/console doctrine:migrations:migrate -n vendor/bin/phpunit diff --git a/tests/integration/symfony4/tests/SymfonyTest.php b/tests/integration/symfony4/tests/SymfonyTest.php index d9e8b1d53..de443a8d7 100644 --- a/tests/integration/symfony4/tests/SymfonyTest.php +++ b/tests/integration/symfony4/tests/SymfonyTest.php @@ -25,7 +25,7 @@ class SymfonyTest extends TestCase private static $outputFile; private static $client; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$outputFile = sys_get_temp_dir() . '/spans.json'; self::$client = new Client([ @@ -33,9 +33,8 @@ public static function setUpBeforeClass() ]); } - public function setUp() + protected function setUp(): void { - parent::setUp(); $this->clearSpans(); } diff --git a/tests/integration/wordpress/composer.json b/tests/integration/wordpress/composer.json index 9b32b05ee..e39b37f2b 100644 --- a/tests/integration/wordpress/composer.json +++ b/tests/integration/wordpress/composer.json @@ -1,12 +1,12 @@ { "require": { - "php": "^7.2", + "php": ">=7.1", "opencensus/opencensus": "dev-master", "ext-opencensus": "*" }, "require-dev": { "wp-cli/wp-cli": "~1.1", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.0", "guzzlehttp/guzzle": "~6.0" }, "repositories": [ diff --git a/tests/integration/wordpress/tests/integration/WordpressTest.php b/tests/integration/wordpress/tests/integration/WordpressTest.php index 5af8d75fb..cb092cd5a 100644 --- a/tests/integration/wordpress/tests/integration/WordpressTest.php +++ b/tests/integration/wordpress/tests/integration/WordpressTest.php @@ -24,14 +24,13 @@ class WordpressTest extends TestCase { private static $outputFile; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$outputFile = sys_get_temp_dir() . '/spans.json'; } - public function setUp() + protected function setUp(): void { - parent::setUp(); if (file_exists(self::$outputFile)) { $fp = fopen(self::$outputFile, 'r+'); ftruncate($fp, 0); @@ -49,7 +48,7 @@ public function testReportsTraceToFile() ] ]); $this->assertEquals(200, $response->getStatusCode()); - $this->assertContains('Hello world!', $response->getBody()->getContents()); + $this->assertStringContainsString('Hello world!', $response->getBody()->getContents()); $spans = json_decode(file_get_contents(self::$outputFile), true); $this->assertNotEmpty($spans); diff --git a/tests/unit/Core/ContextTest.php b/tests/unit/Core/ContextTest.php index e29f461b7..b56bfa193 100644 --- a/tests/unit/Core/ContextTest.php +++ b/tests/unit/Core/ContextTest.php @@ -25,14 +25,15 @@ */ class ContextTest extends TestCase { - public function setUp() + protected function setUp(): void { Context::reset(); } - public function tearDown() + protected function tearDown(): void { Context::reset(); + parent::tearDown(); } public function testBackgroundGeneratesEmptyContext() @@ -68,11 +69,10 @@ public function testRestoringCurrentContext() $this->assertEquals($initialContext, Context::current()); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testRestoringCurrentContextRequiresSameObject() { + $this->expectException(\PHPUnit\Framework\Error\Warning::class); + $context = new Context(['foo' => 'bar']); $prevContext = $context->attach(); diff --git a/tests/unit/Core/ScopeTest.php b/tests/unit/Core/ScopeTest.php index 9ed634111..0be2fb11a 100644 --- a/tests/unit/Core/ScopeTest.php +++ b/tests/unit/Core/ScopeTest.php @@ -27,7 +27,7 @@ class ScopeTest extends TestCase { private $data; - public function setUp() + protected function setUp(): void { $this->data = []; } diff --git a/tests/unit/Trace/Exporter/FileExporterTest.php b/tests/unit/Trace/Exporter/FileExporterTest.php index 1f4718b55..f6c7d1539 100644 --- a/tests/unit/Trace/Exporter/FileExporterTest.php +++ b/tests/unit/Trace/Exporter/FileExporterTest.php @@ -29,14 +29,15 @@ class FileExporterTest extends TestCase private $tracer; private $filename; - public function setUp() + protected function setUp(): void { $this->filename = tempnam(sys_get_temp_dir(), 'traces'); } - public function tearDown() + protected function tearDown(): void { @unlink($this->filename); + parent::tearDown(); } public function testLogsTrace() diff --git a/tests/unit/Trace/Exporter/LoggerExporterTest.php b/tests/unit/Trace/Exporter/LoggerExporterTest.php index 2f9de6d09..5006bea65 100644 --- a/tests/unit/Trace/Exporter/LoggerExporterTest.php +++ b/tests/unit/Trace/Exporter/LoggerExporterTest.php @@ -33,7 +33,7 @@ class LoggerExporterTest extends TestCase private $tracer; private $logger; - public function setUp() + protected function setUp(): void { $this->logger = $this->prophesize(LoggerInterface::class); } diff --git a/tests/unit/Trace/Integrations/Guzzle/EventSubscriberTest.php b/tests/unit/Trace/Integrations/Guzzle/EventSubscriberTest.php index 4d68df645..a23a515a8 100644 --- a/tests/unit/Trace/Integrations/Guzzle/EventSubscriberTest.php +++ b/tests/unit/Trace/Integrations/Guzzle/EventSubscriberTest.php @@ -35,7 +35,7 @@ class EventSubscriberTest extends TestCase { private $exporter; - public function setUp() + protected function setUp(): void { $this->exporter = $this->prophesize(ExporterInterface::class); if (extension_loaded('opencensus')) { diff --git a/tests/unit/Trace/Integrations/Guzzle/MiddlewareTest.php b/tests/unit/Trace/Integrations/Guzzle/MiddlewareTest.php index 7a2884279..cfecb299f 100644 --- a/tests/unit/Trace/Integrations/Guzzle/MiddlewareTest.php +++ b/tests/unit/Trace/Integrations/Guzzle/MiddlewareTest.php @@ -33,7 +33,7 @@ class MiddlewareTest extends TestCase { private $exporter; - public function setUp() + protected function setUp(): void { $this->exporter = $this->prophesize(ExporterInterface::class); if (extension_loaded('opencensus')) { diff --git a/tests/unit/Trace/Propagator/BinaryFormatterTest.php b/tests/unit/Trace/Propagator/BinaryFormatterTest.php index 5699bb2cb..fa884c5e7 100644 --- a/tests/unit/Trace/Propagator/BinaryFormatterTest.php +++ b/tests/unit/Trace/Propagator/BinaryFormatterTest.php @@ -49,11 +49,10 @@ public function testSerialize($traceId, $spanId, $enabled, $hex) $this->assertEquals($hex, bin2hex($formatter->serialize($context))); } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function testDeserializeBadData() { + $this->expectException(\PHPUnit\Framework\Error\Warning::class); + $formatter = new BinaryFormatter(); $context = $formatter->deserialize(hex2bin("0012341abc")); } diff --git a/tests/unit/Trace/RequestHandlerTest.php b/tests/unit/Trace/RequestHandlerTest.php index 9865e4d17..666723261 100644 --- a/tests/unit/Trace/RequestHandlerTest.php +++ b/tests/unit/Trace/RequestHandlerTest.php @@ -43,7 +43,7 @@ class RequestHandlerTest extends TestCase private $sampler; - public function setUp() + protected function setUp(): void { if (extension_loaded('opencensus')) { opencensus_trace_clear(); diff --git a/tests/unit/Trace/Sampler/ProbabilitySamplerTest.php b/tests/unit/Trace/Sampler/ProbabilitySamplerTest.php index a46321213..c397680b8 100644 --- a/tests/unit/Trace/Sampler/ProbabilitySamplerTest.php +++ b/tests/unit/Trace/Sampler/ProbabilitySamplerTest.php @@ -27,10 +27,11 @@ class ProbabilitySamplerTest extends TestCase { /** * @dataProvider invalidRates - * @expectedException \InvalidArgumentException */ public function testInvalidRate($rate) { + $this->expectException(\InvalidArgumentException::class); + $sampler = new ProbabilitySampler($rate); } diff --git a/tests/unit/Trace/Sampler/QpsSamplerTest.php b/tests/unit/Trace/Sampler/QpsSamplerTest.php index c739e6f24..fdd7beab6 100644 --- a/tests/unit/Trace/Sampler/QpsSamplerTest.php +++ b/tests/unit/Trace/Sampler/QpsSamplerTest.php @@ -63,10 +63,11 @@ public function testNotCached() /** * @dataProvider invalidRates - * @expectedException \InvalidArgumentException */ public function testInvalidRate($rate) { + $this->expectException(\InvalidArgumentException::class); + $cache = $this->prophesize(CacheItemPoolInterface::class); $sampler = new QpsSampler($cache->reveal(), [ 'rate' => $rate diff --git a/tests/unit/Trace/SpanDataTest.php b/tests/unit/Trace/SpanDataTest.php index 2ef4f330c..c7db795ca 100644 --- a/tests/unit/Trace/SpanDataTest.php +++ b/tests/unit/Trace/SpanDataTest.php @@ -85,7 +85,7 @@ public function testStackTraceHashIdIsRepeatable() ]); $hashId = $spanData->stackTraceHashId(); - $this->assertInternalType('string', $hashId); + $this->assertIsString($hashId); $this->assertEquals($hashId, $spanData2->stackTraceHashId()); } } diff --git a/tests/unit/Trace/SpanTest.php b/tests/unit/Trace/SpanTest.php index 412629cdd..0ae8951f6 100644 --- a/tests/unit/Trace/SpanTest.php +++ b/tests/unit/Trace/SpanTest.php @@ -101,7 +101,7 @@ public function testGeneratesBacktrace() $span = new Span(); $stackTrace = $span->spanData()->stackTrace(); - $this->assertInternalType('array', $stackTrace); + $this->assertIsArray($stackTrace); $this->assertNotEmpty($stackTrace); $stackframe = $stackTrace[0]; $this->assertEquals('testGeneratesBacktrace', $stackframe['function']); diff --git a/tests/unit/Trace/Tracer/AbstractTracerTest.php b/tests/unit/Trace/Tracer/AbstractTracerTest.php index 659ce996c..1609abc80 100644 --- a/tests/unit/Trace/Tracer/AbstractTracerTest.php +++ b/tests/unit/Trace/Tracer/AbstractTracerTest.php @@ -278,7 +278,7 @@ public function testStackTraceShouldBeSet() $this->assertCount(1, $spans); $spanData = $spans[0]; - $this->assertInternalType('array', $spanData->stackTrace()); + $this->assertIsArray($spanData->stackTrace()); $this->assertNotEmpty($spanData->stackTrace()); } @@ -294,7 +294,7 @@ public function testAttributesShouldBeSet() $this->assertCount(1, $spans); $spanData = $spans[0]; - $this->assertInternalType('array', $spanData->attributes()); + $this->assertIsArray($spanData->attributes()); $this->assertEmpty($spanData->attributes()); } @@ -310,7 +310,7 @@ public function testLinksShouldBeSet() $this->assertCount(1, $spans); $spanData = $spans[0]; - $this->assertInternalType('array', $spanData->links()); + $this->assertIsArray($spanData->links()); $this->assertEmpty($spanData->links()); } @@ -326,7 +326,7 @@ public function testTimeEventsShouldBeSet() $this->assertCount(1, $spans); $spanData = $spans[0]; - $this->assertInternalType('array', $spanData->timeEvents()); + $this->assertIsArray($spanData->timeEvents()); $this->assertEmpty($spanData->timeEvents()); } diff --git a/tests/unit/Trace/Tracer/ContextTracerTest.php b/tests/unit/Trace/Tracer/ContextTracerTest.php index 0149a7762..98ff3b45a 100644 --- a/tests/unit/Trace/Tracer/ContextTracerTest.php +++ b/tests/unit/Trace/Tracer/ContextTracerTest.php @@ -25,7 +25,7 @@ */ class ContextTracerTest extends AbstractTracerTest { - public function setUp() + protected function setUp(): void { Context::reset(); } diff --git a/tests/unit/Trace/Tracer/ExtentionTracerTest.php b/tests/unit/Trace/Tracer/ExtentionTracerTest.php index 1b659607a..e1e493ffe 100644 --- a/tests/unit/Trace/Tracer/ExtentionTracerTest.php +++ b/tests/unit/Trace/Tracer/ExtentionTracerTest.php @@ -24,7 +24,7 @@ */ class ExtensionTracerTest extends AbstractTracerTest { - public function setUp() + protected function setUp(): void { if (!extension_loaded('opencensus')) { $this->markTestSkipped('Must have the opencensus extension installed to run this test.'); diff --git a/tests/unit/Trace/TracerTest.php b/tests/unit/Trace/TracerTest.php index 7f8a7d7e2..2e12f8a08 100644 --- a/tests/unit/Trace/TracerTest.php +++ b/tests/unit/Trace/TracerTest.php @@ -31,7 +31,7 @@ class TracerTest extends TestCase { private $reporter; - public function setUp() + protected function setUp(): void { $this->reporter = $this->prophesize(ExporterInterface::class); }