Skip to content

Commit da1da20

Browse files
author
Malte Riesch
committed
PsvConverter handles true and false values better
1 parent a981068 commit da1da20

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/TestDbAcle/Psv/PsvConverter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ protected function preFormat($toFormat,$excludedKeys)
1010
foreach ($rowToFormat as $key => $value) {
1111
if (is_null($value)) {
1212
$toFormat[$index][$key] = "NULL";
13+
} elseif ($value === false) {
14+
$toFormat[$index][$key] = "FALSE";
15+
} elseif ($value === true) {
16+
$toFormat[$index][$key] = "TRUE";
1317
}
18+
1419
$toFormat[$index][$key] = str_replace("\n", "", $toFormat[$index][$key]);
1520
$toFormat[$index][$key] = str_replace("\r", "", $toFormat[$index][$key]);
1621

tests/TestDbAcle/Psv/PsvConverterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ function test_format_WithNull() {
4646
$this->assertEquals($expectedPsv, $psvConverter->format($arrayToFormat));
4747
}
4848

49+
function test_format_WithFalseAndTrue
50+
() {
51+
52+
$psvConverter = new \TestDbAcle\Psv\PsvConverter();
53+
54+
$expectedPsv = trim("
55+
id |first_name |last_name
56+
10 |FALSE |miller
57+
20 |stu |TRUE
58+
");
59+
60+
$arrayToFormat = array(
61+
array("id" => "10",
62+
"first_name" => false,
63+
"last_name" => "miller"),
64+
array("id" => "20",
65+
"first_name" => "stu",
66+
"last_name" => true),
67+
);
68+
$this->assertEquals($expectedPsv, $psvConverter->format($arrayToFormat));
69+
}
70+
4971
function test_format_Empty() {
5072

5173
$psvConverter = new \TestDbAcle\Psv\PsvConverter();

0 commit comments

Comments
 (0)