Skip to content

Commit c15988a

Browse files
ext/pgsql: Refactor tests (#12608)
This makes the tests independent of each other and allows them to be run in parallel. Co-authored-by: Gina Peter Banyard <girgias@php.net>
1 parent 6537811 commit c15988a

File tree

88 files changed

+872
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+872
-411
lines changed

ext/pgsql/tests/00version.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ PostgreSQL version
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99
// Get postgresql version for easier debugging.
1010
// Execute run-test.php with --keep-all to get version string in 00version.log or 00version.out
11-
include('config.inc');
11+
include('inc/config.inc');
1212

1313
$db = pg_connect($conn_str);
1414
var_dump(pg_version($db));

ext/pgsql/tests/01createdb.phpt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ PostgreSQL create db
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99
// create test table
1010

11-
include('config.inc');
11+
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 IF EXISTS {$table_name} cascade");
49+
pg_query($db, "DROP TABLE IF EXISTS {$table_name_92} cascade");
50+
?>
4151
--EXPECT--
4252
OK

ext/pgsql/tests/02connection.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ PostgreSQL connection
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99
// connection function tests
1010

11-
include('config.inc');
11+
include('inc/config.inc');
1212

1313
$db = pg_pconnect($conn_str);
1414
var_dump($db);

ext/pgsql/tests/03sync_query.phpt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ PostgreSQL sync query
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
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)))
@@ -83,7 +86,7 @@ if (function_exists('pg_result_error_field')) {
8386
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
8487
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
8588
pg_field_name($result, 0);
86-
pg_field_num($result, $field_name);
89+
pg_field_num($result, "num");
8790
pg_field_size($result, 0);
8891
pg_field_type($result, 0);
8992
pg_field_prtlen($result, 0);
@@ -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 IF EXISTS {$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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ PostgreSQL async query
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
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";
@@ -46,7 +49,7 @@ for ($i=0; $i < $rows; $i++)
4649
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
4750
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
4851
pg_field_name($result, 0);
49-
pg_field_num($result, $field_name);
52+
pg_field_num($result, "num");
5053
pg_field_size($result, 0);
5154
pg_field_type($result, 0);
5255
pg_field_prtlen($result, 0);
@@ -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 IF EXISTS {$table_name}");
76+
?>
6677
--EXPECT--
6778
OK

ext/pgsql/tests/05large_object.phpt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ PostgreSQL large object
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
include('inc/config.inc');
1111

1212
$db = pg_connect($conn_str);
1313

1414
echo "create/write/close LO\n";
15-
pg_exec ($db, "begin");
15+
pg_exec ($db, "BEGIN");
1616
$oid = pg_lo_create ($db);
1717
if (!$oid) echo ("pg_lo_create() error\n");
1818
$handle = pg_lo_open ($db, $oid, "w");
1919
if (!$handle) echo ("pg_lo_open() error\n");
2020
pg_lo_write ($handle, "large object data");
2121
pg_lo_close ($handle);
22-
pg_exec ($db, "commit");
22+
pg_exec ($db, "COMMIT");
2323

2424
echo "open/read/tell/seek/close LO\n";
25-
pg_exec ($db, "begin");
25+
pg_exec ($db, "BEGIN");
2626
$handle = pg_lo_open ($db, $oid, "w");
2727
var_dump(pg_lo_read($handle, 5));
2828
var_dump(pg_lo_tell($handle));
@@ -34,50 +34,50 @@ var_dump(pg_lo_read($handle));
3434
var_dump(pg_lo_seek($handle, -4, PGSQL_SEEK_END)); /* Seek from the end */
3535
var_dump(pg_lo_read($handle));
3636
pg_lo_close($handle);
37-
pg_exec ($db, "commit");
37+
pg_exec ($db, "COMMIT");
3838

3939
echo "open/read_all/close LO\n";
40-
pg_exec ($db, "begin");
40+
pg_exec ($db, "BEGIN");
4141
$handle = pg_lo_open ($db, $oid, "w");
4242
/* Will write to stdout */
4343
$bytesWritten = pg_lo_read_all($handle);
4444
echo "\n";
4545
var_dump($bytesWritten);
4646
if (pg_last_error($db)) echo "pg_lo_read_all() error\n".pg_last_error();
4747
pg_lo_close($handle);
48-
pg_exec ($db, "commit");
48+
pg_exec ($db, "COMMIT");
4949

5050
echo "unlink LO\n";
51-
pg_exec ($db, "begin");
51+
pg_exec ($db, "BEGIN");
5252
pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error 1\n");
53-
pg_exec ($db, "commit");
53+
pg_exec ($db, "COMMIT");
5454

5555
// more pg_lo_unlink() tests
5656
echo "Test without connection\n";
57-
pg_exec ($db, "begin");
57+
pg_exec ($db, "BEGIN");
5858
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
5959
pg_lo_unlink($oid) or print("pg_lo_unlink() error 2\n");
60-
pg_exec ($db, "commit");
60+
pg_exec ($db, "COMMIT");
6161

6262
echo "Test with string oid value\n";
63-
pg_exec ($db, "begin");
63+
pg_exec ($db, "BEGIN");
6464
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
6565
pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error 3\n");
66-
pg_exec ($db, "commit");
66+
pg_exec ($db, "COMMIT");
6767

6868
echo "import/export LO\n";
6969
$path = __DIR__ . '/';
70-
pg_query($db, 'begin');
70+
pg_query($db, 'BEGIN');
7171
$oid = pg_lo_import($db, $path . 'php.gif');
72-
pg_query($db, 'commit');
73-
pg_query($db, 'begin');
72+
pg_query($db, 'COMMIT');
73+
pg_query($db, 'BEGIN');
7474
@unlink($path . 'php.gif.exported');
7575
pg_lo_export($db, $oid, $path . 'php.gif.exported');
7676
if (!file_exists($path . 'php.gif.exported')) {
7777
echo "Export failed\n";
7878
}
7979
@unlink($path . 'php.gif.exported');
80-
pg_query($db, 'commit');
80+
pg_query($db, 'COMMIT');
8181

8282
/* invalid OID values */
8383
try {

ext/pgsql/tests/06_bug73498.phpt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@ Bug 73498 Incorrect DELIMITER syntax for pg_copy_to()
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
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

14-
$rows = pg_copy_to($db, "(select * from {$view_name})");
19+
$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 IF EXISTS {$view_name}");
33+
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
1934
?>
2035
--EXPECT--
2136
string(5) "array"

ext/pgsql/tests/06copy.phpt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ PostgreSQL copy functions
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
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 IF EXISTS {$table_name}");
2232
?>
2333
--EXPECT--
2434
OK

ext/pgsql/tests/06copy_2.phpt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@ PostgreSQL copy functions, part 2
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99

10-
include('config.inc');
10+
include('inc/config.inc');
11+
$table_name = 'table_06copy_2';
1112

1213
$db = pg_connect($conn_str);
1314

14-
pg_query($db, 'CREATE TABLE test_copy (x int)');
15+
pg_query($db, "CREATE TABLE {$table_name} (x int)");
1516

16-
pg_query($db, 'COPY test_copy FROM STDIN');
17+
pg_query($db, "COPY {$table_name} FROM STDIN");
1718

1819
pg_put_line($db, "1\n");
1920
pg_put_line($db, "\\N\n");
2021
pg_put_line($db, "\\.\n");
2122
pg_end_copy($db);
2223

23-
var_dump(pg_fetch_all_columns(pg_query($db, 'SELECT * FROM test_copy ORDER BY 1')));
24-
25-
pg_query($db, 'DROP TABLE test_copy');
24+
var_dump(pg_fetch_all_columns(pg_query($db, "SELECT * FROM {$table_name} ORDER BY 1")));
25+
?>
26+
--CLEAN--
27+
<?php
28+
include('inc/config.inc');
29+
$table_name = 'table_06copy_2';
2630

31+
$db = pg_connect($conn_str);
32+
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
2733
?>
2834
--EXPECT--
2935
array(2) {

ext/pgsql/tests/07optional.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ PostgreSQL optional functions
33
--EXTENSIONS--
44
pgsql
55
--SKIPIF--
6-
<?php include("skipif.inc"); ?>
6+
<?php include("inc/skipif.inc"); ?>
77
--FILE--
88
<?php
99
// optional functions
1010

11-
include('config.inc');
11+
include('inc/config.inc');
1212

1313
$db = pg_connect($conn_str);
1414
$enc = pg_client_encoding($db);

0 commit comments

Comments
 (0)