Skip to content

Commit 8c5feb3

Browse files
Fix failing tests for empty cells in csv (SpartnerNL#2754)
1 parent 2658589 commit 8c5feb3

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

tests/Concerns/WithStrictNullComparisonTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,43 @@ public function headings(): array
9292

9393
$this->assertEquals($expected, $actual);
9494
}
95+
96+
/**
97+
* @test
98+
*/
99+
public function exports_empty_cells()
100+
{
101+
$export = new class implements FromCollection, WithStrictNullComparison {
102+
use Exportable;
103+
104+
/**
105+
* @return Collection
106+
*/
107+
public function collection()
108+
{
109+
return collect([
110+
['a1', '', '', 'd1', ''],
111+
['a2', '', '', 'd2', ''],
112+
]);
113+
}
114+
};
115+
116+
$response = $export->store('empty-cells.csv');
117+
118+
$this->assertTrue($response);
119+
120+
$file = __DIR__ . '/../Data/Disks/Local/empty-cells.csv';
121+
$actual = $this->readAsArray($file, 'Csv');
122+
123+
$expected = [
124+
['a1', null, null, 'd1'],
125+
['a2', null, null, 'd2'],
126+
];
127+
128+
$this->assertEquals($expected, $actual);
129+
130+
$contents = file_get_contents($file);
131+
$this->assertStringContains('"a1","","","d1",""', $contents);
132+
$this->assertStringContains('"a2","","","d2",""', $contents);
133+
}
95134
}

tests/ExcelTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ public function can_store_csv_export_with_custom_settings()
163163
public function collection()
164164
{
165165
return collect([
166-
['A1', 'B1', '', ''],
167-
['A2', 'B2', '', ''],
166+
['A1', 'B1'],
167+
['A2', 'B2'],
168168
]);
169169
}
170170

@@ -188,8 +188,8 @@ public function getCsvSettings(): array
188188
$contents = file_get_contents(__DIR__ . '/Data/Disks/Local/filename.csv');
189189

190190
$this->assertStringContains('sep=;', $contents);
191-
$this->assertStringContains('"A1";"B1";;', $contents);
192-
$this->assertStringContains('"A2";"B2";;', $contents);
191+
$this->assertStringContains('"A1";"B1"', $contents);
192+
$this->assertStringContains('"A2";"B2"', $contents);
193193
}
194194

195195
/**

0 commit comments

Comments
 (0)