bug72294.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. --TEST--
  2. Bug #72294 Segmentation fault/invalid pointer in connection with pgsql_stmt_dtor
  3. --EXTENSIONS--
  4. pdo
  5. pdo_pgsql
  6. --SKIPIF--
  7. <?php
  8. require __DIR__ . '/config.inc';
  9. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  10. PDOTest::skip();
  11. ?>
  12. --FILE--
  13. <?php
  14. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  15. function handleError($errno, $errstr, $errfile, $errline)
  16. {
  17. if (!($errno & error_reporting())) {
  18. return false;
  19. }
  20. throw new RuntimeException( $errstr, $errno );
  21. }
  22. abstract class PHPUnit_Framework_TestCase
  23. {
  24. private $name = null;
  25. private $result;
  26. public function run(PHPUnit_Framework_TestResult $result = null)
  27. {
  28. $result->run($this);
  29. }
  30. public function runBare()
  31. {
  32. $class = new ReflectionClass($this);
  33. $method = $class->getMethod($this->name);
  34. $method->invoke($this);
  35. if( $x ) {
  36. }
  37. }
  38. public function setName($name)
  39. {
  40. $this->name = $name;
  41. }
  42. }
  43. class PHPUnit_Framework_TestFailure
  44. {
  45. private $testName;
  46. protected $failedTest;
  47. protected $thrownException;
  48. public function __construct( $failedTest, $t)
  49. {
  50. if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) {
  51. $this->testName = $failedTest->toString();
  52. } else {
  53. $this->testName = get_class($failedTest);
  54. }
  55. $this->thrownException = $t;
  56. }
  57. }
  58. class PHPUnit_Framework_TestResult
  59. {
  60. public function run( $test)
  61. {
  62. $error = false;
  63. $oldErrorHandler = set_error_handler(
  64. 'handleError',
  65. E_ALL
  66. );
  67. try {
  68. $test->runBare();
  69. } catch (RuntimeException $e) {
  70. $error = true;
  71. }
  72. restore_error_handler();
  73. if ($error === true) {
  74. $this->errors[] = new PHPUnit_Framework_TestFailure($test, $e);
  75. }
  76. }
  77. }
  78. $result = new PHPUnit_Framework_TestResult();
  79. class PreparedStatementCache
  80. {
  81. private $cached_statements = array();
  82. public function prepare( $pdo, $sql )
  83. {
  84. //return $pdo->prepare( $sql );
  85. $this->cached_statements[$sql] = $pdo->prepare( $sql );
  86. return $this->cached_statements[$sql];
  87. }
  88. }
  89. class DatabaseTest extends PHPUnit_Framework_TestCase
  90. {
  91. public function testIt()
  92. {
  93. $pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
  94. $prepared_statement_cache = new PreparedStatementCache( $pdo );
  95. for( $i = 1; $i <= 300; ++$i ) {
  96. $statement = $prepared_statement_cache->prepare( $pdo, <<<SQL
  97. SELECT $i;
  98. SQL
  99. );
  100. $statement->execute();
  101. }
  102. }
  103. public function test_construct()
  104. {
  105. $pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
  106. $pdo->exec( 'CREATE TEMPORARY TABLE temp_table ( test_column INT NOT NULL );' );
  107. $this->cache = new PreparedStatementCache( $pdo );
  108. $statement = $this->cache->prepare( $pdo, 'SELECT * FROM temp_table WHERE test_column > 0' );
  109. $statement->execute();
  110. }
  111. }
  112. $test = new DatabaseTest();
  113. $test->setName( 'testIt' );
  114. $test->run( $result );
  115. $test->setName( 'test_construct' );
  116. $test->run( $result );
  117. ?>
  118. ==NOCRASH==
  119. --EXPECT--
  120. ==NOCRASH==