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

Fixed the flaws of decimal tests and added more debugging #879

Merged
merged 1 commit into from
Nov 16, 2018
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
17 changes: 11 additions & 6 deletions test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 10 additions & 3 deletions test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down