mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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:
parent
067df26344
commit
108bd4417a
4 changed files with 111 additions and 0 deletions
20
ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt
Normal file
20
ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt
Normal 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)
|
|
@ -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:
|
||||||
|
|
47
ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt
Normal file
47
ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt
Normal 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
|
32
ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt
Normal file
32
ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue