Skip to content

Commit 37cd00e

Browse files
committed
ext/pdo: Add a test with a fetchAll() call being interupted partways
1 parent 8a81d00 commit 37cd00e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
PDO Common: PDO::FETCH_FUNC with a call that throws an exception for one specific value
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if (false == $dir) die('skip no driver');
9+
require_once $dir . 'pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16+
$db = PDOTest::factory();
17+
18+
$db->exec('CREATE TABLE pdo_fetch_function_exception_in_call(id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10))');
19+
$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(1, 'A', 'alpha')");
20+
$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(2, 'B', 'beta')");
21+
$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(3, 'C', 'gamma')");
22+
$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(4, 'D', 'delta')");
23+
24+
$selectVals = $db->prepare('SELECT val1, val2 FROM pdo_fetch_function_exception_in_call');
25+
26+
function bogusCallback(string $val1, string $val2) {
27+
$r = $val1 . ': ' . $val2 . PHP_EOL;
28+
echo $r;
29+
if ($val2 === 'gamma') {
30+
throw new Exception("GAMMA IS BAD");
31+
}
32+
return $val1 . ': ' . $val2;
33+
}
34+
35+
$selectVals->execute();
36+
37+
try {
38+
$result = $selectVals->fetchAll(PDO::FETCH_FUNC, 'bogusCallback');
39+
var_dump($result);
40+
} catch (Throwable $e) {
41+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
42+
}
43+
44+
?>
45+
--CLEAN--
46+
<?php
47+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
48+
$db = PDOTest::factory();
49+
PDOTest::dropTableIfExists($db, "pdo_fetch_function_exception_in_call");
50+
?>
51+
--EXPECT--
52+
A: alpha
53+
B: beta
54+
C: gamma
55+
Exception: GAMMA IS BAD

0 commit comments

Comments
 (0)