xref: /PHP-8.1/ext/pdo_pgsql/tests/bug72294.phpt (revision 39131219)
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    public function run( $test)
74    {
75        $error      = false;
76
77        $oldErrorHandler = set_error_handler(
78            'handleError',
79            E_ALL
80        );
81
82        try {
83            $test->runBare();
84        } catch (RuntimeException $e) {
85            $error = true;
86        }
87
88        restore_error_handler();
89
90        if ($error === true) {
91            $this->errors[] = new PHPUnit_Framework_TestFailure($test, $e);
92        }
93    }
94}
95
96$result = new PHPUnit_Framework_TestResult();
97
98class PreparedStatementCache
99{
100    private $cached_statements = array();
101
102    public function prepare( $pdo, $sql )
103    {
104        //return $pdo->prepare( $sql );
105        $this->cached_statements[$sql] = $pdo->prepare( $sql );
106
107    return $this->cached_statements[$sql];
108    }
109}
110
111class DatabaseTest extends PHPUnit_Framework_TestCase
112{
113    public function testIt()
114    {
115    $pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
116
117    $prepared_statement_cache = new PreparedStatementCache( $pdo );
118
119    for( $i = 1; $i <= 300; ++$i ) {
120        $statement = $prepared_statement_cache->prepare( $pdo,  <<<SQL
121                SELECT $i;
122SQL
123        );
124            $statement->execute();
125    }
126    }
127
128    public function test_construct()
129    {
130    $pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
131
132    $pdo->exec( 'CREATE TEMPORARY TABLE temp_table ( test_column INT NOT NULL );' );
133
134    $this->cache = new PreparedStatementCache( $pdo );
135
136    $statement = $this->cache->prepare( $pdo, 'SELECT * FROM temp_table WHERE test_column > 0' );
137    $statement->execute();
138    }
139}
140
141$test = new DatabaseTest();
142$test->setName( 'testIt' );
143$test->run( $result );
144$test->setName( 'test_construct' );
145$test->run( $result );
146
147?>
148==NOCRASH==
149--EXPECT--
150==NOCRASH==
151