msphpsql/test/functional/sqlsrv/TC24_Close.phpt

87 строки
2.3 KiB
Plaintext
Исходник Обычный вид История

2017-05-04 02:00:31 +03:00
--TEST--
Connection Close Test
--DESCRIPTION--
Verifies that a connection can be closed multiple times and
that resources are invalidated when connection is closed.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
2017-05-04 02:00:31 +03:00
--FILE--
<?php
require_once('MsCommon.inc');
2017-05-04 02:00:31 +03:00
// 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()
2017-05-04 02:00:31 +03:00
{
$testName = "Connection - Close";
startTest($testName);
setup();
$conn1 = AE\connect();
$tableName = 'TC24test';
2017-10-26 20:48:36 +03:00
// Insert some random rows
AE\createTestTable($conn1, $tableName);
2017-10-26 20:48:36 +03:00
AE\insertTestRows($conn1, $tableName, 5);
2017-05-04 02:00:31 +03:00
try {
// Close connection twice
for ($i = 0; $i < 2; $i++) {
$ret = sqlsrv_close($conn1);
if ($ret === false) {
die("Unexpected return for sqlsrv_close: $ret");
}
2017-05-04 02:00:31 +03:00
}
} catch (TypeError $e) {
echo $e->getMessage() . PHP_EOL;
2017-05-04 02:00:31 +03:00
}
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;
2017-05-04 02:00:31 +03:00
}
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;
2017-05-04 02:00:31 +03:00
}
$conn3 = AE\connect();
dropTable($conn3, $tableName);
sqlsrv_close($conn3);
2017-05-04 02:00:31 +03:00
endTest($testName);
2017-05-04 02:00:31 +03:00
}
try {
set_error_handler("warningHandler", E_WARNING);
connectionClose();
} catch (Exception $e) {
echo $e->getMessage();
2017-05-04 02:00:31 +03:00
}
?>
--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
2017-05-04 02:00:31 +03:00
Test "Connection - Close" completed successfully.