Skip to content

Commit

Permalink
[Serializer] Add test for headers with label
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb33300 committed May 27, 2024
1 parent 5ecf425 commit ba9c90c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,38 @@ public function testEncodeCustomHeaders()
CsvEncoder::HEADERS_KEY => [
'b',
'c',
'n.0',
'n.k',
],
];
$value = [
['a' => 'foo', 'b' => 'bar'],
['a' => 'foo', 'b' => 'bar', 'n' => ['nested_index', 'k' => 'nested_key']],
];
$csv = <<<CSV
b,c,a
bar,,foo
b,c,n.0,n.k,a
bar,,nested_index,nested_key,foo
CSV;

$this->assertEquals($csv, $this->encoder->encode($value, 'csv', $context));
}

public function testEncodeCustomHeadersWithLabels()
{
$context = [
CsvEncoder::HEADERS_KEY => [
'Label_B' => 'b',
'c', // No label = use header key as label
'Label_N_index' => 'n.0',
'Label_N_key' => 'n.k',
],
];
$value = [
['a' => 'foo', 'b' => 'bar', 'n' => ['nested_index', 'k' => 'nested_key']],
];
$csv = <<<CSV
Label_B,c,Label_N_index,Label_N_key,a
bar,,nested_index,nested_key,foo
CSV;

Expand Down

0 comments on commit ba9c90c

Please sign in to comment.