PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_class_mysqli_result_interface.php

http://github.com/facebook/hiphop-php
PHP | 143 lines | 116 code | 26 blank | 1 comment | 21 complexity | a5e364c78c388925a9e99af10d577472 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. require('connect.inc');
  3. $test_table_name = 'test_mysqli_class_mysqli_result_interface_table_1'; require('table.inc');
  4. $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
  5. $mysqli_result = $mysqli->query('SELECT * FROM test_mysqli_class_mysqli_result_interface_table_1');
  6. $row = $mysqli_result->fetch_row();
  7. $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
  8. $res = mysqli_query($link, 'SELECT * FROM test_mysqli_class_mysqli_result_interface_table_1');
  9. assert(mysqli_fetch_row($res) === $row);
  10. printf("Parent class:\n");
  11. var_dump(get_parent_class($mysqli_result));
  12. printf("\nMethods:\n");
  13. $methods = get_class_methods($mysqli_result);
  14. $expected_methods = array(
  15. '__construct' => true,
  16. 'close' => true,
  17. 'data_seek' => true,
  18. 'fetch_array' => true,
  19. 'fetch_assoc' => true,
  20. 'fetch_field' => true,
  21. 'fetch_field_direct' => true,
  22. 'fetch_fields' => true,
  23. 'fetch_object' => true,
  24. 'fetch_row' => true,
  25. 'field_seek' => true,
  26. 'free' => true,
  27. 'free_result' => true,
  28. );
  29. if ($IS_MYSQLND)
  30. $expected_methods['fetch_all'] = true;
  31. foreach ($methods as $k => $method) {
  32. if (isset($expected_methods[$method])) {
  33. unset($expected_methods[$method]);
  34. unset($methods[$k]);
  35. }
  36. if ($method == 'mysqli_result') {
  37. // get_class_method reports different constructor names
  38. unset($expected_methods['__construct']);
  39. unset($methods[$k]);
  40. }
  41. }
  42. if (!empty($expected_methods)) {
  43. printf("Dumping list of missing methods.\n");
  44. var_dump($expected_methods);
  45. }
  46. if (!empty($methods)) {
  47. printf("Dumping list of unexpected methods.\n");
  48. var_dump($methods);
  49. }
  50. if (empty($expected_methods) && empty($methods))
  51. printf("ok\n");
  52. printf("\nClass variables:\n");
  53. $variables = array_keys(get_class_vars(get_class($mysqli_result)));
  54. sort($variables);
  55. foreach ($variables as $k => $var)
  56. printf("%s\n", $var);
  57. printf("\nObject variables:\n");
  58. $variables = array_keys(get_object_vars($mysqli_result));
  59. foreach ($variables as $k => $var)
  60. printf("%s\n", $var);
  61. printf("\nMagic, magic properties:\n");
  62. assert(($tmp = mysqli_field_tell($res)) === $mysqli_result->current_field);
  63. printf("mysqli_result->current_field = '%s'/%s ('%s'/%s)\n",
  64. $mysqli_result->current_field, gettype($mysqli_result->current_field),
  65. $tmp, gettype($tmp));
  66. assert(($tmp = mysqli_field_count($link)) === $mysqli_result->field_count);
  67. printf("mysqli_result->field_count = '%s'/%s ('%s'/%s)\n",
  68. $mysqli_result->field_count, gettype($mysqli_result->field_count),
  69. $tmp, gettype($tmp));
  70. assert(($tmp = mysqli_fetch_lengths($res)) === $mysqli_result->lengths);
  71. printf("mysqli_result->lengths -> '%s'/%s ('%s'/%s)\n",
  72. ((is_array($mysqli_result->lengths)) ? implode(' ', $mysqli_result->lengths) : 'n/a'),
  73. gettype($mysqli_result->lengths),
  74. ((is_array($tmp)) ? implode(' ', $tmp) : 'n/a'),
  75. gettype($tmp));
  76. assert(($tmp = mysqli_num_rows($res)) === $mysqli_result->num_rows);
  77. printf("mysqli_result->num_rows = '%s'/%s ('%s'/%s)\n",
  78. $mysqli_result->num_rows, gettype($mysqli_result->num_rows),
  79. $tmp, gettype($tmp));
  80. assert(in_array($mysqli_result->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT)));
  81. printf("mysqli_result->type = '%s'/%s\n",
  82. ((MYSQLI_STORE_RESULT == $mysqli_result->type) ? 'store' : 'use'),
  83. gettype($mysqli_result->type));
  84. printf("\nAccess to undefined properties:\n");
  85. printf("mysqli_result->unknown = '%s'\n", @$mysqli_result->unknown);
  86. printf("\nConstructor:\n");
  87. if (!is_object($res = new mysqli_result($link)))
  88. printf("[001] Expecting object/mysqli_result got %s/%s\n", gettye($res), $res);
  89. if (!mysqli_query($link, "SELECT id FROM test_mysqli_class_mysqli_result_interface_table_1 ORDER BY id"))
  90. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  91. if (!is_object($res = new mysqli_result($link)))
  92. printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  93. if (!is_object($res = new mysqli_result($link, MYSQLI_STORE_RESULT)))
  94. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  95. if (!is_object($res = new mysqli_result($link, MYSQLI_USE_RESULT)))
  96. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  97. if (!is_object($res = new mysqli_result($link, 'invalid')))
  98. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  99. $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT);
  100. do {
  101. $mode = mt_rand(-1000, 1000);
  102. } while (in_array($mode, $valid));
  103. if ($TEST_EXPERIMENTAL) {
  104. ob_start();
  105. if (!is_object($res = new mysqli_result($link, $mode)))
  106. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  107. $content = ob_get_contents();
  108. ob_end_clean();
  109. if (!stristr($content, 'Invalid value for resultmode'))
  110. printf("[009] Expecting warning because of invalid resultmode\n");
  111. }
  112. if (!is_object($res = new mysqli_result('foo')))
  113. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  114. if (!is_object($res = @new mysqli_result($link, MYSQLI_STORE_RESULT, 1)))
  115. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  116. print "done!";
  117. ?>