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