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