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