Skip to content

Commit

Permalink
Fix some snmp stubs
Browse files Browse the repository at this point in the history
As well as some basic mistakes in tests.
  • Loading branch information
nikic committed Sep 8, 2020
1 parent 6e91a2e commit 905c79c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
12 changes: 6 additions & 6 deletions ext/snmp/snmp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -26,19 +26,19 @@ 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 {}

function snmp2_real_walk(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {}

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 {}

Expand Down
37 changes: 27 additions & 10 deletions ext/snmp/snmp_arginfo.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ext/snmp/tests/snmp-object-error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {
}
try {
var_dump(new SNMP(7, $hostname, $community));
} catch (Exception $e) {
} catch (ValueError $e) {
print $e->getMessage() . "\n";
}

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ext/snmp/tests/snmp-object-properties.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 905c79c

Please sign in to comment.