From 905c79c05c4194b0bc58d6e8e85895fc91c28be5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 8 Sep 2020 17:01:08 +0200 Subject: [PATCH] Fix some snmp stubs As well as some basic mistakes in tests. --- ext/snmp/snmp.stub.php | 12 +++---- ext/snmp/snmp_arginfo.h | 37 ++++++++++++++++------ ext/snmp/tests/snmp-object-error.phpt | 6 ++-- ext/snmp/tests/snmp-object-properties.phpt | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 1b7c1ac20e..e7592ee67b 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -2,9 +2,9 @@ /** @generate-function-entries */ -function snmpget(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmpget(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} -function snmpgetnext(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmpgetnext(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} function snmpwalk(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} @@ -26,9 +26,9 @@ function snmp_set_oid_output_format(int $oid_format): bool {} /** @alias snmp_set_oid_output_format */ function snmp_set_oid_numeric_print(int $oid_format): bool {} -function snmp2_get(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmp2_get(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} -function snmp2_getnext(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmp2_getnext(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} function snmp2_walk(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} @@ -36,9 +36,9 @@ function snmp2_real_walk(string $host, string $community, array|string $object_i function snmp2_set(string $host, string $community, array|string $object_id, array|string $type, array|string $value, int $timeout = -1, int $retries = -1): array|bool {} -function snmp3_get(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmp3_get(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} -function snmp3_getnext(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} +function snmp3_getnext(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): stdClass|array|string|bool {} function snmp3_walk(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 5c4a0c35a8..8bfd40833f 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,7 +1,7 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: c9906ff8ef879e567cf8aed9a34dcff850f3e949 */ + * Stub hash: 759c8a5e721d1c6c9cb63e59ae14f85831396a4d */ -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmpget, 0, 3, MAY_BE_ARRAY|MAY_BE_BOOL) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_snmpget, 0, 3, stdClass, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, community, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) @@ -11,11 +11,17 @@ ZEND_END_ARG_INFO() #define arginfo_snmpgetnext arginfo_snmpget -#define arginfo_snmpwalk arginfo_snmpget +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmpwalk, 0, 3, MAY_BE_ARRAY|MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, community, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retries, IS_LONG, 0, "-1") +ZEND_END_ARG_INFO() -#define arginfo_snmprealwalk arginfo_snmpget +#define arginfo_snmprealwalk arginfo_snmpwalk -#define arginfo_snmpwalkoid arginfo_snmpget +#define arginfo_snmpwalkoid arginfo_snmpwalk ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmpset, 0, 5, MAY_BE_ARRAY|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) @@ -48,13 +54,13 @@ ZEND_END_ARG_INFO() #define arginfo_snmp2_getnext arginfo_snmpget -#define arginfo_snmp2_walk arginfo_snmpget +#define arginfo_snmp2_walk arginfo_snmpwalk -#define arginfo_snmp2_real_walk arginfo_snmpget +#define arginfo_snmp2_real_walk arginfo_snmpwalk #define arginfo_snmp2_set arginfo_snmpset -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmp3_get, 0, 8, MAY_BE_ARRAY|MAY_BE_BOOL) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_snmp3_get, 0, 8, stdClass, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, sec_name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, sec_level, IS_STRING, 0) @@ -69,9 +75,20 @@ ZEND_END_ARG_INFO() #define arginfo_snmp3_getnext arginfo_snmp3_get -#define arginfo_snmp3_walk arginfo_snmp3_get +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmp3_walk, 0, 8, MAY_BE_ARRAY|MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, sec_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, sec_level, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, auth_protocol, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, auth_passphrase, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, priv_protocol, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, priv_passphrase, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retries, IS_LONG, 0, "-1") +ZEND_END_ARG_INFO() -#define arginfo_snmp3_real_walk arginfo_snmp3_get +#define arginfo_snmp3_real_walk arginfo_snmp3_walk ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmp3_set, 0, 10, MAY_BE_ARRAY|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) diff --git a/ext/snmp/tests/snmp-object-error.phpt b/ext/snmp/tests/snmp-object-error.phpt index 56db079c35..9185d8d576 100644 --- a/ext/snmp/tests/snmp-object-error.phpt +++ b/ext/snmp/tests/snmp-object-error.phpt @@ -31,7 +31,7 @@ try { } try { var_dump(new SNMP(7, $hostname, $community)); -} catch (Exception $e) { +} catch (ValueError $e) { print $e->getMessage() . "\n"; } @@ -70,8 +70,8 @@ var_dump($session->max_oids); ?> --EXPECTF-- SNMP::__construct() expects at least 3 parameters, 2 given -SNMP::__construct(): Argument #4 must be of type int, string given -SNMP::__construct(): Argument #5 must be of type int, string given +SNMP::__construct(): Argument #4 ($timeout) must be of type int, string given +SNMP::__construct(): Argument #5 ($retries) must be of type int, string given SNMP::__construct(): Argument #1 ($version) must be a valid SNMP protocol version Exception handling diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index 0cce9a5e8d..6bcee4157f 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -184,7 +184,7 @@ string(11) "param_value" bool(true) Error handling -Notice: Undefined property: SNMP::$there is no such parameter in %s on line %d +Warning: Undefined property: SNMP::$there is no such parameter in %s on line %d NULL bool(false) -- 2.40.0