10000 Added test · symfony/symfony@4c2512f · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c2512f

Browse files
author
Bizley
committed
Added test
1 parent b6931ab commit 4c2512f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function encode($data, string $format, array $context = [])
9595

9696
$headers = array_merge(array_values($headers), array_diff($this->extractHeaders($data), $headers));
9797
$endOfLine = $context[self::END_OF_LINE] ?? $this->defaultContext[self::END_OF_LINE];
98-
98+
9999
if (!($context[self::NO_HEADERS_KEY] ?? $this->defaultContext[self::NO_HEADERS_KEY])) {
100100
fputcsv($handle, $headers, $delimiter, $enclosure, $escapeChar);
101101
if ("\n" !== $endOfLine && 0 === fseek($handle, -1, \SEEK_CUR)) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,12 @@ public function testEndOfLine()
697697

698698
$this->assertSame("foo,bar\r\nhello,test\r\n", $this->encoder->encode($value, 'csv', [CsvEncoder::END_OF_LINE => "\r\n"]));
699699
}
700+
701+
public function testEndOfLinePassedInConstructor()
702+
{
703+
$value = ['foo' => 'hello', 'bar' => 'test'];
704+
705+
$encoder = new CsvEncoder([CsvEncoder::END_OF_LINE => "\r\n"]);
706+
$this->assertSame("foo,bar\r\nhello,test\r\n", $encoder->encode($value, 'csv'));
707+
}
700708
}

0 commit comments

Comments
 (0)
0