[Serializer] add a context key to return csv always as collection
This commit is contained in:
parent
424cbcc1c5
commit
d19d05dc5d
@ -150,6 +150,10 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
if ($context['as_collection'] ?? false) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (empty($result) || isset($result[1])) {
|
||||
return $result;
|
||||
}
|
||||
|
@ -208,6 +208,22 @@ CSV
|
||||
, 'csv'));
|
||||
}
|
||||
|
||||
public function testDecodeOnlyOneAsCollection()
|
||||
{
|
||||
$this->encoder = new CsvEncoder(',', '"', '\\', '.');
|
||||
|
||||
$expected = array(
|
||||
array('foo' => 'a'),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
|
||||
foo
|
||||
a
|
||||
|
||||
CSV
|
||||
, 'csv', array('as_collection' => true)));
|
||||
}
|
||||
|
||||
public function testDecodeToManyRelation()
|
||||
{
|
||||
$expected = array(
|
||||
|
Reference in New Issue
Block a user