[Serializer] Deprecate CsvEncoder as_collection false default value
This commit is contained in:
parent
83232f85ff
commit
bce59c8427
@ -53,6 +53,12 @@ SecurityBundle
|
||||
the token classes is deprecated. To use
|
||||
custom tokens extend the existing AnonymousToken and RememberMeToken.
|
||||
|
||||
Serializer
|
||||
----------
|
||||
|
||||
* Relying on the default value (false) of the "as_collection" option is deprecated since 4.2.
|
||||
You should set it to false explicitly instead as true will be the default value in 5.0.
|
||||
|
||||
DoctrineBridge
|
||||
--------------
|
||||
|
||||
|
@ -166,6 +166,10 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!isset($context['as_collection'])) {
|
||||
@trigger_error('Relying on the default value (false) of the "as_collection" option is deprecated since 4.2. You should set it to false explicitly instead as true will be the default value in 5.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// If there is only one data line in the document, return it (the line), the result is not considered as a collection
|
||||
return $result[0];
|
||||
}
|
||||
|
@ -282,7 +282,11 @@ CSV
|
||||
$this->assertFalse($this->encoder->supportsDecoding('foo'));
|
||||
}
|
||||
|
||||
public function testDecode()
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Relying on the default value (false) of the "as_collection" option is deprecated since 4.2. You should set it to false explicitly instead as true will be the default value in 5.0.
|
||||
*/
|
||||
public function testDecodeLegacy()
|
||||
{
|
||||
$expected = array('foo' => 'a', 'bar' => 'b');
|
||||
|
||||
@ -293,6 +297,17 @@ CSV
|
||||
, 'csv'));
|
||||
}
|
||||
|
||||
public function testDecodeAsSingle()
|
||||
{
|
||||
$expected = array('foo' => 'a', 'bar' => 'b');
|
||||
|
||||
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
|
||||
foo,bar
|
||||
a,b
|
||||
CSV
|
||||
, 'csv', array(CsvEncoder::AS_COLLECTION_KEY => false)));
|
||||
}
|
||||
|
||||
public function testDecodeCollection()
|
||||
{
|
||||
$expected = array(
|
||||
@ -311,10 +326,8 @@ CSV
|
||||
, 'csv'));
|
||||
}
|
||||
|
||||
public function testDecodeOnlyOneAsCollection()
|
||||
public function testDecode()
|
||||
{
|
||||
$this->encoder = new CsvEncoder(',', '"', '\\', '.');
|
||||
|
||||
$expected = array(
|
||||
array('foo' => 'a'),
|
||||
);
|
||||
@ -324,7 +337,9 @@ foo
|
||||
a
|
||||
|
||||
CSV
|
||||
, 'csv', array(CsvEncoder::AS_COLLECTION_KEY => true)));
|
||||
, 'csv', array(
|
||||
CsvEncoder::AS_COLLECTION_KEY => true, // Can be removed in 5.0
|
||||
)));
|
||||
}
|
||||
|
||||
public function testDecodeToManyRelation()
|
||||
@ -365,17 +380,19 @@ CSV
|
||||
{
|
||||
$this->encoder = new CsvEncoder(';', "'", '|', '-');
|
||||
|
||||
$expected = array('a' => 'hell\'o', 'bar' => array('baz' => 'b'));
|
||||
$expected = array(array('a' => 'hell\'o', 'bar' => array('baz' => 'b')));
|
||||
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
|
||||
a;bar-baz
|
||||
'hell''o';b;c
|
||||
CSV
|
||||
, 'csv'));
|
||||
, 'csv', array(
|
||||
CsvEncoder::AS_COLLECTION_KEY => true, // Can be removed in 5.0
|
||||
)));
|
||||
}
|
||||
|
||||
public function testDecodeCustomSettingsPassedInContext()
|
||||
{
|
||||
$expected = array('a' => 'hell\'o', 'bar' => array('baz' => 'b'));
|
||||
$expected = array(array('a' => 'hell\'o', 'bar' => array('baz' => 'b')));
|
||||
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
|
||||
a;bar-baz
|
||||
'hell''o';b;c
|
||||
@ -385,6 +402,7 @@ CSV
|
||||
CsvEncoder::ENCLOSURE_KEY => "'",
|
||||
CsvEncoder::ESCAPE_CHAR_KEY => '|',
|
||||
CsvEncoder::KEY_SEPARATOR_KEY => '-',
|
||||
CsvEncoder::AS_COLLECTION_KEY => true, // Can be removed in 5.0
|
||||
)));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user