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
22 changes: 16 additions & 6 deletions ext/pgsql/tests/01createdb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ pgsql
// create test table

include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';
$view_name = "view_01createdb";

$db = pg_connect($conn_str);
if (!($q = @pg_query($db, "SELECT * FROM ".$table_name)) || !@pg_num_rows($q))
{
pg_query($db,$table_def); // Create table here
for ($i=0; $i < $num_test_record; $i++) {
pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
}
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); // Create table here
}
else {
echo pg_last_error()."\n";
Expand All @@ -25,18 +25,28 @@ else {
$v = pg_version($db);
if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q)))
{
pg_query($db,$table_def_92); // Create table here
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)"); // Create table here
}
else {
echo pg_last_error()."\n";
}

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

pg_close($db);

echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name} cascade");
pg_query($db, "drop table if exists {$table_name_92} cascade");
?>
--EXPECT--
OK
11 changes: 11 additions & 0 deletions ext/pgsql/tests/03sync_query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ pgsql
<?php

include('inc/config.inc');
$table_name = "table_03sync_query";

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

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

echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_03sync_query";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
Argument #3 must be greater than or equal to 0
Argument #3 must be less than the number of fields for this result set
Expand Down
11 changes: 11 additions & 0 deletions ext/pgsql/tests/04async_query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ pgsql
<?php

include('inc/config.inc');
$table_name = "table_04async_query";

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

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

echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_04async_query";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
OK
15 changes: 15 additions & 0 deletions ext/pgsql/tests/06_bug73498.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ pgsql
<?php

include('inc/config.inc');
$table_name = "table_06_bug73498";
$view_name = "view_06_bug73498";

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

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

var_dump(gettype($rows));
var_dump(count($rows) > 0);

?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_06_bug73498";
$view_name = "view_06_bug73498";

$db = pg_connect($conn_str);
pg_query($db, "drop view {$view_name}");
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
string(5) "array"
Expand Down
10 changes: 10 additions & 0 deletions ext/pgsql/tests/06copy.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ pgsql
<?php

include('inc/config.inc');
$table_name = "table_06copy";

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

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

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

echo "OK";

?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_06copy";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
OK
11 changes: 11 additions & 0 deletions ext/pgsql/tests/08escape.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pgsql
<?php

include 'inc/config.inc';
$table_name = "table_08escape";

define('FILE_NAME', __DIR__ . '/php.gif');

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

// Insert binary to DB
$escaped_data = pg_escape_bytea($db, $data);
Expand Down Expand Up @@ -97,6 +100,14 @@ else {
var_dump($expect);
}

?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_08escape";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECTF--
Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
Expand Down
11 changes: 11 additions & 0 deletions ext/pgsql/tests/10pg_convert_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ skip_bytea_not_hex();
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = "table_10pg_convert_9";

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

pg_query($db, "SET standard_conforming_strings = 0");

$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
Expand Down Expand Up @@ -49,6 +52,14 @@ try {
echo $e->getMessage(), \PHP_EOL;
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_10pg_convert_9";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
array(3) {
[""num""]=>
Expand Down
10 changes: 10 additions & 0 deletions ext/pgsql/tests/10pg_convert_json_array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ skip_server_version('9.2');
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name_92 = "table_10pg_convert_json_array_92";

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

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

?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name_92 = "table_10pg_convert_json_array_92";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name_92}");
?>
--EXPECT--
array(2) {
Expand Down
10 changes: 10 additions & 0 deletions ext/pgsql/tests/11pg_meta_data.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ pgsql
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = "table_11pg_meta_data";

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

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

var_dump($meta);
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_11pg_meta_data";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
array(3) {
["num"]=>
Expand Down
15 changes: 13 additions & 2 deletions ext/pgsql/tests/12pg_insert_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ skip_bytea_not_hex();
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = "table_12pg_insert_9";

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

pg_query($db, "SET standard_conforming_strings = 0");

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

echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_12pg_insert_9";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECTF--
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES ('1234','AAA','BBB');
object(PgSql\Result)#%d (0) {
}
Array of values must be an associative array with string keys
Expand Down
18 changes: 15 additions & 3 deletions ext/pgsql/tests/13pg_select_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ skip_server_version('9.0', '<');
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = "table_13pg_select_9";

$db = pg_connect($conn_str);
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
pg_query($db, "insert into {$table_name} values(1234, 'AAA', 'BBB')");
pg_query($db, "insert into {$table_name} values(1234, 'AAA', 'BBB')");

pg_query($db, "SET bytea_output = 'hex'");

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

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

echo "Ok\n";

?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_13pg_select_9";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
array(2) {
Expand All @@ -76,8 +88,8 @@ array(2) {
string(8) "\x424242"
}
}
SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
SELECT * FROM "table_13pg_select_9" WHERE "num"=1234;
SELECT * FROM "table_13pg_select_9" WHERE "num"='1234';
Array of values must be an associative array with string keys
Array of values must be an associative array with string keys
Values must be of type string|int|float|bool|null, array given
Expand Down
17 changes: 15 additions & 2 deletions ext/pgsql/tests/14pg_update_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ skip_bytea_not_hex();
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = "table_14pg_update_9";

$db = pg_connect($conn_str);
pg_query($db, "create table {$table_name} (num int, str text, bin bytea)");
pg_query($db, "insert into {$table_name} values(1, 'ABC', null)");
pg_query($db, "insert into {$table_name} values(1, 'ABC', null)");

pg_query($db, "SET standard_conforming_strings = 0");

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

echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_14pg_update_9";

$db = pg_connect($conn_str);
pg_query($db, "drop table {$table_name}");
?>
--EXPECT--
UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
UPDATE "php_pgsql_test" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
UPDATE "table_14pg_update_9" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
UPDATE "table_14pg_update_9" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
Ok
Loading