Skip to content

Commit 002fe32

Browse files
refactor(ext/pgsql/tests): move table settings in config.inc to each test
1 parent faabc3f commit 002fe32

29 files changed

+331
-28
lines changed

ext/pgsql/tests/01createdb.phpt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ pgsql
99
// create test table
1010

1111
include('inc/config.inc');
12+
$table_name = 'table_01createdb';
13+
$table_name_92 = 'table_01createdb_92';
14+
$view_name = "view_01createdb";
1215

1316
$db = pg_connect($conn_str);
1417
if (!($q = @pg_query($db, "SELECT * FROM ".$table_name)) || !@pg_num_rows($q))
1518
{
16-
pg_query($db,$table_def); // Create table here
17-
for ($i=0; $i < $num_test_record; $i++) {
18-
pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
19-
}
19+
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); // Create table here
2020
}
2121
else {
2222
echo pg_last_error()."\n";
@@ -25,18 +25,28 @@ else {
2525
$v = pg_version($db);
2626
if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q)))
2727
{
28-
pg_query($db,$table_def_92); // Create table here
28+
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)"); // Create table here
2929
}
3030
else {
3131
echo pg_last_error()."\n";
3232
}
3333

3434
// Create view here
35-
pg_query($db,$view_def);
35+
pg_query($db, "CREATE VIEW {$view_name} AS SELECT * FROM {$table_name}");
3636

3737
pg_close($db);
3838

3939
echo "OK";
4040
?>
41+
--CLEAN--
42+
<?php
43+
include('inc/config.inc');
44+
$table_name = 'table_01createdb';
45+
$table_name_92 = 'table_01createdb_92';
46+
47+
$db = pg_connect($conn_str);
48+
pg_query($db, "drop table {$table_name} cascade");
49+
pg_query($db, "drop table if exists {$table_name_92} cascade");
50+
?>
4151
--EXPECT--
4252
OK

ext/pgsql/tests/03sync_query.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ pgsql
88
<?php
99

1010
include('inc/config.inc');
11+
$table_name = "table_03sync_query";
1112

1213
$db = pg_connect($conn_str);
14+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
15+
pg_query($db, "insert into {$table_name} default values");
1316

1417
$result = pg_query($db, "SELECT * FROM ".$table_name.";");
1518
if (!($rows = pg_num_rows($result)))
@@ -134,6 +137,14 @@ pg_close($db);
134137

135138
echo "OK";
136139
?>
140+
--CLEAN--
141+
<?php
142+
include('inc/config.inc');
143+
$table_name = "table_03sync_query";
144+
145+
$db = pg_connect($conn_str);
146+
pg_query($db, "drop table {$table_name}");
147+
?>
137148
--EXPECT--
138149
Argument #3 must be greater than or equal to 0
139150
Argument #3 must be less than the number of fields for this result set

ext/pgsql/tests/04async_query.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ pgsql
88
<?php
99

1010
include('inc/config.inc');
11+
$table_name = "table_04async_query";
1112

1213
$db = pg_connect($conn_str);
14+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
15+
pg_query($db, "insert into {$table_name} default values");
1316

