From c43421ca39205fe56727075f5e589e39e799fa49 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 14 Nov 2018 10:23:56 -0800 Subject: [PATCH] Fixed the flaws of decimal tests and added more debugging --- .../pdostatement_format_decimals.phpt | 17 +++++++++++------ .../sqlsrv_statement_format_decimals.phpt | 13 ++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt b/test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt index b4410e279..ff29a8086 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt @@ -188,21 +188,26 @@ function compareNumbers($actual, $input, $column, $fieldScale, $formatDecimal = $matched = false; if ($actual === $input) { $matched = true; - trace("$actual, $input\n"); + trace("Matched: $actual, $input\n"); } else { // When $formatDecimal is negative, that means no formatting done // Otherwise, if $formatDecimal > $fieldScale, will show $fieldScale decimal digits if ($formatDecimal >= 0) { $numDecimals = ($formatDecimal > $fieldScale) ? $fieldScale : $formatDecimal; + $expected = number_format($input, $numDecimals); } else { - $numDecimals = $fieldScale; + $expected = number_format($input, $fieldScale); + if (abs($input) < 1) { + // Since no formatting, the leading zero should not be there + trace("Drop leading zero of $input--"); + $expected = str_replace('0.', '.', $expected); + } } - $expected = number_format($input, $numDecimals); - trace("$actual, $expected\n"); + trace("With number_format: $actual, $expected\n"); if ($actual === $expected) { $matched = true; } else { - echo "For $column: expected $expected but the value is $actual\n"; + echo "For $column ($formatDecimal): expected $expected ($input) but the value is $actual\n"; } } return $matched; @@ -265,7 +270,7 @@ function getOutputParam($conn, $storedProcName, $inputValue, $prec, $scale, $ino $paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT; // For inout parameters the input type should match the output one - $outString = '0.0'; + $outString = '0.0'; } else { $paramType = PDO::PARAM_STR; } diff --git a/test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt b/test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt index 23ddbba94..223e4fb6b 100644 --- a/test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt +++ b/test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt @@ -30,19 +30,26 @@ function compareNumbers($actual, $input, $column, $fieldScale, $formatDecimal = $matched = false; if ($actual === $input) { $matched = true; + trace("Matched: $actual, $input\n"); } else { // When $formatDecimal is negative, that means no formatting done // Otherwise, if $formatDecimal > $fieldScale, will show $fieldScale decimal digits if ($formatDecimal >= 0) { $numDecimals = ($formatDecimal > $fieldScale) ? $fieldScale : $formatDecimal; + $expected = number_format($input, $numDecimals); } else { - $numDecimals = $fieldScale; + $expected = number_format($input, $fieldScale); + if (abs($input) < 1) { + // Since no formatting, the leading zero should not be there + trace("Drop leading zero of $input--"); + $expected = str_replace('0.', '.', $expected); + } } - $expected = number_format($input, $numDecimals); + trace("With number_format: $actual, $expected\n"); if ($actual === $expected) { $matched = true; } else { - echo "For $column: expected $expected but the value is $actual\n"; + echo "For $column ($formatDecimal): expected $expected ($input) but the value is $actual\n"; } } return $matched;