Skip to content

Commit

Permalink
Fixed tests that failed in php 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam committed Jun 25, 2019
1 parent d4387a9 commit 21b71fe
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 71 deletions.
8 changes: 8 additions & 0 deletions test/functional/pdo_sqlsrv/PDO29_ConnInterface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function CheckInterface($conn)
'__sleep' => true,
'inTransaction' => true,
);

$phpver = substr(phpversion(), 0, 3);
if ($phpver >= '7.4') {
// Reference: https://wiki.php.net/rfc/custom_object_serialization
unset($expected['__wakeup']);
unset($expected['__sleep']);
}

$classname = get_class($conn);
$methods = get_class_methods($classname);
foreach ($methods as $k => $method)
Expand Down
8 changes: 8 additions & 0 deletions test/functional/pdo_sqlsrv/PDO32_StmtInterface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ function checkInterface($stmt)
'__wakeup' => true,
'__sleep' => true,
);

$phpver = substr(phpversion(), 0, 3);
if ($phpver >= '7.4') {
// Reference: https://wiki.php.net/rfc/custom_object_serialization
unset($expected['__wakeup']);
unset($expected['__sleep']);
}

$classname = get_class($stmt);
$methods = get_class_methods($classname);
foreach ($methods as $k => $method) {
Expand Down
19 changes: 16 additions & 3 deletions test/functional/pdo_sqlsrv/pdo_fetch_datetime_time_as_objects.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ require_once("MsCommon_mid-refactor.inc");
function checkStringValues($obj, $columns, $values)
{
$size = count($values);
$objArray = (array)$obj; // turn the object into an associated array

for ($i = 0; $i < $size; $i++) {
$col = $columns[$i];
$val = $objArray[$col];
switch ($i) {
case 0:
$val = $obj->c1; break;
case 1:
$val = $obj->c2; break;
case 2:
$val = $obj->c3; break;
case 3:
$val = $obj->c4; break;
case 4:
$val = $obj->c5; break;
case 5:
$val = $obj->c6; break;
default:
echo "Something went wrong!\n";
}

if ($val != $values[$i]) {
echo "Expected $values[$i] for column $col but got: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function fetchColumns($conn, $tableName, $numRows, $numCols)
$res = $stmtTmp->execute();

if (! $res) {
echo "Failed to insert data from column ". $j +1 ."\n";
echo "Failed to insert data from column ". ($j + 1) ."\n";
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/functional/pdo_sqlsrv/pdo_test_non_LOB_types.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ function verifyResult($result)
$expectedLen = ($i % 2 == 0) ? $fullLen : $trimmedLen;
$len = strlen($result[$i]);
if ($len != $expectedLen) {
echo "String length $len for column ". $i + 1 . " is unexpected!\n";
echo "String length $len for column ". ($i + 1) . " is unexpected!\n";
}

$data = rtrim($result[$i]);
if ($data !== $input) {
echo "Result for column ". $i + 1 . " is unexpected:";
echo "Result for column ". ($i + 1) . " is unexpected:";
var_dump($result[$i]);
}
}
Expand Down
68 changes: 20 additions & 48 deletions test/functional/sqlsrv/sqlsrv_ae_insert_datetime.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ foreach ($dataTypes as $dataType) {
is_incompatible_types_error($dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
if ($dataType != "time") {
AE\fetchAll($conn, $tbname);
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($row as $key => $value) {
//var_dump( $row );
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($row as $key => $value) {
if ($dataType == "time") {
$t = $value->format('H:i:s');
print "$key: $t\n";
} else {
$t = date_format($value, "Y-m-d H:i:s.u");
$tz = $value->getTimezone()->getName();
print "$key: $t $tz\n";
}
}

}
dropTable($conn, $tbname);
}
Expand All @@ -51,47 +53,23 @@ sqlsrv_close($conn);

Testing date:
****Encrypted default type is compatible with encrypted date****
c_det:
date: 0001-01-01 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_rand:
date: 9999-12-31 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_det: 0001-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 00:00:00.000000 Canada/Pacific

Testing datetime:
****Encrypted default type is compatible with encrypted datetime****
c_det:
date: 1753-01-01 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_rand:
date: 9999-12-31 23:59:59.997000
timezone_type: 3
timezone: Canada/Pacific
c_det: 1753-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 23:59:59.997000 Canada/Pacific

Testing datetime2:
****Encrypted default type is compatible with encrypted datetime2****
c_det:
date: 0001-01-01 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_rand:
date: 9999-12-31 23:59:59.123456
timezone_type: 3
timezone: Canada/Pacific
c_det: 0001-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 23:59:59.123456 Canada/Pacific

Testing smalldatetime:
****Encrypted default type is compatible with encrypted smalldatetime****
c_det:
date: 1900-01-01 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_rand:
date: 2079-06-05 23:59:00.000000
timezone_type: 3
timezone: Canada/Pacific
c_det: 1900-01-01 00:00:00.000000 Canada/Pacific
c_rand: 2079-06-05 23:59:00.000000 Canada/Pacific

Testing time:
****Encrypted default type is compatible with encrypted time****
Expand All @@ -100,11 +78,5 @@ c_rand: 23:59:59

Testing datetimeoffset:
****Encrypted default type is compatible with encrypted datetimeoffset****
c_det:
date: 0001-01-01 00:00:00.000000
timezone_type: 1
timezone: -14:00
c_rand:
date: 9999-12-31 23:59:59.123456
timezone_type: 1
timezone: +14:00
c_det: 0001-01-01 00:00:00.000000 -14:00
c_rand: 9999-12-31 23:59:59.123456 +14:00
16 changes: 8 additions & 8 deletions test/functional/sqlsrv/sqlsrv_ae_insert_retrieve.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ foreach ($decrypted_row as $key => $value) {
if (!is_object($value)) {
print "$key: $value\n";
} else {
print "$key:\n";
foreach ($value as $dateKey => $dateValue) {
print " $dateKey: $dateValue\n";
}
// print "$key:\n";
// foreach ($value as $dateKey => $dateValue) {
// print " $dateKey: $dateValue\n";
// }
$t = date_format($value, "Y-m-d H:i:s.u");
$tz = $value->getTimezone()->getName();
print "$key: $t $tz\n";
}
}
sqlsrv_free_stmt($stmt);
Expand Down Expand Up @@ -70,10 +73,7 @@ Retrieving plaintext data:
SSN: 795-73-9838
FirstName: Catherine
LastName: Abel
BirthDate:
date: 1996-10-19 00:00:00.000000
timezone_type: 3
timezone: Canada/Pacific
BirthDate: 1996-10-19 00:00:00.000000 Canada/Pacific

Checking ciphertext data:
Done
25 changes: 16 additions & 9 deletions test/functional/sqlsrv/sqlsrv_ae_insert_retrieve_fixed_size.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ if ($r === false) {
}

print "Decrypted values:\n";
AE\fetchAll($conn, $tbname);

$stmt = selectFromTable($conn, $tbname);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
foreach ($row as $key => $value) {
if (is_object($value)) {
// datetime objects
$t = date_format($value,"Y-m-d H:i:s.u");
$tz = $value->getTimezone()->getName();
print("$key: $t $tz\n");
} else {
print("$key: $value\n");
}
}
}

sqlsrv_free_stmt($stmt);

Expand Down Expand Up @@ -75,12 +88,6 @@ IntData: 2147483647
BigIntData: 92233720368547
DecimalData: 79228162514264
BitData: 1
DateTimeData:
date: 9999-12-31 23:59:59.997000
timezone_type: 3
timezone: Canada/Pacific
DateTime2Data:
date: 9999-12-31 23:59:59.123456
timezone_type: 3
timezone: Canada/Pacific
DateTimeData: 9999-12-31 23:59:59.997000 Canada/Pacific
DateTime2Data: 9999-12-31 23:59:59.123456 Canada/Pacific
Done

0 comments on commit 21b71fe

Please sign in to comment.