Skip to content

Refactor ext/pgsql test #12608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/pgsql/tests/06copy_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ pg_put_line($db, "\\.\n");
pg_end_copy($db);

var_dump(pg_fetch_all_columns(pg_query($db, 'SELECT * FROM test_copy ORDER BY 1')));
?>
--CLEAN--
<?php
include('inc/config.inc');
$db = pg_connect($conn_str);

pg_query($db, 'DROP TABLE test_copy');

?>
--EXPECT--
array(2) {
Expand Down
9 changes: 7 additions & 2 deletions ext/pgsql/tests/80_bug24499.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if (!$dbh) {
die ("Could not connect to the server");
}

@pg_query($dbh, "DROP SEQUENCE id_id_seq");
@pg_query($dbh, "DROP TABLE id");
pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)");

for ($i=0; $i<4; $i++) {
Expand Down Expand Up @@ -48,6 +46,13 @@ pg_close($dbh);

echo "Done\n";

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

pg_query($dbh, "DROP TABLE id CASCADE");
?>
--EXPECTF--
Array
Expand Down
8 changes: 7 additions & 1 deletion ext/pgsql/tests/80_bug27597.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ if (!$dbh) {
die ("Could not connect to the server");
}

@pg_query($dbh, "DROP TABLE id");
pg_query($dbh, "CREATE TABLE id (id INT)");

for ($i=0; $i<4; $i++) {
Expand All @@ -40,6 +39,13 @@ while($row = xi_fetch_array($res)) {

pg_close($dbh);

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

pg_query($dbh, "DROP TABLE id");
?>
--EXPECT--
Array
Expand Down
13 changes: 8 additions & 5 deletions ext/pgsql/tests/80_bug39971.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ require_once('inc/skipif.inc');

require_once('inc/config.inc');

$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}
$dbh = pg_connect($conn_str);

pg_query($dbh, "CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");

Expand All @@ -24,9 +21,15 @@ pg_insert($dbh, 'php_test', $values);
$ids = array('id' => 1);
pg_update($dbh, 'php_test', $values, $ids);

pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
===DONE===
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

pg_query($dbh, "DROP TABLE php_test");
?>
--EXPECT--
===DONE===
8 changes: 7 additions & 1 deletion ext/pgsql/tests/80_bug42783.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ pg_insert($dbh, 'php_test', array());

var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM php_test")));

pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

pg_query($dbh, "DROP TABLE php_test");
?>
--EXPECTF--
array(2) {
["id"]=>
Expand Down
11 changes: 5 additions & 6 deletions ext/pgsql/tests/bug37100.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ include 'inc/config.inc';
$db = pg_connect($conn_str);
@pg_query("SET bytea_output = 'escape'");

@pg_query('DROP TABLE test_bug');

pg_query('CREATE TABLE test_bug (binfield byteA) ;');
pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");

Expand All @@ -35,12 +33,13 @@ var_dump(strlen($res));
var_dump(bin2hex($res));

pg_close($db);

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);
pg_query('DROP TABLE test_bug');
pg_close($db);


pg_query('DROP TABLE test_bug');
?>
--EXPECT--
string(24) "\001\003\252\000\010\022"
Expand Down
10 changes: 7 additions & 3 deletions ext/pgsql/tests/bug37100_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ include 'inc/config.inc';

$db = pg_connect($conn_str);

@pg_query($db, 'DROP TABLE test_bug');

pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;');
pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");

Expand All @@ -36,10 +34,16 @@ var_dump(bin2hex($res));
pg_close($db);

$db = pg_connect($conn_str);
pg_query($db, 'DROP TABLE test_bug');
pg_close($db);


?>
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);

pg_query($db, 'DROP TABLE test_bug');
?>
--EXPECT--
string(14) "\x0103aa000812"
Expand Down
10 changes: 8 additions & 2 deletions ext/pgsql/tests/bug47199.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require_once('inc/config.inc');

$dbh = pg_connect($conn_str);
$tbl_name = 'test_47199';
@pg_query($dbh, "DROP TABLE $tbl_name");
pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");

pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1));
Expand All @@ -31,11 +30,18 @@ echo $query, "\n";

var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));

@pg_query($dbh, "DROP TABLE $tbl_name");
pg_close($dbh);

echo PHP_EOL."Done".PHP_EOL;

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

$tbl_name = 'test_47199';
pg_query($dbh, "DROP TABLE $tbl_name");
?>
--EXPECT--
array(2) {
Expand Down
9 changes: 8 additions & 1 deletion ext/pgsql/tests/bug68638.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ while ($row = pg_fetch_assoc($rs)) {
var_dump($row);
}

pg_query($conn, "DROP TABLE $table");

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);
$table='test_68638';

pg_query($conn, "DROP TABLE $table");
?>
--EXPECT--
string(52) "UPDATE "test_68638" SET "value"=E'inf' WHERE "id"=1;"
Expand Down
10 changes: 8 additions & 2 deletions ext/pgsql/tests/bug71062.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ pg_convert($db, $table, ['test_field' => $date_string_modified_iso8601]);

