- Attempt at an unified test suite

This commit is contained in:
Marcus Boerger 2005-02-20 17:56:19 +00:00
parent 26677dd2a2
commit 94c286f2ef
22 changed files with 298 additions and 128 deletions

11
ext/pdo/tests/pdo.inc Executable file
View File

@ -0,0 +1,11 @@
<?php
function set_sql($name, $query)
{
if (empty($GLOBALS['SQL'][$name]))
{
$GLOBALS['SQL'][$name] = $query;
}
}
?>

20
ext/pdo/tests/pdo_001.inc Executable file
View File

@ -0,0 +1,20 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "B")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C")');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_ASSOC));
?>

21
ext/pdo/tests/pdo_002.inc Executable file
View File

@ -0,0 +1,21 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "B")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C")');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_NUM));
?>

20
ext/pdo/tests/pdo_003.inc Executable file
View File

@ -0,0 +1,20 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "B")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C")');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_BOTH));
?>

20
ext/pdo/tests/pdo_004.inc Executable file
View File

@ -0,0 +1,20 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "B")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C")');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_OBJ));
?>

38
ext/pdo/tests/pdo_005.inc Executable file
View File

@ -0,0 +1,38 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A", "AA")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "B", "BB")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C", "CC")');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
class TestBase
{
public $id;
protected $val;
private $val2;
}
class TestDerived extends TestBase
{
protected $row;
public function __construct(&$row)
{
echo __METHOD__ . "($row,{$this->id})\n";
$this->row = $row++;
}
}
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS, 'TestBase'));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS, 'TestDerived', array(0)));
?>

20
ext/pdo/tests/pdo_006.inc Executable file
View File

@ -0,0 +1,20 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, "A")');
set_sql('insert2', 'INSERT INTO test VALUES(2, "A")');
set_sql('insert3', 'INSERT INTO test VALUES(3, "C")');
set_sql('select', 'SELECT val, id FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_GROUP));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_GROUP));
?>

19
ext/pdo/tests/pdo_007.inc Executable file
View File

@ -0,0 +1,19 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id CHAR(1) PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES("A", "A")');
set_sql('insert2', 'INSERT INTO test VALUES("B", "A")');
set_sql('insert3', 'INSERT INTO test VALUES("C", "C")');
set_sql('select', 'SELECT id, val FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_UNIQUE));
?>

19
ext/pdo/tests/pdo_008.inc Executable file
View File

@ -0,0 +1,19 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id CHAR(1) PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES("A", "A")');
set_sql('insert2', 'INSERT INTO test VALUES("B", "A")');
set_sql('insert3', 'INSERT INTO test VALUES("C", "C")');
set_sql('select', 'SELECT val, id FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
// check that repeated first columns overwrite existing array elements
?>

53
ext/pdo/tests/pdo_009.inc Executable file
View File

@ -0,0 +1,53 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE classtypes(id int PRIMARY KEY, name VARCHAR(10) UNIQUE)');
set_sql('insert1', 'INSERT INTO classtypes VALUES(0, "stdClass")');
set_sql('insert2', 'INSERT INTO classtypes VALUES(1, "Test1")');
set_sql('insert3', 'INSERT INTO classtypes VALUES(2, "Test2")');
set_sql('create2', 'CREATE TABLE test(id int PRIMARY KEY, classtype int, val VARCHAR(10))');
set_sql('insert4', 'INSERT INTO test VALUES(1, 0, "A")');
set_sql('insert5', 'INSERT INTO test VALUES(2, 1, "B")');
set_sql('insert6', 'INSERT INTO test VALUES(3, 2, "C")');
set_sql('insert7', 'INSERT INTO test VALUES(4, 3, "D")');
set_sql('select', 'SELECT classtypes.name, test.id AS id, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id');
$DB->exec($SQL['create1']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$DB->exec($SQL['create2']);
$DB->exec($SQL['insert4']);
$DB->exec($SQL['insert5']);
$DB->exec($SQL['insert6']);
$DB->exec($SQL['insert7']);
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE, 'Test3'));
?>

View File

@ -0,0 +1,7 @@
<?php
$CONNECTION = 'sqlite::memory:';
$PDO_TESTS = dirname(__FILE__) . '/../../pdo/tests/';
?>

View File

@ -2,20 +2,15 @@
PDO-SQLite: PDO_FETCH_ASSOC
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A")');
$db->exec('INSERT INTO test VALUES(2, "B")');
$db->exec('INSERT INTO test VALUES(3, "C")');
require_once($PDO_TESTS . 'pdo_001.inc');
$stmt = $db->query('SELECT * FROM test');
var_dump($stmt->fetchAll(PDO_FETCH_ASSOC));
?>
===DONE===
<?php exit(0); ?>

View File

@ -2,20 +2,15 @@
PDO-SQLite: PDO_FETCH_NUM
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A")');
$db->exec('INSERT INTO test VALUES(2, "B")');
$db->exec('INSERT INTO test VALUES(3, "C")');
require_once($PDO_TESTS . 'pdo_002.inc');
$stmt = $db->query('SELECT * FROM test');
var_dump($stmt->fetchAll(PDO_FETCH_NUM));
?>
===DONE===
<?php exit(0); ?>

View File

@ -2,20 +2,15 @@
PDO-SQLite: PDO_FETCH_BOTH
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A")');
$db->exec('INSERT INTO test VALUES(2, "B")');
$db->exec('INSERT INTO test VALUES(3, "C")');
require_once($PDO_TESTS . 'pdo_003.inc');
$stmt = $db->query('SELECT * FROM test');
var_dump($stmt->fetchAll(PDO_FETCH_BOTH));
?>
===DONE===
<?php exit(0); ?>

View File

@ -2,20 +2,15 @@
PDO-SQLite: PDO_FETCH_OBJ
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A")');
$db->exec('INSERT INTO test VALUES(2, "B")');
$db->exec('INSERT INTO test VALUES(3, "C")');
require_once($PDO_TESTS . 'pdo_004.inc');
$stmt = $db->query('SELECT * FROM test');
var_dump($stmt->fetchAll(PDO_FETCH_OBJ));
?>
===DONE===
<?php exit(0); ?>

View File

@ -2,38 +2,15 @@
PDO-SQLite: PDO_FETCH_CLASS
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A", "AA")');
$db->exec('INSERT INTO test VALUES(2, "B", "BB")');
$db->exec('INSERT INTO test VALUES(3, "C", "CC")');
require_once($PDO_TESTS . 'pdo_005.inc');
class TestBase
{
public $id;
protected $val;
private $val2;
}
class TestDerived extends TestBase
{
protected $row;
public function __construct(&$row)
{
echo __METHOD__ . "($row,{$this->id})\n";
$this->row = $row++;
}
}
var_dump($db->query('SELECT * FROM test')->fetchAll(PDO_FETCH_CLASS));
var_dump($db->query('SELECT * FROM test')->fetchAll(PDO_FETCH_CLASS, 'TestBase'));
var_dump($db->query('SELECT * FROM test')->fetchAll(PDO_FETCH_CLASS, 'TestDerived', array(0)));
?>
===DONE===
<?php exit(0); ?>

View File

@ -2,19 +2,14 @@
PDO-SQLite: PDO_FETCH_GROUP
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, "A")');
$db->exec('INSERT INTO test VALUES(2, "A")');
$db->exec('INSERT INTO test VALUES(3, "C")');
var_dump($db->query('SELECT val, id FROM test')->fetchAll(PDO_FETCH_NUM|PDO_FETCH_GROUP));
var_dump($db->query('SELECT val, id FROM test')->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_GROUP));
require_once($PDO_TESTS . 'pdo_006.inc');
?>
===DONE===

