diff options
Diffstat (limited to 'ext/pdo_sqlite/tests')
20 files changed, 141 insertions, 26 deletions
diff --git a/ext/pdo_sqlite/tests/bug33841.phpt b/ext/pdo_sqlite/tests/bug33841.phpt index 97a28ec5d3..1c9fe201f4 100644 --- a/ext/pdo_sqlite/tests/bug33841.phpt +++ b/ext/pdo_sqlite/tests/bug33841.phpt @@ -1,13 +1,13 @@ --TEST-- PDO SQLite Bug #33841 (rowCount() does not work on prepared statements) --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> --FILE-- <?php -require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; -$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; +$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); $db->exec('CREATE TABLE test (text)'); diff --git a/ext/pdo_sqlite/tests/bug35336.phpt b/ext/pdo_sqlite/tests/bug35336.phpt index 1f9fda12b6..201429bc4e 100644 --- a/ext/pdo_sqlite/tests/bug35336.phpt +++ b/ext/pdo_sqlite/tests/bug35336.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #35336 (crash on PDO::FETCH_CLASS + __set()) --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> --FILE-- diff --git a/ext/pdo_sqlite/tests/bug44327_2.phpt b/ext/pdo_sqlite/tests/bug44327_2.phpt index 4add0730dc..531af9586c 100644 --- a/ext/pdo_sqlite/tests/bug44327_2.phpt +++ b/ext/pdo_sqlite/tests/bug44327_2.phpt @@ -7,7 +7,7 @@ if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $x = $db->query('select 1 as queryString'); var_dump($x, $x->queryString); diff --git a/ext/pdo_sqlite/tests/bug44327_3.phpt b/ext/pdo_sqlite/tests/bug44327_3.phpt index 86f5642876..45cdbff0c4 100644 --- a/ext/pdo_sqlite/tests/bug44327_3.phpt +++ b/ext/pdo_sqlite/tests/bug44327_3.phpt @@ -7,7 +7,7 @@ if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $x = $db->query('select 1 as queryStringxx'); $y = $x->fetch(PDO::FETCH_LAZY); diff --git a/ext/pdo_sqlite/tests/bug46139.phpt b/ext/pdo_sqlite/tests/bug46139.phpt index c361d7a9b1..c85d1b91af 100644 --- a/ext/pdo_sqlite/tests/bug46139.phpt +++ b/ext/pdo_sqlite/tests/bug46139.phpt @@ -7,8 +7,8 @@ if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; --FILE-- <?php -require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; -$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; +$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); class Person { public $test = NULL; diff --git a/ext/pdo_sqlite/tests/bug46542.phpt b/ext/pdo_sqlite/tests/bug46542.phpt index 2de0c05191..d324270f2a 100644 --- a/ext/pdo_sqlite/tests/bug46542.phpt +++ b/ext/pdo_sqlite/tests/bug46542.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #46542 Extending PDO class with a __call() function --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> --FILE-- diff --git a/ext/pdo_sqlite/tests/bug52487.phpt b/ext/pdo_sqlite/tests/bug52487.phpt index fc65bd3b60..ff586d2f64 100644 --- a/ext/pdo_sqlite/tests/bug52487.phpt +++ b/ext/pdo_sqlite/tests/bug52487.phpt @@ -1,13 +1,13 @@ --TEST-- Bug #52487 (PDO::FETCH_INTO leaks memory) --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> --FILE-- <?php -require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; -$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; +$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); $stmt = $db->prepare("select 1 as attr"); for ($i = 0; $i < 10; $i++) { diff --git a/ext/pdo_sqlite/tests/bug70862.phpt b/ext/pdo_sqlite/tests/bug70862.phpt index b0b133d870..d66bb6262f 100644 --- a/ext/pdo_sqlite/tests/bug70862.phpt +++ b/ext/pdo_sqlite/tests/bug70862.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing sqliteCreateCollation() --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec('CREATE TABLE test(field BLOB)'); diff --git a/ext/pdo_sqlite/tests/common.phpt b/ext/pdo_sqlite/tests/common.phpt index da28d91950..9c07a5dc38 100644 --- a/ext/pdo_sqlite/tests/common.phpt +++ b/ext/pdo_sqlite/tests/common.phpt @@ -1,7 +1,7 @@ --TEST-- SQLite --SKIPIF-- -<?php # vim:ft=php +<?php if (!extension_loaded('pdo_sqlite')) print 'skip'; ?> --REDIRECTTEST-- return array( diff --git a/ext/pdo_sqlite/tests/debugdumpparams_001.phpt b/ext/pdo_sqlite/tests/debugdumpparams_001.phpt index 3e51b53237..4402b5c815 100644 --- a/ext/pdo_sqlite/tests/debugdumpparams_001.phpt +++ b/ext/pdo_sqlite/tests/debugdumpparams_001.phpt @@ -7,7 +7,7 @@ if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $x= $db->prepare('select :a, :b, ?'); $x->bindValue(':a', 1, PDO::PARAM_INT); diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt index 54eb06411f..c9157d1b05 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing sqliteCreateAggregate() --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)'); @@ -22,7 +22,7 @@ foreach ($db->query('SELECT testing(name) FROM foobar') as $row) { $db->query('DROP TABLE foobar'); ?> ---EXPECTF-- +--EXPECT-- array(2) { ["testing(name)"]=> string(2) "12" diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt index efcce00e3d..fcfc344896 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing sqliteCreateCollation() --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)'); diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt index 13867ae25c..1e753f3799 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing sqliteCreateFunction() --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)'); @@ -23,7 +23,7 @@ foreach ($db->query('SELECT testing(name) FROM foobar') as $row) { $db->query('DROP TABLE foobar'); ?> ---EXPECTF-- +--EXPECT-- array(2) { ["testing(name)"]=> string(3) "php" diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt index da6f3cf0fb..5a329a1d97 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt @@ -8,7 +8,7 @@ if (!defined('PDO::SQLITE_DETERMINISTIC')) die('skip system sqlite is too old'); --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)'); diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_extendederror_attr.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_extendederror_attr.phpt new file mode 100644 index 0000000000..50b939b6eb --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_extendederror_attr.phpt @@ -0,0 +1,50 @@ +--TEST-- +PDO_sqlite: Testing PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?php + +echo "Creating new PDO" . PHP_EOL; +$db = new PDO('sqlite::memory:'); + +$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )"); + +echo "Inserting first time which should succeed" . PHP_EOL; +$db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +$errorInfo = $db->errorInfo(); +echo sprintf("First Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; + +echo "Inserting second time which should fail" . PHP_EOL; +$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +$errorInfo = $db->errorInfo(); +echo sprintf("Second Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; + + +echo "Creating new PDO with Extended Result Codes turned on" . PHP_EOL; +$db = new PDO('sqlite::memory:', '', '', [PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES => TRUE]); + +$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )"); + +echo "Inserting first time which should succeed" . PHP_EOL; +$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +$errorInfo = $db->errorInfo(); +echo sprintf("First (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; + +echo "Inserting second time which should fail" . PHP_EOL; +$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +$errorInfo = $db->errorInfo(); +echo sprintf("Second (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; + +?> +--EXPECT-- +Creating new PDO +Inserting first time which should succeed +First Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: () +Inserting second time which should fail +Second Error Info: SQLSTATE Error Code: (23000), Driver Specific Error Code: (19) +Creating new PDO with Extended Result Codes turned on +Inserting first time which should succeed +First (Extended) Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: () +Inserting second time which should fail +Second (Extended) Error Info: SQLSTATE Error Code: (HY000), Driver Specific Error Code: (1555) diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt index bb4d033dda..deaefbac98 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing lastInsertId() --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->query('CREATE TABLE IF NOT EXISTS foo (id INT AUTO INCREMENT, name TEXT)'); $db->query('INSERT INTO foo VALUES (NULL, "PHP")'); $db->query('INSERT INTO foo VALUES (NULL, "PHP6")'); @@ -16,7 +16,7 @@ var_dump($db->lastInsertId()); $db->query('DROP TABLE foo'); ?> ---EXPECTF-- +--EXPECT-- object(PDOStatement)#2 (1) { ["queryString"]=> string(17) "SELECT * FROM foo" diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_open_flags.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_open_flags.phpt index 89cb6c89bd..0023f91031 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_open_flags.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_open_flags.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing open flags --FILE-- <?php -$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db"; +$filename = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db"; // Default open flag is read-write|create $db = new PDO('sqlite:' . $filename, null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); @@ -18,7 +18,7 @@ var_dump($db->exec('CREATE TABLE test2 (id INT);')); ?> --CLEAN-- <?php -$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db"; +$filename = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db"; if (file_exists($filename)) { unlink($filename); } diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_statement_getattribute.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_statement_getattribute.phpt new file mode 100644 index 0000000000..ba1d6f949a --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_statement_getattribute.phpt @@ -0,0 +1,20 @@ +--TEST-- +PDO_sqlite: Testing PDOStatement::getAttribute() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?php + +$db = new PDO('sqlite::memory:'); + +$st = $db->prepare('SELECT 1;'); + +var_dump($st->getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT)); + +$st = $db->prepare('CREATE TABLE test (a TEXT);'); + +var_dump($st->getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT)); +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_tostring_exception.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_tostring_exception.phpt new file mode 100644 index 0000000000..b1cd78eee7 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_tostring_exception.phpt @@ -0,0 +1,45 @@ +--TEST-- +__toString() exception during PDO Sqlite parameter binding +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?php + +class throws { + function __toString() { + throw new Exception("Sorry"); + } +} + +$db = new PDO('sqlite::memory:'); +$db->exec('CREATE TABLE t(id int, v varchar(255))'); + +$stmt = $db->prepare('INSERT INTO t VALUES(:i, :v)'); +$param1 = 1234; +$stmt->bindValue('i', $param1); +$param2 = "foo"; +$stmt->bindParam('v', $param2); + +$param2 = new throws; + +try { + $stmt->execute(); +} catch (Exception $e) { + echo "Exception thrown ...\n"; +} + +try { + $stmt->execute(); +} catch (Exception $e) { + echo "Exception thrown ...\n"; +} + +$query = $db->query("SELECT * FROM t"); +while ($row = $query->fetch(PDO::FETCH_ASSOC)) { + print_r($row); +} + +?> +--EXPECT-- +Exception thrown ... +Exception thrown ... diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt index 8cdaae16e6..493fff78d8 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt @@ -5,7 +5,7 @@ PDO_sqlite: Testing transaction --FILE-- <?php -$db = new pdo('sqlite::memory:'); +$db = new PDO('sqlite::memory:'); $db->beginTransaction(); |
