From ba9c90c0656bd9e9b280152b0b940e3d3c95a098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alfaiate?= Date: Sun, 19 May 2024 12:54:30 +0700 Subject: [PATCH] [Serializer] Add test for headers with label --- .../Tests/Encoder/CsvEncoderTest.php | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php index 13c0dcc08d0ed..613b54a4ce4d8 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php @@ -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 = <<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 = <<