View File

@ -2,19 +2,14 @@
PDO-SQLite: PDO_FETCH_UNIQUE
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id CHAR(1) PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES("A", "A")');
$db->exec('INSERT INTO test VALUES("B", "A")');
$db->exec('INSERT INTO test VALUES("C", "C")');
var_dump($db->query('SELECT id, val FROM test')->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
var_dump($db->query('SELECT id, val FROM test')->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_UNIQUE));
require_once($PDO_TESTS . 'pdo_007.inc');
?>
===DONE===

View File

@ -2,19 +2,14 @@
PDO-SQLite: PDO_FETCH_UNIQUE conflict
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE test(id CHAR(1) PRIMARY KEY, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES("A", "A")');
$db->exec('INSERT INTO test VALUES("B", "A")');
$db->exec('INSERT INTO test VALUES("C", "C")');
var_dump($db->query('SELECT val, id FROM test')->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
// check that repeated first columns overwrite existing array elements
require_once($PDO_TESTS . 'pdo_008.inc');
?>
===DONE===

View File

@ -2,49 +2,15 @@
PDO-SQLite: PDO_FETCH_CLASSTYPE
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("pdo_sqlite")) print "skip"; ?>
require_once('skipif.inc'); ?>
--FILE--
<?php
$db =new pdo('sqlite::memory:');
require_once('connection.inc');
require_once('prepare.inc');
$db->exec('CREATE TABLE classtypes(id int PRIMARY KEY, name VARCHAR(10) UNIQUE)');
$db->exec('INSERT INTO classtypes VALUES(0, "stdClass")');
$db->exec('INSERT INTO classtypes VALUES(1, "Test1")');
$db->exec('INSERT INTO classtypes VALUES(2, "Test2")');
$db->exec('CREATE TABLE test(id int PRIMARY KEY, classtype int, val VARCHAR(10))');
$db->exec('INSERT INTO test VALUES(1, 0, "A")');
$db->exec('INSERT INTO test VALUES(2, 1, "B")');
$db->exec('INSERT INTO test VALUES(3, 2, "C")');
$db->exec('INSERT INTO test VALUES(4, 3, "D")');
require_once($PDO_TESTS . 'pdo_009.inc');
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
$sql = 'SELECT classtypes.name, test.id AS id, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id';
var_dump($db->query($sql)->fetchAll(PDO_FETCH_NUM));
var_dump($db->query($sql)->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE, 'Test3'));
?>
===DONE===
<?php exit(0); ?>

View File

@ -0,0 +1,9 @@
<?php
require_once('connection.inc');
$SQL = array();
$DB = new pdo($CONNECTION);
?>

View File

@ -0,0 +1,5 @@
<?php
if (!extension_loaded("pdo_sqlite")) print "skip";
?>