snmp-object-error.phpt 2.9 KB

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