Updated functional tests for php8 (#1150)

This commit is contained in:
Jenny Tam 2020-07-08 19:45:00 -07:00 committed by GitHub
parent 64e8ddc855
commit 44b085f042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 447 additions and 199 deletions

View file

@ -50,12 +50,8 @@ class BuildUtil(object):
def version_label(self):
"""Return the version label based on the PHP version."""
major_ver = self.major_version()
if major_ver[2] == '0':
version = major_ver[0]
else:
version = major_ver[0] + major_ver[2]
major_ver = self.major_version()
version = major_ver[0] + major_ver[2]
return version
def driver_name(self, driver, suffix):

View file

@ -20,6 +20,9 @@ function Extend()
// simply use $databaseName from MsSetup.inc to facilitate testing in Azure,
// which does not support switching databases
$conn2 = new ExPDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd);
// With PHP 8.0 the default is PDO::ERRMODE_EXCEPTION rather than PDO::ERRMODE_SILENT
$conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
DropTable($conn2, "tmp_table");
$conn2->exec("CREATE TABLE tmp_table (id INT)");
$conn2->exec("INSERT INTO tmp_table (id) VALUES (1), (2)");
@ -52,7 +55,7 @@ class ExPDO extends PDO
return (call_user_func_array(array($this, 'parent::exec'), $args));
}
public function query()
public function query(string $statement)
{
$this->protocol();
$args = func_get_args();

View file

@ -12,13 +12,22 @@ try {
echo "Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...\n";
$dsn = getDSN($server, $databaseName, $driver);
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
// With PHP 8.0 the default is PDO::ERRMODE_EXCEPTION rather than PDO::ERRMODE_SILENT
if (PHP_MAJOR_VERSION == 8) {
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_PREFETCH => true);
} else {
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
}
$conn = new PDO($dsn, $uid, $pwd, $attr);
echo "Error from unsupported attribute (ATTR_PREFETCH) is silenced\n\n";
unset($conn);
echo "Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...\n";
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PREFETCH => true);
if (PHP_MAJOR_VERSION == 8) {
$attr = array(PDO::ATTR_PREFETCH => true);
} else {
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PREFETCH => true);
}
$conn = new PDO($dsn, $uid, $pwd, $attr);
//free the connection
unset($conn);

View file

