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