1--TEST--
2OO API: Generic errors
3--CREDITS--
4Boris Lytochkin
5--EXTENSIONS--
6snmp
7--SKIPIF--
8<?php
9require_once(__DIR__.'/skipif.inc');
10if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN');
11?>
12--FILE--
13<?php
14require_once(__DIR__.'/snmp_include.inc');
15
16//EXPECTF format is quickprint OFF
17snmp_set_quick_print(false);
18snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
19
20try {
21    var_dump(new SNMP(SNMP::VERSION_1, $hostname));
22} catch (TypeError $e) {
23    print $e->getMessage() . "\n";
24}
25try {
26    var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, ''));
27} catch (TypeError $e) {
28    print $e->getMessage() . "\n";
29}
30try {
31    var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, ''));
32} catch (TypeError $e) {
33    print $e->getMessage() . "\n";
34}
35try {
36    var_dump(new SNMP(7, $hostname, $community));
37} catch (ValueError $e) {
38    print $e->getMessage() . "\n";
39}
40
41echo "Exception handling\n";
42$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
43try {
44    var_dump($session->get('.1.3.6.1.2.1.1.1..0'));
45} catch (SNMPException $e) {
46    var_dump($e->getCode());
47    var_dump($e->getMessage());
48}
49$session->exceptions_enabled = SNMP::ERRNO_ANY;
50try {
51    var_dump($session->get('.1.3.6.1.2.1.1.1..0'));
52} catch (SNMPException $e) {
53    var_dump($e->getCode());
54    var_dump($e->getMessage());
55}
56var_dump($session->close());
57
58echo "Open normal session\n";
59$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
60try {
61    $session->valueretrieval = 67;
62    var_dump($session->valueretrieval);
63} catch (\ValueError $e) {
64    echo $e->getMessage() . \PHP_EOL;
65}
66echo "Closing session\n";
67var_dump($session->close());
68
69try {
70    var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
71    var_dump($session->close());
72} catch (\Error $e) {
73    echo $e->getMessage() . \PHP_EOL;
74}
75
76$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
77
78var_dump($session->max_oids);
79try {
80    $session->max_oids = "ttt";
81} catch (TypeError $e) {
82    echo $e->getMessage() . \PHP_EOL;
83}
84try {
85    $session->max_oids = 0;
86} catch (\ValueError $e) {
87    echo $e->getMessage() . \PHP_EOL;
88}
89var_dump($session->max_oids);
90?>
91--EXPECTF--
92SNMP::__construct() expects at least 3 arguments, 2 given
93SNMP::__construct(): Argument #4 ($timeout) must be of type int, string given
94SNMP::__construct(): Argument #5 ($retries) must be of type int, string given
95SNMP::__construct(): Argument #1 ($version) must be a valid SNMP protocol version
96Exception handling
97
98Warning: SNMP::get(): Invalid object identifier: .1.3.6.1.2.1.1.1..0 in %s on line %d
99bool(false)
100int(32)
101string(46) "Invalid object identifier: .1.3.6.1.2.1.1.1..0"
102bool(true)
103Open normal session
104SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
105Closing session
106bool(true)
107Invalid or uninitialized SNMP object
108NULL
109Cannot assign string to property SNMP::$max_oids of type ?int
110SNMP::$max_oids must be greater than 0 or null
111NULL
112