Skip to content

Commit 78911f4

Browse files
authored
Fixed the flaws of decimal tests and added more debugging (#879)
1 parent d51f6db commit 78911f4

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

test/functional/pdo_sqlsrv/pdostatement_format_decimals.phpt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,26 @@ function compareNumbers($actual, $input, $column, $fieldScale, $formatDecimal =
188188
$matched = false;
189189
if ($actual === $input) {
190190
$matched = true;
191-
trace("$actual, $input\n");
191+
trace("Matched: $actual, $input\n");
192192
} else {
193193
// When $formatDecimal is negative, that means no formatting done
194194
// Otherwise, if $formatDecimal > $fieldScale, will show $fieldScale decimal digits
195195
if ($formatDecimal >= 0) {
196196
$numDecimals = ($formatDecimal > $fieldScale) ? $fieldScale : $formatDecimal;
197+
$expected = number_format($input, $numDecimals);
197198
} else {
198-
$numDecimals = $fieldScale;
199+
$expected = number_format($input, $fieldScale);
200+
if (abs($input) < 1) {
201+
// Since no formatting, the leading zero should not be there
202+
trace("Drop leading zero of $input--");
203+
$expected = str_replace('0.', '.', $expected);
204+
}
199205
}
200-
$expected = number_format($input, $numDecimals);
201-
trace("$actual, $expected\n");
206+
trace("With number_format: $actual, $expected\n");
202207
if ($actual === $expected) {
203208
$matched = true;
204209
} else {
205-
echo "For $column: expected $expected but the value is $actual\n";
210+
echo "For $column ($formatDecimal): expected $expected ($input) but the value is $actual\n";
206211
}
207212
}
208213
return $matched;
@@ -265,7 +270,7 @@ function getOutputParam($conn, $storedProcName, $inputValue, $prec, $scale, $ino
265270
$paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT;
266271

267272
// For inout parameters the input type should match the output one
268-
$outString = '0.0';
273+
$outString = '0.0';
269274
} else {
270275
$paramType = PDO::PARAM_STR;
271276
}

test/functional/sqlsrv/sqlsrv_statement_format_decimals.phpt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,26 @@ function compareNumbers($actual, $input, $column, $fieldScale, $formatDecimal =
3030
$matched = false;
3131
if ($actual === $input) {
3232
$matched = true;
33+
trace("Matched: $actual, $input\n");
3334
} else {
3435
// When $formatDecimal is negative, that means no formatting done
3536
// Otherwise, if $formatDecimal > $fieldScale, will show $fieldScale decimal digits
3637
if ($formatDecimal >= 0) {
3738
$numDecimals = ($formatDecimal > $fieldScale) ? $fieldScale : $formatDecimal;
39+
$expected = number_format($input, $numDecimals);
3840
} else {
39-
$numDecimals = $fieldScale;
41+
$expected = number_format($input, $fieldScale);
42+
if (abs($input) < 1) {
43+
// Since no formatting, the leading zero should not be there
44+
trace("Drop leading zero of $input--");
45+
$expected = str_replace('0.', '.', $expected);
46+
}
4047
}
41-
$expected = number_format($input, $numDecimals);
48+
trace("With number_format: $actual, $expected\n");
4249
if ($actual === $expected) {
4350
$matched = true;
4451
} else {
45-
echo "For $column: expected $expected but the value is $actual\n";
52+
echo "For $column ($formatDecimal): expected $expected ($input) but the value is $actual\n";
4653
}
4754
}
4855
return $matched;

0 commit comments

Comments
 (0)