[PECL-CVS] [pecl-database-oci8] main: Improve test documentations and make test runs easier
[email protected] (Sharad Chandran R)
| Newsgroups | php.pecl.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Sharad Chandran R (sharadraju)
Date: 2025-12-29T17:39:38+05:30
Commit: https://github.com/php/pecl-database-oci8/commit/acf5df911add6af1fa047179bddafea522bca48a
Raw diff: https://github.com/php/pecl-database-oci8/commit/acf5df911add6af1fa047179bddafea522bca48a.diff
Improve test documentations and make test runs easier
Changed paths:
A tests/connectsysdba.inc
A tests/skipifsysdbaconnectfailure.inc
M README.md
M tests/README.md
M tests/conn_attr.inc
M tests/conn_attr_1.phpt
M tests/conn_attr_2.phpt
M tests/conn_attr_3.phpt
M tests/conn_attr_4.phpt
M tests/conn_attr_5.phpt
M tests/db_op_1.phpt
M tests/db_op_2.phpt
M tests/details.inc
M tests/drcp_cclass1.phpt
M tests/drcp_privileged.phpt
M tests/driver_name_11gR2.phpt
M tests/edition_1.phpt
M tests/edition_2.phpt
M tests/password.phpt
M tests/password_2.phpt
M tests/privileged_connect.phpt
Diff:
diff --git a/README.md b/README.md
index 105a6d3..ac47afe 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,11 @@ OCI8 linked with Instant Client 19c can connect to Oracle Database 11.2 or
later. See Oracle Support's note "Oracle Client / Server Interoperability
Support" (ID 207303.1) for details.
+Tests
+-----
+
+To run the tests, see [tests/README.md](tests/README.md).
+
Useful Links
------------
diff --git a/tests/README.md b/tests/README.md
index b1821d1..3c1881c 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -13,10 +13,16 @@ Set the following environment variables to provide credentials for the PHP tests
`PHP_OCI8_TEST_DRCP` - for running DRCP tests. It should be set to ``true``
to run DRCP tests. Otherwise, DRCP-specific tests are skipped.
+`PHP_OCI8_TEST_SYSUSER` - the SYSDBA user required for specific tests. These
+tests are skipped, if this environment variable is not set.
+
+`PHP_OCI8_TEST_SYSPASS` - the password for the SYSDBA user.
+
# Running the tests
To run the tests, execute:
```
php <testname>
-```
\ No newline at end of file
+```
+Ensure that the Oracle Client library path is set in the PATH environment variable.
diff --git a/tests/conn_attr.inc b/tests/conn_attr.inc
index f7faf70..3024ab4 100644
--- a/tests/conn_attr.inc
+++ b/tests/conn_attr.inc
@@ -1,6 +1,6 @@
<?php
-require dirname(__FILE__)."/connect.inc";
+require dirname(__FILE__)."/connectsysdba.inc";
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
if ((isset($matches[1]) && $matches[1] >= 11)) {
diff --git a/tests/conn_attr_1.phpt b/tests/conn_attr_1.phpt
index 5c7ab61..da5fcc5 100644
--- a/tests/conn_attr_1.phpt
+++ b/tests/conn_attr_1.phpt
@@ -5,12 +5,10 @@ oci8
--SKIPIF--
<?php
if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys"))
- die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/conn_attr_2.phpt b/tests/conn_attr_2.phpt
index dce6270..c691570 100644
--- a/tests/conn_attr_2.phpt
+++ b/tests/conn_attr_2.phpt
@@ -5,11 +5,10 @@ oci8
--SKIPIF--
<?php
if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/conn_attr_3.phpt b/tests/conn_attr_3.phpt
index c2e62bd..6049954 100644
--- a/tests/conn_attr_3.phpt
+++ b/tests/conn_attr_3.phpt
@@ -5,11 +5,10 @@ oci8
--SKIPIF--
<?php
if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/conn_attr_4.phpt b/tests/conn_attr_4.phpt
index eccbc78..79e95b6 100644
--- a/tests/conn_attr_4.phpt
+++ b/tests/conn_attr_4.phpt
@@ -4,12 +4,11 @@ Set and get of connection attributes with errors.
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/conn_attr_5.phpt b/tests/conn_attr_5.phpt
index 6ea0796..550b511 100644
--- a/tests/conn_attr_5.phpt
+++ b/tests/conn_attr_5.phpt
@@ -5,11 +5,10 @@ oci8
--SKIPIF--
<?php
if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/connectsysdba.inc b/tests/connectsysdba.inc
new file mode 100644
index 0000000..7959828
--- /dev/null
+++ b/tests/connectsysdba.inc
@@ -0,0 +1,17 @@
+<?php
+
+require 'details.inc';
+
+if (!empty($dbase)) {
+ $c = @oci_connect($sysuser, $syspassword, $dbase, false, OCI_SYSDBA);
+}
+else {
+ $c = @oci_connect($sysuser, $syspassword,'', false, OCI_SYSDBA);
+}
+
+if (!$c) {
+ $m = oci_error();
+ trigger_error("connect.inc: Failed to connect as '$sysuser' to '$dbase': ". $m['message'], E_USER_ERROR);
+}
+
+?>
diff --git a/tests/db_op_1.phpt b/tests/db_op_1.phpt
index bc7e964..c61aadb 100644
--- a/tests/db_op_1.phpt
+++ b/tests/db_op_1.phpt
@@ -4,12 +4,9 @@ oci_set_db_operation: basic test for end-to-end tracing
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
- die("skip needs to be run as a DBA user");
-}
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
if (!(isset($matches[0]) && $matches[1] >= 12)) {
die("skip expected output only valid when using Oracle Database 12c or greater");
diff --git a/tests/db_op_2.phpt b/tests/db_op_2.phpt
index 79ee97b..5d8d85a 100644
--- a/tests/db_op_2.phpt
+++ b/tests/db_op_2.phpt
@@ -4,12 +4,9 @@ oci_set_db_operation: test DBOP for end-to-end tracing
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
require __DIR__.'/skipif.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
- die("skip needs to be run as a DBA user");
-}
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
if (!(isset($matches[0]) && $matches[1] >= 12)) {
die("skip expected output only valid when using Oracle Database 12c or greater");
diff --git a/tests/details.inc b/tests/details.inc
index 9f5a4ec..bd777e0 100644
--- a/tests/details.inc
+++ b/tests/details.inc
@@ -20,6 +20,11 @@ if (file_exists(dirname(__FILE__)."/details_local.inc")) {
$user = getenv('PHP_OCI8_TEST_USER'); // Database username for tests
$password = getenv('PHP_OCI8_TEST_PASS'); // Password for $user
$dbase = getenv('PHP_OCI8_TEST_DB'); // Database connection string
+ if (false !== getenv('PHP_OCI8_TEST_SYSUSER')) {
+ $sysuser = getenv('PHP_OCI8_TEST_SYSUSER');
+ $syspassword = getenv('PHP_OCI8_TEST_SYSPASS');
+ if (false === $syspassword) die('skip as system password is not specified');
+ }
$test_drcp = getenv('PHP_OCI8_TEST_DRCP');
if (false !== $test_drcp && 0 == strcasecmp($test_drcp,'TRUE')) {
$test_drcp = TRUE;
@@ -31,6 +36,8 @@ if (file_exists(dirname(__FILE__)."/details_local.inc")) {
$password = "oracle";
$dbase = "localhost/XE";
$test_drcp = FALSE;
+ $sysuser = "system";
+ $syspass = "oracle";
}
/*
diff --git a/tests/drcp_cclass1.phpt b/tests/drcp_cclass1.phpt
index e71284a..58ed3c1 100644
--- a/tests/drcp_cclass1.phpt
+++ b/tests/drcp_cclass1.phpt
@@ -10,7 +10,7 @@ if (!$test_drcp) die("skip testing DRCP connection class only works in DRCP mode
// Looked for :pooled in EZ connect string
if (strpos($dbase, "/") !== false && stripos($dbase, ":pooled") === false)
die('skip DRCP test requires a DRCP pooled server connection');
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
+if (!isset($sysuser)) die("skip needs to be run as a DBA user");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches_sv);
// This test in Oracle 12c needs a non-CDB or the root container
diff --git a/tests/drcp_privileged.phpt b/tests/drcp_privileged.phpt
index cb12660..768bd9f 100644
--- a/tests/drcp_privileged.phpt
+++ b/tests/drcp_privileged.phpt
@@ -10,7 +10,7 @@ if (!$test_drcp) die("skip requires DRCP connection");
// Looked for :pooled in EZ connect string
if (strpos($dbase, "/") !== false && stripos($dbase, ":pooled") === false)
die('skip DRCP test requires a DRCP pooled server connection');
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
+if (!isset($sysuser)) die("skip needs to be run as a DBA user");
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_clean();
diff --git a/tests/driver_name_11gR2.phpt b/tests/driver_name_11gR2.phpt
index a91855c..9e7309a 100644
--- a/tests/driver_name_11gR2.phpt
+++ b/tests/driver_name_11gR2.phpt
@@ -4,9 +4,8 @@ Verify that the Driver Name attribute is set
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
require __DIR__.'/connect.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip as Output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/edition_1.phpt b/tests/edition_1.phpt
index c467bb1..42f66bd 100644
--- a/tests/edition_1.phpt
+++ b/tests/edition_1.phpt
@@ -4,11 +4,8 @@ Basic test for setting Oracle 11gR2 "edition" attribute
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
require __DIR__.'/connect.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
- die("skip needs to be run as a DBA user");
-}
if ($test_drcp) {
die("skip as Output might vary with DRCP");
}
diff --git a/tests/edition_2.phpt b/tests/edition_2.phpt
index 2a5ef0a..82f96f7 100644
--- a/tests/edition_2.phpt
+++ b/tests/edition_2.phpt
@@ -5,10 +5,8 @@ oci8
--SKIPIF--
<?php
if (getenv('SKIP_REPEAT')) die('skip fails with repeat');
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
require __DIR__.'/connect.inc';
-if (strcasecmp($user, "system") && strcasecmp($user, "sys"))
- die("skip needs to be run as a DBA user");
if ($test_drcp)
die("skip as Output might vary with DRCP");
preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
diff --git a/tests/password.phpt b/tests/password.phpt
index 322a4d7..7a3fb33 100644
--- a/tests/password.phpt
+++ b/tests/password.phpt
@@ -4,15 +4,14 @@ oci_password_change() for non-persistent connections
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
if (is_null($dbase)) die ("skip requires database connection string be set");
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip password change not supported in DRCP Mode");
?>
--FILE--
<?php
-require __DIR__.'/connect.inc';
+require __DIR__.'/connectsysdba.inc';
$stmtarray = array(
"drop user testuser_pw cascade",
@@ -65,7 +64,7 @@ echo "Done\n";
--CLEAN--
<?php
-require __DIR__.'/connect.inc';
+require __DIR__.'/connectsysdba.inc';
$stmtarray = array(
"drop user testuser_pw cascade"
diff --git a/tests/password_2.phpt b/tests/password_2.phpt
index e975d52..a06e2bd 100644
--- a/tests/password_2.phpt
+++ b/tests/password_2.phpt
@@ -4,15 +4,14 @@ oci_password_change() for persistent connections
oci8
--SKIPIF--
<?php
-require_once 'skipifconnectfailure.inc';
+require_once 'skipifsysdbaconnectfailure.inc';
if (is_null($dbase)) die ("skip requires database connection string be set");
-if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
if ($test_drcp) die("skip password change not supported in DRCP Mode");
?>
--FILE--
<?php
-require __DIR__.'/connect.inc';
+require __DIR__.'/connectsysdba.inc';
$stmtarray = array(
"drop user testuser_pw2 cascade",
@@ -64,7 +63,7 @@ echo "Done\n";
--CLEAN--
<?php
-require __DIR__.'/connect.inc';
+require __DIR__.'/connectsysdba.inc';
$stmtarray = array(
"drop user testuser_pw2 cascade"
diff --git a/tests/privileged_connect.phpt b/tests/privileged_connect.phpt
index 3e21aa0..3527a4f 100644
--- a/tests/privileged_connect.phpt
+++ b/tests/privileged_connect.phpt
@@ -5,6 +5,8 @@ oci8
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
+
+if (ini_get('oci8.privileged_connect') == 1) die('skip as privileged_connect is enabled');
?>
--FILE--
<?php
diff --git a/tests/skipifsysdbaconnectfailure.inc b/tests/skipifsysdbaconnectfailure.inc
new file mode 100644
index 0000000..ea42d1e
--- /dev/null
+++ b/tests/skipifsysdbaconnectfailure.inc
@@ -0,0 +1,33 @@
+<?php
+
+require "details.inc";
+
+// the oci_connect parameter corresponding to $dbase defaults to null
+if (!isset($dbase)) {
+ $dbase = null;
+}
+
+if (!isset($sysuser)) {
+ die("skip as SYSDBA user is required but not set");
+}
+
+$c = @oci_connect($sysuser, $syspassword, $dbase, '', OCI_SYSDBA);
+
+if ($c) {
+ oci_close($c);
+}
+else {
+ $msg = "skip Failed to connect to Oracle Database instance ";
+ if (is_null($dbase)) {
+ $msg .= "<default>";
+ }
+ else {
+ $msg .= "\"$dbase\"";
+ }
+ $msg .= " as user \"$sysuser\"";
+ $e = oci_error();
+ $msg .= ": {$e['message']}";
+ die($msg);
+}
+
+?>