summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJani Taskinen <jani@php.net>2010-03-12 11:51:40 +0000
committerJani Taskinen <jani@php.net>2010-03-12 11:51:40 +0000
commitbc4588b1d9325ad5c7510c32520977a120b76e91 (patch)
tree3206bb536111c3615658594d20d991975db74ee4
parenta99e0b69df40ea6e0f745cd8adf225fbace2dd13 (diff)
parent321ca32642fcfd68b5b89052239ff8139286ed10 (diff)
downloadphp-git-bc4588b1d9325ad5c7510c32520977a120b76e91.tar.gz
MF53: New and improved DBA tests
-rw-r--r--ext/dba/tests/dba012.phpt42
-rw-r--r--ext/dba/tests/dba013.phpt27
-rw-r--r--ext/dba/tests/dba014.phpt27
-rw-r--r--ext/dba/tests/dba015.phpt76
-rw-r--r--ext/dba/tests/dba_db4_003.phpt5
5 files changed, 177 insertions, 0 deletions
diff --git a/ext/dba/tests/dba012.phpt b/ext/dba/tests/dba012.phpt
new file mode 100644
index 0000000000..821c4e2aba
--- /dev/null
+++ b/ext/dba/tests/dba012.phpt
@@ -0,0 +1,42 @@
+--TEST--
+DBA dba.default_handler tests
+--SKIPIF--
+<?php
+$handler = "flatfile";
+require_once(dirname(__FILE__) .'/skipif.inc');
+?>
+--INI--
+dba.default_handler=flatfile
+--FILE--
+<?php
+$handler = "flatfile";
+require_once(dirname(__FILE__) .'/test.inc');
+echo "database handler: $handler\n";
+
+echo "Test 1\n";
+
+ini_set('dba.default_handler', 'does_not_exist');
+
+var_dump(dba_open($db_filename, 'c'));
+
+echo "Test 2\n";
+
+ini_set('dba.default_handler', '');
+
+var_dump(dba_open($db_filename, 'n'));
+
+?>
+--CLEAN--
+<?php
+require(dirname(__FILE__) .'/clean.inc');
+?>
+--EXPECTF--
+database handler: flatfile
+Test 1
+
+Warning: ini_set(): No such handler: does_not_exist in %sdba012.php on line %d
+resource(%d) of type (dba)
+Test 2
+
+Warning: dba_open(%stest0.dbm,n): No default handler selected in %sdba012.php on line %d
+bool(false)
diff --git a/ext/dba/tests/dba013.phpt b/ext/dba/tests/dba013.phpt
new file mode 100644
index 0000000000..bf95642e9d
--- /dev/null
+++ b/ext/dba/tests/dba013.phpt
@@ -0,0 +1,27 @@
+--TEST--
+DBA with array key with empty array
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__) .'/skipif.inc');
+die("info $HND handler used");
+?>
+--FILE--
+<?php
+require_once(dirname(__FILE__) .'/test.inc');
+echo "database handler: $handler\n";
+
+if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+ dba_insert(array(), "Content String 1", $db_file);
+} else {
+ echo "Error creating database\n";
+}
+
+?>
+--CLEAN--
+<?php
+require(dirname(__FILE__) .'/clean.inc');
+?>
+--EXPECTF--
+database handler: %s
+
+Catchable fatal error: dba_insert(): Key does not have exactly two elements: (key, name) in %sdba013.php on line %d
diff --git a/ext/dba/tests/dba014.phpt b/ext/dba/tests/dba014.phpt
new file mode 100644
index 0000000000..7e52be7c3a
--- /dev/null
+++ b/ext/dba/tests/dba014.phpt
@@ -0,0 +1,27 @@
+--TEST--
+DBA with array key with array containing too many elements
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__) .'/skipif.inc');
+die("info $HND handler used");
+?>
+--FILE--
+<?php
+require_once(dirname(__FILE__) .'/test.inc');
+echo "database handler: $handler\n";
+
+if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+ dba_insert(array("a", "b", "c"), "Content String 2", $db_file);
+} else {
+ echo "Error creating database\n";
+}
+
+?>
+--CLEAN--
+<?php
+require(dirname(__FILE__) .'/clean.inc');
+?>
+--EXPECTF--
+database handler: %s
+
+Catchable fatal error: dba_insert(): Key does not have exactly two elements: (key, name) in %sdba014.php on line %d
diff --git a/ext/dba/tests/dba015.phpt b/ext/dba/tests/dba015.phpt
new file mode 100644
index 0000000000..9f560c5b2f
--- /dev/null
+++ b/ext/dba/tests/dba015.phpt
@@ -0,0 +1,76 @@
+--TEST--
+DBA with persistent connections
+--SKIPIF--
+<?php
+$handler = "flatfile";
+require_once(dirname(__FILE__) .'/skipif.inc');
+die("info $HND handler used");
+?>
+--FILE--
+<?php
+
+$handler = "flatfile";
+require_once(dirname(__FILE__) .'/test.inc');
+echo "database handler: $handler\n";
+
+echo "Test 1\n";
+$db_file1 = dba_popen($db_filename, 'n', 'flatfile');
+dba_insert("key1", "This is a test insert 1", $db_file1);
+echo dba_fetch("key1", $db_file1), "\n";
+
+
+echo "Test 2\n";
+$db_file2 = dba_popen($db_filename, 'n', 'flatfile');
+if ($db_file1 === $db_file2) {
+ echo "resources are the same\n";
+} else {
+ echo "resources are different\n";
+}
+
+
+echo "Test 3 - fetch both rows from second resource\n";
+dba_insert("key2", "This is a test insert 2", $db_file2);
+echo dba_fetch("key1", $db_file2), "\n";
+echo dba_fetch("key2", $db_file2), "\n";
+
+
+echo "Test 4 - fetch both rows from first resource\n";
+echo dba_fetch("key1", $db_file1), "\n";
+echo dba_fetch("key2", $db_file1), "\n";
+
+echo "Test 5 - close 2nd resource\n";
+dba_close($db_file2);
+var_dump($db_file1);
+var_dump($db_file2);
+
+echo "Test 6 - query after closing 2nd resource\n";
+echo dba_fetch("key1", $db_file1), "\n";
+echo dba_fetch("key2", $db_file1), "\n";
+
+?>
+===DONE===
+--CLEAN--
+<?php
+ require(dirname(__FILE__) .'/clean.inc');
+?>
+--XFAIL--
+Test 6 crashes in flatfile_findkey with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278
+--EXPECTF--
+database handler: flatfile
+Test 1
+This is a test insert 1
+Test 2
+resources are different
+Test 3 - fetch both rows from second resource
+This is a test insert 1
+This is a test insert 2
+Test 4 - fetch both rows from first resource
+This is a test insert 1
+This is a test insert 2
+Test 5 - close 2nd resource
+resource(%d) of type (dba persistent)
+resource(%d) of type (Unknown)
+Test 6 - query after closing 2nd resource
+This is a test insert 1
+This is a test insert 2
+===DONE===
diff --git a/ext/dba/tests/dba_db4_003.phpt b/ext/dba/tests/dba_db4_003.phpt
index 084bff8d87..7e8568c085 100644
--- a/ext/dba/tests/dba_db4_003.phpt
+++ b/ext/dba/tests/dba_db4_003.phpt
@@ -26,6 +26,10 @@ if (($db_file = dba_open($db_filename, "c", $handler)) !== FALSE) {
echo "Error creating $db_filename\n";
}
+// Check the file still exists
+$s = file_get_contents($db_filename);
+echo "$s\n";
+
?>
--CLEAN--
<?php
@@ -39,3 +43,4 @@ Notice: dba_open(): %stest0.dbm: unexpected file type or format in %sdba_db4_003
Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_003.php on line %d
Error creating %stest0.dbm
+Dummy contents