snmp-object-properties.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. --TEST--
  2. OO API: SNMP object properties
  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_enum_print(false);
  16. snmp_set_quick_print(false);
  17. snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
  18. snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
  19. echo "Check working\n";
  20. $session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
  21. var_dump($session);
  22. $session->max_oids = 40;
  23. $session->enum_print = TRUE;
  24. $session->quick_print = TRUE;
  25. $session->valueretrieval = SNMP_VALUE_LIBRARY;
  26. $session->oid_output_format = SNMP_OID_OUTPUT_NUMERIC;
  27. $session->oid_increasing_check = FALSE;
  28. var_dump($session);
  29. $session->max_oids = "40";
  30. $session->enum_print = "1";
  31. $session->quick_print = "1";
  32. $session->valueretrieval = "1";
  33. $session->oid_output_format = "3";
  34. $session->oid_increasing_check = "45";
  35. var_dump($session);
  36. var_dump(property_exists($session, "enum_print"));
  37. var_dump(isset($session->enum_print));
  38. var_dump(empty($session->enum_print));
  39. $param=123;
  40. $session->$param = "param_value";
  41. var_dump($session);
  42. var_dump($session->$param);
  43. var_dump(property_exists($session, $param));
  44. echo "Error handling\n";
  45. $param = 'there is no such parameter';
  46. var_dump($session->$param);
  47. var_dump(property_exists($session, $param));
  48. try {
  49. $session->valueretrieval = 67;
  50. var_dump($session->valueretrieval);
  51. } catch (\ValueError $e) {
  52. echo $e->getMessage() . \PHP_EOL;
  53. }
  54. try {
  55. $session->oid_output_format = 78;
  56. var_dump($session->oid_output_format);
  57. } catch (\ValueError $e) {
  58. echo $e->getMessage() . \PHP_EOL;
  59. }
  60. try {
  61. $session->info = array("blah" => 2);
  62. var_dump($session->info);
  63. } catch (\Error $e) {
  64. echo $e->getMessage() . \PHP_EOL;
  65. }
  66. $session->max_oids = NULL;
  67. var_dump($session->max_oids);
  68. ?>
  69. --EXPECTF--
  70. Check working
  71. object(SNMP)#%d (%d) {
  72. ["info"]=>
  73. array(3) {
  74. ["hostname"]=>
  75. string(%d) "%s"
  76. ["timeout"]=>
  77. int(%i)
  78. ["retries"]=>
  79. int(%d)
  80. }
  81. ["max_oids"]=>
  82. NULL
  83. ["valueretrieval"]=>
  84. int(1)
  85. ["quick_print"]=>
  86. bool(false)
  87. ["enum_print"]=>
  88. bool(false)
  89. ["oid_output_format"]=>
  90. int(3)
  91. ["oid_increasing_check"]=>
  92. bool(true)
  93. ["exceptions_enabled"]=>
  94. int(0)
  95. }
  96. object(SNMP)#%d (%d) {
  97. ["info"]=>
  98. array(3) {
  99. ["hostname"]=>
  100. string(%d) "%s"
  101. ["timeout"]=>
  102. int(%i)
  103. ["retries"]=>
  104. int(%d)
  105. }
  106. ["max_oids"]=>
  107. int(40)
  108. ["valueretrieval"]=>
  109. int(0)
  110. ["quick_print"]=>
  111. bool(true)
  112. ["enum_print"]=>
  113. bool(true)
  114. ["oid_output_format"]=>
  115. int(4)
  116. ["oid_increasing_check"]=>
  117. bool(false)
  118. ["exceptions_enabled"]=>
  119. int(0)
  120. }
  121. object(SNMP)#%d (%d) {
  122. ["info"]=>
  123. array(3) {
  124. ["hostname"]=>
  125. string(%d) "%s"
  126. ["timeout"]=>
  127. int(%i)
  128. ["retries"]=>
  129. int(%d)
  130. }
  131. ["max_oids"]=>
  132. int(40)
  133. ["valueretrieval"]=>
  134. int(1)
  135. ["quick_print"]=>
  136. bool(true)
  137. ["enum_print"]=>
  138. bool(true)
  139. ["oid_output_format"]=>
  140. int(3)
  141. ["oid_increasing_check"]=>
  142. bool(true)
  143. ["exceptions_enabled"]=>
  144. int(0)
  145. }
  146. bool(true)
  147. bool(true)
  148. bool(false)
  149. object(SNMP)#%d (%d) {
  150. ["info"]=>
  151. array(3) {
  152. ["hostname"]=>
  153. string(%d) "%s"
  154. ["timeout"]=>
  155. int(%i)
  156. ["retries"]=>
  157. int(%d)
  158. }
  159. ["max_oids"]=>
  160. int(40)
  161. ["valueretrieval"]=>
  162. int(1)
  163. ["quick_print"]=>
  164. bool(true)
  165. ["enum_print"]=>
  166. bool(true)
  167. ["oid_output_format"]=>
  168. int(3)
  169. ["oid_increasing_check"]=>
  170. bool(true)
  171. ["exceptions_enabled"]=>
  172. int(0)
  173. ["123"]=>
  174. string(11) "param_value"
  175. }
  176. string(11) "param_value"
  177. bool(true)
  178. Error handling
  179. Warning: Undefined property: SNMP::$there is no such parameter in %s on line %d
  180. NULL
  181. bool(false)
  182. SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
  183. SNMP output print format must be an SNMP_OID_OUTPUT_* constant
  184. Cannot write read-only property SNMP::$info
  185. NULL