Skip to content

Commit ba9c90c

Browse files
committed
[Serializer] Add test for headers with label
1 parent 5ecf425 commit ba9c90c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,38 @@ public function testEncodeCustomHeaders()
242242
CsvEncoder::HEADERS_KEY => [
243243
'b',
244244
'c',
245+
'n.0',
246+
'n.k',
245247
],
246248
];
247249
$value = [
248-
['a' => 'foo', 'b' => 'bar'],
250+
['a' => 'foo', 'b' => 'bar', 'n' => ['nested_index', 'k' => 'nested_key']],
249251
];
250252
$csv = <<<CSV
251-
b,c,a
252-
bar,,foo
253+
b,c,n.0,n.k,a
254+
bar,,nested_index,nested_key,foo
255+
256+
CSV;
257+
258+
$this->assertEquals($csv, $this->encoder->encode($value, 'csv', $context));
259+
}
260+
261+
public function testEncodeCustomHeadersWithLabels()
262+
{
263+
$context = [
264+
CsvEncoder::HEADERS_KEY => [
265+
'Label_B' => 'b',
266+
'c', // No label = use header key as label
267+
'Label_N_index' => 'n.0',
268+
'Label_N_key' => 'n.k',
269+
],
270+
];
271+
$value = [
272+
['a' => 'foo', 'b' => 'bar', 'n' => ['nested_index', 'k' => 'nested_key']],
273+
];
274+
$csv = <<<CSV
275+
Label_B,c,Label_N_index,Label_N_key,a
276+
bar,,nested_index,nested_key,foo
253277
254278
CSV;
255279

0 commit comments

Comments
 (0)