@ -7,11 +7,13 @@ Test PDO::__Construct by passing connection options and attributes.
require_once("MsCommon_mid-refactor.inc");
try {
// With PHP 8.0 the default is PDO::ERRMODE_EXCEPTION rather than PDO::ERRMODE_SILENT
// With PHP 7.X the ATTR_ERRMODE must be set before the unsupported attribute(s) to have any effect
$attr = array( PDO::SQLSRV_ATTR_ENCODING => 3,
PDO::ATTR_CASE => 2,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PREFETCH => false,
PDO::ATTR_TIMEOUT => 35,
PDO::ATTR_ERRMODE => 2,
PDO::ATTR_STRINGIFY_FETCHES => true,
PDO::SQLSRV_ATTR_DIRECT_QUERY => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
@ -33,6 +35,7 @@ try {
"TransactionIsolation = " . PDO::SQLSRV_TXN_READ_UNCOMMITTED . ";" .
"TrustServerCertificate = false;" .
"WSID = whatever;";
$conn = connect($dsn, $attr);
echo "Test Successful\n";
} catch (PDOException $e) {
@ -41,4 +44,12 @@ try {
}
?>
--EXPECT--
Test Successful
array(3) {
[0]=>
string(5) "IMSSP"
[1]=>
int(-38)
[2]=>
string(58) "An unsupported attribute was designated on the PDO object."
}
Test Successful

View file

@ -7,8 +7,10 @@ Test PDO::__Construct by passing different connection attributes
require_once("MsCommon_mid-refactor.inc");
try {
// With PHP 8.0 the default is PDO::ERRMODE_EXCEPTION rather than PDO::ERRMODE_SILENT
$attr = array( PDO::SQLSRV_ATTR_ENCODING => 3,
PDO::ATTR_CASE => 2,
PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT,
PDO::ATTR_PREFETCH => false,
PDO::ATTR_TIMEOUT => 35,
PDO::ATTR_STRINGIFY_FETCHES => true,

View file

@ -77,11 +77,25 @@ function fetchAllInvalid($conn, $tbname)
$stmt = $conn->query("Select * from $tbname");
try {
$result = $stmt->fetchAll(PDO::FETCH_UNKNOWN);
} catch (PDOException $err) {
print_r($err);
} catch (PDOException $ex) {
print_r($ex);
} catch (Error $err) {
$expected = (PHP_MAJOR_VERSION == 8) ? 'PDO::FETCH_UNKNOWN' : 'FETCH_UNKNOWN';
$message = "Undefined class constant '$expected'";
if ($err->getMessage() !== $message) {
echo $err->getMessage() . PHP_EOL;
}
}
}
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
function warningHandler($errno, $errstr)
{
throw new Error($errstr);
}
try {
$db = connect();
$tbname1 = "PDO_MainTypes";
@ -105,7 +119,10 @@ try {
echo "Test_8 : FETCH_CLASS :\n";
fetchAllClass($db, $tbname1);
echo "Test_9 : FETCH_INVALID :\n";
set_error_handler("warningHandler", E_WARNING);
fetchAllInvalid($db, $tbname1);
restore_error_handler();
dropTable($db, $tbname1);
dropTable($db, $tbname2);
@ -427,10 +444,4 @@ string(10) "STRINGCOL2"
string(10) "STRINGCOL2"
string(%d) "222.222%S"
string(431) "<xml> 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace:
#0 %s: fetchAllInvalid(%S)
#1 {main}
thrown in %s on line %x
Test_9 : FETCH_INVALID :

View file

@ -7,6 +7,14 @@ Test the PDOStatement::fetch() method with different fetch styles.
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
function warningHandler($errno, $errstr)
{
throw new Error($errstr);
}
function fetchWithStyle($conn, $tbname, $style)
{
$stmt = $conn->query("SELECT * FROM $tbname");
@ -68,11 +76,20 @@ function fetchWithStyle($conn, $tbname, $style)
}
case "PDO::FETCH_INVALID":
{
set_error_handler("warningHandler", E_WARNING);
try {
$result = $stmt->fetch(PDO::FETCH_UNKNOWN);
} catch (PDOException $err) {
print_r($err);
} catch (Error $err) {
$expected = (PHP_MAJOR_VERSION == 8) ? 'PDO::FETCH_UNKNOWN' : 'FETCH_UNKNOWN';
$message = "Undefined class constant '$expected'";
if ($err->getMessage() !== $message) {
echo $err->getMessage() . PHP_EOL;
}
}
restore_error_handler();
break;
}
@ -255,8 +272,3 @@ string(%d) "111.111%S"
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace:
#0 %s: fetchWithStyle(%S)
#1 {main}
thrown in %s on line %x

View file

@ -4,11 +4,21 @@ zombied streams after sqlsrv_stmt_cancel.
<?php require('skipif_azure_dw.inc'); ?>
--FILE--
<?php
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
set_error_handler("warningHandler", E_WARNING);
$conn = Connect();
if( !$conn ) {
var_dump( sqlsrv_errors() );
@ -33,9 +43,14 @@ zombied streams after sqlsrv_stmt_cancel.
$str = fread( $stream, 80 );
echo "$str\n";
sqlsrv_cancel( $stmt );
while( !feof( $stream ) && is_resource($stream)) {
$str = fread( $stream, 80 );
echo "$str\n";
try {
while( !feof( $stream ) && is_resource($stream)) {
$str = fread( $stream, 80 );
echo "$str\n";
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
sqlsrv_free_stmt( $stmt );
@ -44,9 +59,13 @@ zombied streams after sqlsrv_stmt_cancel.
sqlsrv_fetch( $stmt );
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
sqlsrv_cancel( $stmt );
while( !feof( $stream ) && is_resource($stream) ) {
$str = fread( $stream, 80 );
echo "$str\n";
try {
while( !feof( $stream ) && is_resource($stream) ) {
$str = fread( $stream, 80 );
echo "$str\n";
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
sqlsrv_free_stmt( $stmt );
@ -64,7 +83,5 @@ Baby and Howlin Wolfs How Many More Times into near-cartoon parodies, the band a
lso hinted at things to come with the manic Communication Breakdown and the lumb
ering set stopper Dazed and Confused. \<I\>--Billy Altman\<\/I\>
Source: Amazon.com essential recording - Most critics complain \<I\>Back in Black\<
Warning: feof\(\): supplied resource is not a valid stream resource in .+(\/|\\)0022\.php on line [0-9]+
Warning: feof\(\): supplied resource is not a valid stream resource in .+(\/|\\)0022\.php on line [0-9]+
feof\(\): supplied resource is not a valid stream resource
feof\(\): supplied resource is not a valid stream resource

View file

@ -11,6 +11,13 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
function connectionClose()
{
$testName = "Connection - Close";
@ -23,26 +30,38 @@ function connectionClose()
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, 5);
// Close connection twice
for ($i = 0; $i < 2; $i++) {
$ret = sqlsrv_close($conn1);
if ($ret === false) {
die("Unexpected return for sqlsrv_close: $ret");
try {
// Close connection twice
for ($i = 0; $i < 2; $i++) {
$ret = sqlsrv_close($conn1);
if ($ret === false) {
die("Unexpected return for sqlsrv_close: $ret");
}
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
// Invalid Query
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM [$tableName]");
if ($stmt1) {
die("Select query should fail when connection is closed");
try {
// Invalid Query
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM [$tableName]");
if ($stmt1) {
die("Select query should fail when connection is closed");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
// Invalid Statement
$conn2 = AE\connect();
$stmt2 = AE\selectFromTable($conn2, $tableName);
sqlsrv_close($conn2);
if (sqlsrv_fetch($stmt2)) {
die("Fetch should fail when connection is closed");
try {
// Invalid Statement
$conn2 = AE\connect();
$stmt2 = AE\selectFromTable($conn2, $tableName);
sqlsrv_close($conn2);
if (sqlsrv_fetch($stmt2)) {
die("Fetch should fail when connection is closed");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
$conn3 = AE\connect();
@ -53,17 +72,15 @@ function connectionClose()
}
try {
set_error_handler("warningHandler", E_WARNING);
connectionClose();
} catch (Exception $e) {
echo $e->getMessage();
}
?>
--EXPECTREGEX--
Warning: sqlsrv_close\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 18
Warning: sqlsrv_query\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 25
Warning: sqlsrv_fetch\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC24_Close.php on line 34
--EXPECT--
sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resource
sqlsrv_query(): supplied resource is not a valid ss_sqlsrv_conn resource
sqlsrv_fetch(): supplied resource is not a valid ss_sqlsrv_stmt resource
Test "Connection - Close" completed successfully.

View file

@ -12,6 +12,13 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
function close()
{
$testName = "Statement - Close";
@ -29,18 +36,24 @@ function close()
sqlsrv_free_stmt($stmt1);
trace("Attempting to retrieve the number of fields after statement was closed ...\n");
if (sqlsrv_num_fields($stmt1) === false) {
handleErrors();
} else {
die("A closed statement cannot be reused.");
try {
if (sqlsrv_num_fields($stmt1) === false) {
handleErrors();
} else {
die("A closed statement cannot be reused.");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
trace("\nClosing the statement again (no error expected) ...\n");
if (sqlsrv_free_stmt($stmt1) === false) {
fatalError("A statement can be closed multiple times.");
try {
if (sqlsrv_free_stmt($stmt1) === false) {
fatalError("A statement can be closed multiple times.");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
@ -49,15 +62,14 @@ function close()
}
try {
set_error_handler("warningHandler", E_WARNING);
close();
} catch (Exception $e) {
echo $e->getMessage();
echo $e->getMessage() . PHP_EOL;
}
?>
--EXPECTREGEX--
Warning: sqlsrv_num_fields\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC36_Close.php on line 21
Warning: sqlsrv_free_stmt\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC36_Close.php on line 29
--EXPECT--
sqlsrv_num_fields(): supplied resource is not a valid ss_sqlsrv_stmt resource
sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource
Test "Statement - Close" completed successfully.

View file

@ -212,7 +212,7 @@ function fetchAsInts($conn, $tableName, $inputs)
fatalError("in fetchAsInts: expected $outOfRange for column $i\n");
}
} else {
$expected = floor($inputs[$i]);
$expected = floor(floatval($inputs[$i]));
if ($f != $expected) {
echo "in fetchAsInts: for column $i expected $expected but got: ";
var_dump($f);

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,14 @@ Free statement twice
--FILE--
<?php
require_once('MsCommon.inc');
set_error_handler("warningHandler", E_WARNING);
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
function CloseTwice()
{
@ -35,8 +43,10 @@ function Repro()
startTest("sqlsrv_close_twice");
try {
CloseTwice();
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
} catch (Exception $e) {
echo $e->getMessage();
echo $e->getMessage() . PHP_EOL;
}
echo "\nDone\n";
endTest("sqlsrv_close_twice");
@ -45,9 +55,8 @@ function Repro()
Repro();
?>
--EXPECTREGEX--

Warning: sqlsrv_free_stmt\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .+sqlsrv_close_twice.php on line [0-9]+
--EXPECT--
sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource
Done
Test "sqlsrv_close_twice" completed successfully.

View file

@ -4,17 +4,29 @@ sqlsrv_configure.
<?php require('skipif.inc'); ?>
--FILE--
<?php
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
set_error_handler("warningHandler", E_WARNING);
// test negative cases first
// must have two parameters
$result = sqlsrv_configure("WarningsReturnAsErrors");
if ($result) {
fatalError("sqlsrv_configure(1) should have failed.");
try {
$result = sqlsrv_configure("WarningsReturnAsErrors");
if ($result) {
fatalError("sqlsrv_configure(1) should have failed.");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
// warnings_return_as_errors the only supported option
$result = sqlsrv_configure("blahblahblah", 1);
if ($result) {
@ -134,34 +146,34 @@ sqlsrv_configure.
}
?>
--EXPECTREGEX--
Warning: sqlsrv_configure\(\) expects exactly 2 parameters, 1 given in .+(\/|\\)sqlsrv_configure\.php on line [0-9]+
--EXPECT--
sqlsrv_configure() expects exactly 2 parameters, 1 given
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => -14
\[code\] => -14
\[2\] => An invalid parameter was passed to sqlsrv_configure.
\[message\] => An invalid parameter was passed to sqlsrv_configure.
\)
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -14
[code] => -14
[2] => An invalid parameter was passed to sqlsrv_configure.
[message] => An invalid parameter was passed to sqlsrv_configure.
)
\)
)
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => -14
\[code\] => -14
\[2\] => An invalid parameter was passed to sqlsrv_get_config.
\[message\] => An invalid parameter was passed to sqlsrv_get_config.
\)
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -14
[code] => -14
[2] => An invalid parameter was passed to sqlsrv_get_config.
[message] => An invalid parameter was passed to sqlsrv_get_config.
)
\)
)
sqlsrv.LogSubsystems = -1
sqlsrv_configure: entering
sqlsrv.LogSubsystems = 8

View file

@ -8,19 +8,44 @@ sqlsrv_close returns true even if an error happens.
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
function compareMessages($err, $exp8x, $exp7x)
{
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
if ($err->getMessage() !== $expected) {
echo $err->getMessage() . PHP_EOL;
}
}
set_error_handler("warningHandler", E_WARNING);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require('MsCommon.inc');
$conn = sqlsrv_connect("InvalidServerName", array( "Database" => "test" ));
$result = sqlsrv_close($conn);
$errors = sqlsrv_errors();
if ($result !== false) {
die("sqlsrv_close succeeded despite an invalid server name.");
try {
$result = sqlsrv_close($conn);
if ($result !== false) {
die("sqlsrv_close succeeded despite an invalid server name.");
}
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, bool given",
"sqlsrv_close() expects parameter 1 to be resource, bool given");
}
print_r($errors);
$errors = sqlsrv_errors();
print_r($errors);
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
@ -72,28 +97,52 @@ sqlsrv_close returns true even if an error happens.
sqlsrv_free_stmt($stmt);
die("sqlsrv_send_stream_data failed.");
}
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
try {
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
try {
$result = sqlsrv_free_stmt(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_free_stmt(): Argument #1 (\$stmt) must be of type resource, null given",
"sqlsrv_free_stmt() expects parameter 1 to be resource, null given");
}
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_free_stmt(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_free_stmt($conn);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed the connection resource");
try {
$result = sqlsrv_free_stmt($conn);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed the connection resource");
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
print_r(sqlsrv_errors());
$result = sqlsrv_free_stmt(1);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed a 1");
try {
$result = sqlsrv_free_stmt(1);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed a 1");
}
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_free_stmt(): Argument #1 (\$stmt) must be of type resource, int given",
"sqlsrv_free_stmt() expects parameter 1 to be resource, int given");
}
print_r(sqlsrv_errors());
dropTable($conn, $tableName);
@ -102,24 +151,43 @@ sqlsrv_close returns true even if an error happens.
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_close($conn);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
try {
$result = sqlsrv_close($conn);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
$result = sqlsrv_close(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
try {
$result = sqlsrv_close(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, null given",
"sqlsrv_close() expects parameter 1 to be resource, null given");
}
$result = sqlsrv_close(1);
if ($result !== false) {
die("sqlsrv_close shouldn't have freed a 1");
try {
$result = sqlsrv_close(1);
if ($result !== false) {
die("sqlsrv_close shouldn't have freed a 1");
}
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, int given",
"sqlsrv_close() expects parameter 1 to be resource, int given");
}
print_r(sqlsrv_errors());
echo "Test successfully done.\n";
?>
--EXPECTF--
Warning: sqlsrv_close() expects parameter 1 to be resource, bool%S given in %Ssqlsrv_errors.php on line %x
--EXPECT--
Array
(
[0] => Array
@ -133,12 +201,8 @@ Array
)
)
Warning: sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, null given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource in %Ssqlsrv_errors.php on line %x
sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource
sqlsrv_free_stmt(): supplied resource is not a valid ss_sqlsrv_stmt resource
Array
(
[0] => Array
@ -152,8 +216,6 @@ Array
)
)
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
Array
(
[0] => Array
@ -167,12 +229,7 @@ Array
)
)
Warning: sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resource in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_close() expects parameter 1 to be resource, null given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_close() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resource
Array
(
[0] => Array

View file

@ -98,7 +98,7 @@ function Repro()
Repro();
?>
--EXPECT--
--EXPECTF--

Test begins...
string(79) "A statement must be prepared with sqlsrv_prepare before calling sqlsrv_execute."
@ -111,7 +111,7 @@ string(25) "Field 0 returned no data."
float(1.09)
bool(false)
string(25) "Field 1 returned no data."
float(3.4379999637604)
float(3.437999963760%s)
bool(false)
string(25) "Field 2 returned no data."
string(23) "1756-04-16 23:27:09.130"

View file

@ -1,10 +1,35 @@
--TEST--
test input param with unknown encoding
--DESCRIPTION--
When running this test with PHP 7.x, PHP warnings like the one below are expected
"Warning: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed 'SQLSRV_ENC_UNKNOWN'
(this will throw an Error in a future version of PHP)"
When running this test with PHP 8.0, the previous warnings are now errors directly from PHP
Because PHP warnings are intercepted, no need to check sqlsrv errors for those.
Add a new test case to check the error message 'An invalid PHP type for parameter 2 was specified.'
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
set_error_handler("warningHandler", E_WARNING);
function warningHandler($errno, $errstr)
{
throw new Error($errstr);
}
function compareMessages($err)
{
$exp8x = "Undefined constant 'SQLSRV_ENC_UNKNOWN'";
$exp7x = "Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed 'SQLSRV_ENC_UNKNOWN' (this will throw an Error in a future version of PHP)";
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
if ($err->getMessage() !== $expected) {
echo $err->getMessage() . PHP_EOL;
}
}
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
@ -13,7 +38,7 @@ sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
require_once('MsCommon.inc');
$conn = AE\connect();
$tableName = 'php_table_SERIL1_1';
$tableName = 'table_unknown_encoding';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max'));
$stmt = AE\createTable($conn, $tableName, $columns);
@ -21,37 +46,38 @@ if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
try {
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
die("sqlsrv_query shouldn't have succeeded.");
}
} catch (Error $err) {
compareMessages($err);
}
try {
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
} catch (Error $err) {
compareMessages($err);
}
restore_error_handler();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_PHPTYPE_INT), null)));
$errState = 'IMSSP';
$errMessage = 'An invalid PHP type for parameter 2 was specified.';
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
die("sqlsrv_query shouldn't have succeeded.");
}
verifyError(sqlsrv_errors()[0], $errState, $errMessage);
echo "Done\n";
$stmt = sqlsrv_prepare($conn, "INSERT INTO [php_table_SERIL1_1] (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_execute($stmt);
if ($result !== false) {
sqlsrv_free_stmt($stmt);
die("sqlsrv_execute shouldn't have succeeded.");
}
verifyError(sqlsrv_errors()[0], $errState, $errMessage);
sqlsrv_query($conn, "DROP TABLE [php_table_SERIL1_1]");
sqlsrv_query($conn, "DROP TABLE $tableName");
sqlsrv_close($conn);
?>
--EXPECTREGEX--
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 24
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 32
--EXPECT--
Done

View file

@ -4,21 +4,42 @@ crash caused by a statement being orphaned when an error occurred during sqlsrv_
<?php require('skipif.inc'); ?>
--FILE--
<?php
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
function compareMessages($err, $exp8x, $exp7x)
{
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
if ($err->getMessage() !== $expected) {
echo $err->getMessage() . PHP_EOL;
}
}
set_error_handler("warningHandler", E_WARNING);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
try {
$conn1 = Connect();
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
sqlsrv_close($conn1);
$row1 = sqlsrv_fetch_array($stmt1);
$conn3 = Connect();
} catch (TypeError $e) {
compareMessages($e,
"sqlsrv_fetch_array(): Argument #1 (\$stmt) must be of type resource, bool given",
"sqlsrv_fetch_array() expects parameter 1 to be resource, bool given");
}
$conn1 = Connect();
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
sqlsrv_close($conn1);
$row1 = sqlsrv_fetch_array($stmt1);
$conn3 = Connect();
echo "Test successful\n";
echo "Done\n";
?>
--EXPECTREGEX--
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, bool(ean){0,1} given in .+(\/|\\)test_conn_execute\.php on line 11
Test successful
--EXPECT--
Done

View file

@ -4,6 +4,16 @@ Test for stream zombifying.
<?php require('skipif.inc'); ?>
--FILE--
<?php
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
// Sometimes the error messages from PHP 8.0 may be different and have to be handled differently.
function warningHandler($errno, $errstr)
{
throw new TypeError($errstr);
}
set_error_handler("warningHandler", E_WARNING);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
@ -20,10 +30,16 @@ Test for stream zombifying.
sqlsrv_fetch($stmt);
$stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
sqlsrv_fetch($stmt);
$name = fread($stream, 100);
try {
$name = fread($stream, 100);
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECTREGEX--
Warning: fread\(\): supplied resource is not a valid stream resource in .+(\/|\\)test_stream\.php on line [0-9]+
--EXPECT--
fread(): supplied resource is not a valid stream resource