print "done\n";

pg_query($db, "DROP TABLE $table");

?>
==OK==
--CLEAN--
<?php
require_once('inc/config.inc');
$db = @pg_connect($conn_str);
$table = "public.test_table_bug71062_bug71062";

pg_query($db, "DROP TABLE $table");
?>
--EXPECT--
trying format Y-m-d\TH:i:sO
trying format Y-m-d H:i:sO
Expand Down
8 changes: 7 additions & 1 deletion ext/pgsql/tests/bug71998.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ while (false != ($row = pg_fetch_row($r))) {
}
echo $errors, " errors caught\n";

pg_query($db, "DROP TABLE tmp_statistics");
pg_close($db);

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$db = @pg_connect($conn_str);

pg_query($db, "DROP TABLE tmp_statistics");
?>
--EXPECT--
pg_insert(): Field "remote_addr" must be a valid IPv4 or IPv6 address string, "256.257.258.259" given
Expand Down
9 changes: 7 additions & 2 deletions ext/pgsql/tests/bug72028.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include('inc/config.inc');

$conn = pg_connect($conn_str);

$table = "bug72028_" . md5(uniqid(time()));
$table = "bug72028";

pg_query($conn, "CREATE TABLE $table (value TEXT, details TEXT);");

Expand All @@ -33,9 +33,14 @@ $r = pg_query($conn, "SELECT * FROM $table");
while (false !== ($i = pg_fetch_assoc($r))) {
var_dump($i);
}
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table = "bug72028";;
$conn = pg_connect($conn_str);

pg_query($conn, "DROP TABLE $table");

?>
--EXPECT--
array(2) {
Expand Down
8 changes: 7 additions & 1 deletion ext/pgsql/tests/bug77047.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ include 'inc/config.inc';

$db = pg_connect($conn_str);

pg_query($db, "DROP TABLE IF EXISTS bug77047");
pg_query($db, "CREATE TABLE bug77047 (
t TIME WITHOUT TIME ZONE
)");
Expand All @@ -39,6 +38,13 @@ while (false !== ($row = pg_fetch_row($res))) {
var_dump(array_pop($row));
}

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);

pg_query($db, "DROP TABLE IF EXISTS bug77047");
?>
--EXPECTF--
pg_insert(): Field "t" must be of type string|null, time given
Expand Down
8 changes: 7 additions & 1 deletion ext/pgsql/tests/gh10672.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ declare(strict_types=1);
include "inc/config.inc";

$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS gh10672");
pg_query($db, "CREATE TABLE gh10672 (bar text);");

// Begin a transaction
Expand All @@ -35,5 +34,12 @@ if ($oid === false) {

echo 'The large object has been opened successfully.', PHP_EOL;
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);

pg_query($dbh, "DROP TABLE IF EXISTS gh10672");
?>
--EXPECT--
The large object has been opened successfully.
8 changes: 7 additions & 1 deletion ext/pgsql/tests/gh8253.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ $a = ["bar" => "testing"];
fee($a["bar"]);

$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS gh8253");
pg_query($db, "CREATE TABLE gh8253 (bar text);");
pg_insert($db, "gh8253", $a);
$res = pg_query($db, "SELECT * FROM gh8253");
var_dump(pg_fetch_all($res));
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);

pg_query($db, "DROP TABLE IF EXISTS gh8253");
?>
--EXPECT--
array(1) {
[0]=>
Expand Down
7 changes: 6 additions & 1 deletion ext/pgsql/tests/pg_delete_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM phptests.foo')));
pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);

pg_query($conn, 'DROP TABLE foo');
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');

?>
--EXPECTF--
string(43) "DELETE FROM "foo" WHERE "id"=1 AND "id2"=2;"
Expand Down
7 changes: 6 additions & 1 deletion ext/pgsql/tests/pg_insert_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DM

var_dump(pg_select($conn, 'phptests.foo', array('id' => 1)));

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);

pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');

?>
--EXPECTF--
Warning: pg_insert(): Table 'foo' doesn't exists in %s on line %d
Expand Down
6 changes: 5 additions & 1 deletion ext/pgsql/tests/pg_meta_data_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ var_dump(pg_meta_data($conn, 'foo'));
var_dump(pg_meta_data($conn, 'phptests.foo'));
var_dump(pg_meta_data($conn, 'phptests.foo', TRUE));

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);

pg_query($conn, 'DROP TABLE foo');
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');

?>
--EXPECT--
array(2) {
Expand Down
7 changes: 6 additions & 1 deletion ext/pgsql/tests/pg_select_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ var_dump(pg_select($conn, 'phptests.bar', array()));
/* No array */
var_dump(pg_select($conn, 'phptests.bar'));

?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);

pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP TABLE phptests.bar');
pg_query($conn, 'DROP SCHEMA phptests');

?>
--EXPECTF--
Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d
Expand Down
Loading