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