Skip to content
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

Made some tests more robust and work with PHP 8.1 #1285

Merged
merged 3 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ install:
}
- echo Downloading MSODBCSQL 17
# AppVeyor build works are x64 VMs and 32-bit ODBC driver cannot be installed on it
- ps: (new-object net.webclient).DownloadFile('https://download.microsoft.com/download/2/c/c/2cc12eab-a3aa-45d6-95bb-13f968fb6cd6/en-US/17.7.2.1/x64/msodbcsql.msi', 'c:\projects\msodbcsql.msi')
- ps: (new-object net.webclient).DownloadFile('https://download.microsoft.com/download/a/e/b/aeb7d4ff-ca20-45db-86b8-8a8f774ce97b/en-US/17.8.1.1/x64/msodbcsql.msi', 'c:\projects\msodbcsql.msi')
- cmd /c start /wait msiexec /i "c:\projects\msodbcsql.msi" /q IACCEPTMSODBCSQLLICENSETERMS=YES ADDLOCAL=ALL
- echo Checking the version of MSODBCSQL
- reg query "HKLM\SOFTWARE\ODBC\odbcinst.ini\ODBC Driver 17 for SQL Server"
Expand Down
7 changes: 7 additions & 0 deletions test/bvt/sqlsrv/connect.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ function dropProc($conn, $procName)
sqlsrv_query($conn, $tsql);
}

// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
// changes are made to SalesOrderDetail. Since RevisionNumber is a tinyint, it can
// overflow quickly if the BVT tests often run. Disable the trigger.
function disableTrigger($conn)
{
sqlsrv_query($conn, 'DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader');
}
?>
6 changes: 1 addition & 5 deletions test/bvt/sqlsrv/msdn_sqlsrv_begin_transaction.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ if( $conn === false )
die( print_r( sqlsrv_errors(), true ));
}

$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);
disableTrigger($conn);

/* Initiate transaction. */
/* Exit script if transaction cannot be initiated. */
Expand Down Expand Up @@ -64,9 +63,6 @@ else
$d_sql = "DELETE FROM Sales.SalesOrderDetail WHERE SalesOrderID=43659 AND OrderQty=5 AND ProductID=709 AND SpecialOfferID=1 AND Unitprice=5.70";
$stmt3 = sqlsrv_query($conn, $d_sql);

$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);

/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt1);
sqlsrv_free_stmt( $stmt2);
Expand Down
11 changes: 1 addition & 10 deletions test/bvt/sqlsrv/msdn_sqlsrv_execute_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ echo "<br>";

sqlsrv_free_stmt( $stmt);

// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
// overflow quickly if this test is often run. So disable the trigger.
$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);

disableTrigger($conn);

/* Prepare with string type in parameter. */
$tsql = "UPDATE Sales.SalesOrderDetail
Expand Down Expand Up @@ -142,10 +137,6 @@ else
}
echo sqlsrv_rows_affected( $stmt)." rows affected.<br>";

// Re-enable the trigger
$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);

/* Free the statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
Expand Down
10 changes: 1 addition & 9 deletions test/bvt/sqlsrv/msdn_sqlsrv_query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ if( $conn === false )
die( print_r( sqlsrv_errors(), true));
}

// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
// overflow quickly if this test is often run. So disable the trigger.
$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);
disableTrigger($conn);

/* Set up the parameterized query. */
$tsql = "INSERT INTO Sales.SalesOrderDetail
Expand Down Expand Up @@ -47,10 +43,6 @@ else
die( print_r( sqlsrv_errors(), true));
}

// Re-enable the trigger
$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
$stmt = sqlsrv_query($conn, $tsql);

/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
Expand Down
9 changes: 5 additions & 4 deletions test/functional/pdo_sqlsrv/pdo_ae_output_param_floats.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
--TEST--
Test for retrieving encrypted data of floats as output parameters
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
Use PDOstatement::bindParam with all PDO::PARAM_ types. This test generates input float. For your reference:
https://en.wikipedia.org/wiki/Single-precision_floating-point_format#Precision_limitations_on_integer_values
--ENV--
PHPT_EXEC=true
--SKIPIF--
Expand Down Expand Up @@ -51,9 +52,9 @@ function testOutputFloats($fetchNumeric, $inout)
$inputValues = array();
// create random input values
for ($i = 0; $i < 2; $i++) {
$mantissa = rand(1, 100000000);
$decimals = rand(1, 100000000);
$floatNum = $mantissa + $decimals / 10000000;
$mantissa = rand(1, 10000000);
$decimals = rand(1, 100);
$floatNum = $mantissa + $decimals / 10000;
if ($i > 0) {
// make the second input negative
$floatNum *= -1;
Expand Down
12 changes: 11 additions & 1 deletion test/functional/pdo_sqlsrv/pdo_test_TVP_bind_params.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ PHPT_EXEC=true
require_once('MsSetup.inc');
require_once('MsCommon_mid-refactor.inc');

function verifyPhoto($image, $photo)
{
// With PHP 8.1+, bindColumn() of binary fields will be resource
if (PHP_VERSION_ID >= 80100) {
return verifyBinaryStream($image, $photo);
} else {
return verifyBinaryData($image, $photo);
}
}

try {
date_default_timezone_set('America/Los_Angeles');

Expand Down Expand Up @@ -76,7 +86,7 @@ try {
$stmt = $conn->query($tsql);
$stmt->bindColumn('Photo', $photo, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
if ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
if (!verifyBinaryData($images[$index], $photo)) {
if (!verifyPhoto($images[$index], $photo)) {
echo 'Image data corrupted for row '. ($index + 1) . PHP_EOL;
}
} else {
Expand Down
13 changes: 12 additions & 1 deletion test/functional/pdo_sqlsrv/pdo_test_TVP_nulls_buffered.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ PHPT_EXEC=true
require_once('MsSetup.inc');
require_once('MsCommon_mid-refactor.inc');

function verifyPhoto($image, $photo)
{
// With PHP 8.1+, bindColumn() of binary fields will be resource
if (PHP_VERSION_ID >= 80100) {
return verifyBinaryStream($image, $photo);
} else {
return verifyBinaryData($image, $photo);
}
}

try {
date_default_timezone_set('America/Los_Angeles');

Expand Down Expand Up @@ -84,8 +94,9 @@ try {
$stmt = $conn->query($tsql);
$index = 2;
$stmt->bindColumn('Photo', $photo, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);

if ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
if (!verifyBinaryData($images[$index], $photo)) {
if (!verifyPhoto($images[$index], $photo)) {
echo 'Image data corrupted for row '. ($index + 1) . PHP_EOL;
}
} else {
Expand Down