diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml index 370b364cd9..c96e42c608 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml @@ -23,10 +23,15 @@ - + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php new file mode 100644 index 0000000000..ee79850c47 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; + +use Symfony\Component\Serializer\Normalizer\DataUriNormalizer; + +/** + * @author Kévin Dunglas + */ +class SerializerTest extends WebTestCase +{ + public function testDeserializeArrayOfObject() + { + if (!class_exists(DataUriNormalizer::class)) { + $this->markTestSkipped('This test is only applicable when using the Symfony Serializer Component version 3.1 or superior.'); + } + + static::bootKernel(array('test_case' => 'Serializer')); + $container = static::$kernel->getContainer(); + + $result = $container->get('serializer')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json'); + + $bar1 = new Bar(); + $bar1->id = 1; + $bar2 = new Bar(); + $bar2->id = 2; + + $expected = new Foo(); + $expected->bars = array($bar1, $bar2); + + $this->assertEquals($expected, $result); + } +} + +class Foo +{ + /** + * @var Bar[] + */ + public $bars; +} + +class Bar +{ + /** + * @var int + */ + public $id; +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/bundles.php new file mode 100644 index 0000000000..144db90236 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/bundles.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; + +return array( + new FrameworkBundle(), +); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml new file mode 100644 index 0000000000..cac135c315 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml @@ -0,0 +1,6 @@ +imports: + - { resource: ../config/default.yml } + +framework: + serializer: { enabled: true } + property_info: { enabled: true }