Skip to content

Commit 5a12a73

Browse files
committed
Split tests/interbase.inc into 3 files
If a test includes `interbase.inc` a dummy database will always be created, even if the test does not need a database. This patch splits the `interbase.inc` file into three files so that you have more control over what is included in a test.
1 parent 40b4541 commit 5a12a73

4 files changed

Lines changed: 93 additions & 88 deletions

File tree

tests/config.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$user = 'SYSDBA';
4+
$password = 'masterkey';
5+
ini_set('ibase.default_user',$user);
6+
ini_set('ibase.default_password',$password);

tests/functions.inc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
srand((double)microtime()*1000000);
4+
5+
function out_table($table_name)
6+
{
7+
echo "--- $table_name ---\n";
8+
$res = ibase_query("select * from $table_name");
9+
while ($r = ibase_fetch_row($res)) {
10+
echo join("\t",$r)."\t\n";
11+
}
12+
ibase_free_result($res);
13+
echo "---\n";
14+
}
15+
16+
function out_result($result, $table_name = "")
17+
{
18+
echo "--- $table_name ---\n";
19+
while ($r = ibase_fetch_row($result)) {
20+
echo join("\t",$r)."\t\n";
21+
}
22+
echo "---\n";
23+
}
24+
25+
function out_result_trap_error($result, $table_name = "")
26+
{
27+
echo "--- $table_name ---\n";
28+
while ($r = @ibase_fetch_row($result)) {
29+
echo join("\t",$r)."\t\n";
30+
}
31+
echo "errmsg [" . ibase_errmsg() . "]\n";
32+
echo "---\n";
33+
}
34+
35+
/* M/D/Y H:M:S */
36+
function rand_datetime()
37+
{
38+
return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
39+
rand()%12+1, rand()%28+1, rand()%100+1910,
40+
rand()%24, rand()%60, rand()%60);
41+
}
42+
43+
/* random binary string */
44+
function rand_binstr($max_len)
45+
{
46+
$len = rand() % $max_len;
47+
$s = "";
48+
while($len--) {
49+
$s .= sprintf("%c", rand() % 256);
50+
}
51+
return $s;
52+
}
53+
54+
function rand_str($max_len)
55+
{
56+
$len = rand() % $max_len;
57+
$s = "";
58+
while ($len--) {
59+
$s .= sprintf("%c", rand() % 26 + 65);
60+
}
61+
return $s;
62+
}
63+
64+
function rand_number($len , $prec = -1, $sign = 1)
65+
{
66+
if ($prec == -1) {
67+
$n = substr(rand() . rand(), 0, rand() % $len + 1);
68+
if (strlen($n) < $len) {
69+
$n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
70+
}
71+
} else if ($prec == 0) {
72+
$n = substr(rand() . rand(), 0, rand() % $len + 1);
73+
} else if (($prec - $len) == 0) {
74+
$n = substr(rand() . rand(), 0, 1);
75+
$n .= "." . substr(rand(), 0, $prec);
76+
} else {
77+
$n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
78+
$n .= "." . substr(rand(), 0, $prec);
79+
}
80+
if ($sign && (rand() % 3 == 0)) {
81+
$n = "-" .$n;
82+
}
83+
return $n;
84+
}

tests/ibase_drop_db_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ibase_drop_db(): Basic test
55
--FILE--
66
<?php
77

8-
require("interbase.inc");
8+
require("config.inc");
99

1010
unlink($file = tempnam('/tmp',"php_ibase_test"));
1111

tests/interbase.inc

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<?php
22

3-
srand((double)microtime()*1000000);
4-
5-
$user = 'SYSDBA';
6-
$password = 'masterkey';
7-
ini_set('ibase.default_user',$user);
8-
ini_set('ibase.default_password',$password);
3+
require('config.inc');
4+
require('functions.inc');
95

106
/* we need just the generated name, not the file itself */
117
unlink($test_base = tempnam(sys_get_temp_dir(),"php_ibase_test"));
@@ -36,85 +32,4 @@ function cleanup_db()
3632
register_shutdown_function('cleanup_db');
3733
init_db();
3834

39-
function out_table($table_name)
40-
{
41-
echo "--- $table_name ---\n";
42-
$res = ibase_query("select * from $table_name");
43-
while ($r = ibase_fetch_row($res)) {
44-
echo join("\t",$r)."\t\n";
45-
}
46-
ibase_free_result($res);
47-
echo "---\n";
48-
}
49-
50-
function out_result($result, $table_name = "")
51-
{
52-
echo "--- $table_name ---\n";
53-
while ($r = ibase_fetch_row($result)) {
54-
echo join("\t",$r)."\t\n";
55-
}
56-
echo "---\n";
57-
}
58-
59-
function out_result_trap_error($result, $table_name = "")
60-
{
61-
echo "--- $table_name ---\n";
62-
while ($r = @ibase_fetch_row($result)) {
63-
echo join("\t",$r)."\t\n";
64-
}
65-
echo "errmsg [" . ibase_errmsg() . "]\n";
66-
echo "---\n";
67-
}
68-
69-
/* M/D/Y H:M:S */
70-
function rand_datetime()
71-
{
72-
return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
73-
rand()%12+1, rand()%28+1, rand()%100+1910,
74-
rand()%24, rand()%60, rand()%60);
75-
}
76-
77-
/* random binary string */
78-
function rand_binstr($max_len)
79-
{
80-
$len = rand() % $max_len;
81-
$s = "";
82-
while($len--) {
83-
$s .= sprintf("%c", rand() % 256);
84-
}
85-
return $s;
86-
}
87-
88-
function rand_str($max_len)
89-
{
90-
$len = rand() % $max_len;
91-
$s = "";
92-
while ($len--) {
93-
$s .= sprintf("%c", rand() % 26 + 65);
94-
}
95-
return $s;
96-
}
97-
98-
function rand_number($len , $prec = -1, $sign = 1)
99-
{
100-
if ($prec == -1) {
101-
$n = substr(rand() . rand(), 0, rand() % $len + 1);
102-
if (strlen($n) < $len) {
103-
$n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
104-
}
105-
} else if ($prec == 0) {
106-
$n = substr(rand() . rand(), 0, rand() % $len + 1);
107-
} else if (($prec - $len) == 0) {
108-
$n = substr(rand() . rand(), 0, 1);
109-
$n .= "." . substr(rand(), 0, $prec);
110-
} else {
111-
$n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
112-
$n .= "." . substr(rand(), 0, $prec);
113-
}
114-
if ($sign && (rand() % 3 == 0)) {
115-
$n = "-" .$n;
116-
}
117-
return $n;
118-
}
119-
12035
?>

0 commit comments

Comments
 (0)