diff options
| author | George Peter Banyard <girgias@php.net> | 2020-09-28 18:31:02 +0100 |
|---|---|---|
| committer | George Peter Banyard <girgias@php.net> | 2020-09-29 15:13:01 +0100 |
| commit | 053a5fc141be9d3d9b9fb50e9856e0e102c28e66 (patch) | |
| tree | a9fa9cc54d3bf3cef0c4d1474c9634ee75c3792c /ext/pgsql/tests | |
| parent | 5dd5569b89cce66b377f9934ae82ceea4e19e2a5 (diff) | |
| download | php-git-053a5fc141be9d3d9b9fb50e9856e0e102c28e66.tar.gz | |
Promote E_NOTICE to Value/TypeError in PostgreSQL extension
Add some tests to cover related codepaths.
With the small caveat that the ones in build_assignment_string()
still don't seem to be tested as it looks the condtions are checked
beforehand, might need some more investigation.
Closes GH-6226
Diffstat (limited to 'ext/pgsql/tests')
| -rw-r--r-- | ext/pgsql/tests/05large_object.phpt | 26 | ||||
| -rw-r--r-- | ext/pgsql/tests/10pg_convert_9.phpt | 33 | ||||
| -rw-r--r-- | ext/pgsql/tests/12pg_insert_9.phpt | 33 | ||||
| -rw-r--r-- | ext/pgsql/tests/13pg_select_9.phpt | 34 | ||||
| -rw-r--r-- | ext/pgsql/tests/28large_object_import_oid.phpt | 49 |
5 files changed, 175 insertions, 0 deletions
diff --git a/ext/pgsql/tests/05large_object.phpt b/ext/pgsql/tests/05large_object.phpt index 3a4a40eb08..b493edd221 100644 --- a/ext/pgsql/tests/05large_object.phpt +++ b/ext/pgsql/tests/05large_object.phpt @@ -68,6 +68,28 @@ if (!file_exists($path . 'php.gif.exported')) { @unlink($path . 'php.gif.exported'); pg_query($db, 'commit'); +/* invalid OID values */ +try { + pg_lo_create(-15); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_create($db, -15); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_create('giberrish'); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_create($db, 'giberrish'); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} + echo "OK"; ?> --EXPECT-- @@ -79,4 +101,8 @@ unlink LO Test without connection Test with string oid value import/export LO +Invalid OID value passed +Invalid OID value passed +Invalid OID value passed +Invalid OID value passed OK diff --git a/ext/pgsql/tests/10pg_convert_9.phpt b/ext/pgsql/tests/10pg_convert_9.phpt index a8395315c6..0a2828a247 100644 --- a/ext/pgsql/tests/10pg_convert_9.phpt +++ b/ext/pgsql/tests/10pg_convert_9.phpt @@ -18,6 +18,34 @@ $fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB'); $converted = pg_convert($db, $table_name, $fields); var_dump($converted); + +/* Invalid values */ +try { + $converted = pg_convert($db, $table_name, [5 => 'AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_convert($db, $table_name, ['AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_convert($db, $table_name, ['num' => []]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_convert($db, $table_name, ['num' => new stdClass()]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_convert($db, $table_name, ['num' => $db]); + var_dump($converted); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} ?> --EXPECT-- array(3) { @@ -28,3 +56,8 @@ array(3) { [""bin""]=> string(12) "E'\\x424242'" } +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 +Values must be of type string|int|float|bool|null, stdClass given +Values must be of type string|int|float|bool|null, resource given diff --git a/ext/pgsql/tests/12pg_insert_9.phpt b/ext/pgsql/tests/12pg_insert_9.phpt index 275afc55e1..11a401f358 100644 --- a/ext/pgsql/tests/12pg_insert_9.phpt +++ b/ext/pgsql/tests/12pg_insert_9.phpt @@ -21,10 +21,43 @@ echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n"; echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n"; var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) ); // Return resource +/* Invalid values */ +try { + $converted = pg_insert($db, $table_name, [5 => 'AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_insert($db, $table_name, ['AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_insert($db, $table_name, ['num' => []]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_insert($db, $table_name, ['num' => new stdClass()]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_insert($db, $table_name, ['num' => $db]); + var_dump($converted); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} + echo "Ok\n"; ?> --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'); resource(%d) of type (pgsql result) +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 +Values must be of type string|int|float|bool|null, stdClass given +Values must be of type string|int|float|bool|null, resource given Ok diff --git a/ext/pgsql/tests/13pg_select_9.phpt b/ext/pgsql/tests/13pg_select_9.phpt index d5e661e5e0..82a59a1cf5 100644 --- a/ext/pgsql/tests/13pg_select_9.phpt +++ b/ext/pgsql/tests/13pg_select_9.phpt @@ -21,6 +21,35 @@ $res = pg_select($db, $table_name, $ids) or print "Error\n"; var_dump($res); echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n"; echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n"; + +/* Invalid values */ +try { + $converted = pg_select($db, $table_name, [5 => 'AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_select($db, $table_name, ['AAA']); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_select($db, $table_name, ['num' => []]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_select($db, $table_name, ['num' => new stdClass()]); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + $converted = pg_select($db, $table_name, ['num' => $db]); + var_dump($converted); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} + echo "Ok\n"; ?> @@ -47,4 +76,9 @@ array(2) { } SELECT * FROM "php_pgsql_test" WHERE "num"=1234; SELECT * FROM "php_pgsql_test" 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 +Values must be of type string|int|float|bool|null, stdClass given +Values must be of type string|int|float|bool|null, resource given Ok diff --git a/ext/pgsql/tests/28large_object_import_oid.phpt b/ext/pgsql/tests/28large_object_import_oid.phpt index 9ffb96123e..8209cc2932 100644 --- a/ext/pgsql/tests/28large_object_import_oid.phpt +++ b/ext/pgsql/tests/28large_object_import_oid.phpt @@ -38,6 +38,47 @@ if ($oid != 21005) echo ("pg_lo_import() wrong id\n"); pg_lo_unlink ($oid); pg_exec('commit'); +/* Invalide OID */ +try { + pg_lo_import(__FILE__, -15); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import($db, __FILE__, -15); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import(__FILE__, 'giberrish'); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import($db, __FILE__, 'giberrish'); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import(__FILE__, true); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import($db, __FILE__, []); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import($db, __FILE__, new stdClass()); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} +try { + pg_lo_import($db, __FILE__, $db); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} echo "OK"; ?> @@ -45,4 +86,12 @@ echo "OK"; import LO from int import LO from string import LO using default connection +Invalid OID value passed +Invalid OID value passed +Invalid OID value passed +Invalid OID value passed +OID value must be of type string|int, bool given +OID value must be of type string|int, array given +OID value must be of type string|int, stdClass given +OID value must be of type string|int, resource given OK |