1417
if (!pg_send_query($db, "SELECT * FROM ".$table_name.";")) {
1518
echo "pg_send_query() error\n";
@@ -63,5 +66,13 @@ pg_free_result($result);
6366

6467
echo "OK";
6568
?>
69+
--CLEAN--
70+
<?php
71+
include('inc/config.inc');
72+
$table_name = "table_04async_query";
73+
74+
$db = pg_connect($conn_str);
75+
pg_query($db, "drop table {$table_name}");
76+
?>
6677
--EXPECT--
6778
OK

ext/pgsql/tests/06_bug73498.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,29 @@ pgsql
88
<?php
99

1010
include('inc/config.inc');
11+
$table_name = "table_06_bug73498";
12+
$view_name = "view_06_bug73498";
1113

1214
$db = pg_connect($conn_str);
15+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
16+
pg_query($db, "create view {$view_name} as select * from {$table_name}");
17+
pg_query($db, "insert into {$table_name} default values");
1318

1419
$rows = pg_copy_to($db, "(select * from {$view_name})");
1520

1621
var_dump(gettype($rows));
1722
var_dump(count($rows) > 0);
1823

24+
?>
25+
--CLEAN--
26+
<?php
27+
include('inc/config.inc');
28+
$table_name = "table_06_bug73498";
29+
$view_name = "view_06_bug73498";
30+
31+
$db = pg_connect($conn_str);
32+
pg_query($db, "drop view {$view_name}");
33+
pg_query($db, "drop table {$table_name}");
1934
?>
2035
--EXPECT--
2136
string(5) "array"

ext/pgsql/tests/06copy.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ pgsql
88
<?php
99

1010
include('inc/config.inc');
11+
$table_name = "table_06copy";
1112

1213
$db = pg_connect($conn_str);
14+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
1315

1416
$rows = pg_copy_to($db, $table_name);
1517

@@ -19,6 +21,14 @@ pg_copy_from($db, $table_name, $rows);
1921

2022
echo "OK";
2123

24+
?>
25+
--CLEAN--
26+
<?php
27+
include('inc/config.inc');
28+
$table_name = "table_06copy";
29+
30+
$db = pg_connect($conn_str);
31+
pg_query($db, "drop table {$table_name}");
2232
?>
2333
--EXPECT--
2434
OK

ext/pgsql/tests/08escape.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pgsql
88
<?php
99

1010
include 'inc/config.inc';
11+
$table_name = "table_08escape";
12+
1113
define('FILE_NAME', __DIR__ . '/php.gif');
1214

1315
// pg_escape_string() test
@@ -42,6 +44,7 @@ else {
4244
// Test using database
4345
$data = file_get_contents(FILE_NAME);
4446
$db = pg_connect($conn_str);
47+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
4548

4649
// Insert binary to DB
4750
$escaped_data = pg_escape_bytea($db, $data);
@@ -97,6 +100,14 @@ else {
97100
var_dump($expect);
98101
}
99102

103+
?>
104+
--CLEAN--
105+
<?php
106+
include('inc/config.inc');
107+
$table_name = "table_08escape";
108+
109+
$db = pg_connect($conn_str);
110+
pg_query($db, "drop table {$table_name}");
100111
?>
101112
--EXPECTF--
102113
Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d

ext/pgsql/tests/10pg_convert_9.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ skip_bytea_not_hex();
1212
error_reporting(E_ALL);
1313

1414
include 'inc/config.inc';
15+
$table_name = "table_10pg_convert_9";
1516

1617
$db = pg_connect($conn_str);
18+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
19+
1720
pg_query($db, "SET standard_conforming_strings = 0");
1821

1922
$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
@@ -49,6 +52,14 @@ try {
4952
echo $e->getMessage(), \PHP_EOL;
5053
}
5154
?>
55+
--CLEAN--
56+
<?php
57+
include('inc/config.inc');
58+
$table_name = "table_10pg_convert_9";
59+
60+
$db = pg_connect($conn_str);
61+
pg_query($db, "drop table {$table_name}");
62+
?>
5263
--EXPECT--
5364
array(3) {
5465
[""num""]=>

ext/pgsql/tests/10pg_convert_json_array.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ skip_server_version('9.2');
1212
error_reporting(E_ALL);
1313

1414
include 'inc/config.inc';
15+
$table_name_92 = "table_10pg_convert_json_array_92";
1516

1617
$db = pg_connect($conn_str);
18+
pg_query($db, "create table {$table_name_92} (textary text[], jsn json)");
1719

1820
$fields = array(
1921
'textary'=>'{"meeting", "lunch", "training", "presentation"}',
@@ -28,6 +30,14 @@ if (!pg_insert($db, $table_name_92, $fields)) {
2830
echo "OK\n";
2931
}
3032

33+
?>
34+
--CLEAN--
35+
<?php
36+
include('inc/config.inc');
37+
$table_name_92 = "table_10pg_convert_json_array_92";
38+
39+
$db = pg_connect($conn_str);
40+
pg_query($db, "drop table {$table_name_92}");
3141
?>
3242
--EXPECT--
3343
array(2) {

ext/pgsql/tests/11pg_meta_data.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ pgsql
99
error_reporting(E_ALL);
1010

1111
include 'inc/config.inc';
12+
$table_name = "table_11pg_meta_data";
1213

1314
$db = pg_connect($conn_str);
15+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
1416

1517
$meta = pg_meta_data($db, $table_name);
1618

1719
var_dump($meta);
1820
?>
21+
--CLEAN--
22+
<?php
23+
include('inc/config.inc');
24+
$table_name = "table_11pg_meta_data";
25+
26+
$db = pg_connect($conn_str);
27+
pg_query($db, "drop table {$table_name}");
28+
?>
1929
--EXPECT--
2030
array(3) {
2131
["num"]=>

ext/pgsql/tests/12pg_insert_9.phpt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ skip_bytea_not_hex();
1212
error_reporting(E_ALL);
1313

1414
include 'inc/config.inc';
15+
$table_name = "table_12pg_insert_9";
1516

1617
$db = pg_connect($conn_str);
18+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
19+
1720
pg_query($db, "SET standard_conforming_strings = 0");
1821

1922
$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
@@ -53,9 +56,17 @@ try {
5356

5457
echo "Ok\n";
5558
?>
59+
--CLEAN--
60+
<?php
61+
include('inc/config.inc');
62+
$table_name = "table_12pg_insert_9";
63+
64+
$db = pg_connect($conn_str);
65+
pg_query($db, "drop table {$table_name}");
66+
?>
5667
--EXPECTF--
57-
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
58-
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
68+
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
69+
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES ('1234','AAA','BBB');
5970
object(PgSql\Result)#%d (0) {
6071
}
6172
Array of values must be an associative array with string keys

ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ skip_server_version('9.0', '<');
1212
error_reporting(E_ALL);
1313

1414
include 'inc/config.inc';
15+
$table_name = "table_13pg_select_9";
1516

1617
$db = pg_connect($conn_str);
18+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
19+
pg_query($db, "insert into {$table_name} values(1234, 'AAA', 'BBB')");
20+
pg_query($db, "insert into {$table_name} values(1234, 'AAA', 'BBB')");
21+
1722
pg_query($db, "SET bytea_output = 'hex'");
1823

19-
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
2024
$ids = array('num'=>'1234');
2125

2226
$res = pg_select($db, $table_name, $ids) or print "Error\n";
@@ -54,6 +58,14 @@ try {
5458

5559
echo "Ok\n";
5660

61+
?>
62+
--CLEAN--
63+
<?php
64+
include('inc/config.inc');
65+
$table_name = "table_13pg_select_9";
66+
67+
$db = pg_connect($conn_str);
68+
pg_query($db, "drop table {$table_name}");
5769
?>
5870
--EXPECT--
5971
array(2) {
@@ -76,8 +88,8 @@ array(2) {
7688
string(8) "\x424242"
7789
}
7890
}
79-
SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
80-
SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
91+
SELECT * FROM "table_13pg_select_9" WHERE "num"=1234;
92+
SELECT * FROM "table_13pg_select_9" WHERE "num"='1234';
8193
Array of values must be an associative array with string keys
8294
Array of values must be an associative array with string keys
8395
Values must be of type string|int|float|bool|null, array given

ext/pgsql/tests/14pg_update_9.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ skip_bytea_not_hex();
1212
error_reporting(E_ALL);
1313

1414
include 'inc/config.inc';
15+
$table_name = "table_14pg_update_9";
1516

1617
$db = pg_connect($conn_str);
18+
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
19+
pg_query($db, "insert into {$table_name} values(1, 'ABC', null)");
20+
pg_query($db, "insert into {$table_name} values(1, 'ABC', null)");
21+
1722
pg_query($db, "SET standard_conforming_strings = 0");
1823

1924
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
@@ -25,7 +30,15 @@ echo pg_update($db, $table_name, $fields, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAP
2530

2631
echo "Ok\n";
2732
?>
33+
--CLEAN--
34+
<?php
35+
include('inc/config.inc');
36+
$table_name = "table_14pg_update_9";
37+
38+
$db = pg_connect($conn_str);
39+
pg_query($db, "drop table {$table_name}");
40+
?>
2841
--EXPECT--
29-
UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
30-
UPDATE "php_pgsql_test" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
42+
UPDATE "table_14pg_update_9" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
43+
UPDATE "table_14pg_update_9" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
3144
Ok

0 commit comments

Comments
 (0)