Add pdo_sqlite tests for empty filename and in-memory uri (#7662)

pdo_sqlite already supports empty filenames and shared in-memory DBs. Add tests for them.
This commit is contained in:
othercorey 2021-11-24 07:49:10 -06:00 committed by GitHub
parent 067df26344
commit 108bd4417a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 111 additions and 0 deletions

View file

@ -0,0 +1,20 @@
--TEST--
PDO_sqlite: Testing empty filename
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
// create with empty filename
$db = new PDO('sqlite:');
var_dump($db->exec('CREATE TABLE test1 (id INT);'));
// create with empty URI
$db = new PDO('sqlite:file:?cache=shared');
var_dump($db->exec('CREATE TABLE test1 (id INT);'));
?>
--EXPECT--
int(0)
int(0)

View file

@ -5,6 +5,16 @@ pdo_sqlite
--FILE-- --FILE--
<?php <?php
// create with in-memory database using shared cached
$db = new PDO('sqlite:file::memory:?cache=shared');
var_dump($db->exec('CREATE TABLE test1 (id INT);'));
// create second connection to in-memory database
$db = new PDO('sqlite:file::memory:?cache=shared');
var_dump($db->exec('SELECT * from test1'));
// create with default read-write|create mode // create with default read-write|create mode
$filename = "file:" . __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_filename_uri.db"; $filename = "file:" . __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_filename_uri.db";
@ -29,6 +39,8 @@ if (file_exists($filename)) {
?> ?>
--EXPECTF-- --EXPECTF--
int(0) int(0)
int(0)
int(0)
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s
Stack trace: Stack trace:

View file

@ -0,0 +1,47 @@
--TEST--
PDO_sqlite: Testing filenames with open_basedir
--EXTENSIONS--
pdo_sqlite
--INI--
open_basedir=.
--FILE--
<?php
// create in basedir
$filename = 'pdo_sqlite_filename.db';
$db = new PDO('sqlite:' . $filename);
var_dump($db->exec('CREATE TABLE test1 (id INT);'));
// create outside basedir
$filename = '..' . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db';
new PDO('sqlite:' . $filename);
?>
--CLEAN--
<?php
$filenames = [
'pdo_sqlite_filename.db',
'..' . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db',
];
foreach ($filenames as $filename) {
if (file_exists($filename)) {
unlink($filename);
}
}
?>
--EXPECTF--
int(0)
Fatal error: Uncaught PDOException: PDO::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s:%d
Stack trace:
%s
#1 {main}
Next PDOException: open_basedir prohibits opening %s in %s:%d
Stack trace:
%s
#1 {main}
thrown in %s

View file

@ -0,0 +1,32 @@
--TEST--
PDO_sqlite: Testing URIs with open_basedir
--EXTENSIONS--
pdo_sqlite
--INI--
open_basedir={TMP}
--FILE--
<?php
// create in basedir
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db';
new PDO('sqlite:file:' . $filename);
?>
--CLEAN--
<?php
$filenames = [
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db',
];
foreach ($filenames as $filename) {
if (file_exists($filename)) {
unlink($filename);
}
}
?>
--EXPECTF--
Fatal error: Uncaught PDOException: open_basedir prohibits opening %s in %s:%d
Stack trace:
%s
#1 {main}
thrown in %s