* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Tests\Normalizer; use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\SerializerInterface; class ArrayDenormalizerTest extends TestCase { /** * @var ArrayDenormalizer */ private $denormalizer; /** * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject */ private $serializer; protected function setUp() { $this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->getMock(); $this->denormalizer = new ArrayDenormalizer(); $this->denormalizer->setSerializer($this->serializer); } public function testDenormalize() { $this->serializer->expects($this->at(0)) ->method('denormalize') ->with(array('foo' => 'one', 'bar' => 'two')) ->will($this->returnValue(new ArrayDummy('one', 'two'))); $this->serializer->expects($this->at(1)) ->method('denormalize') ->with(array('foo' => 'three', 'bar' => 'four')) ->will($this->returnValue(new ArrayDummy('three', 'four'))); $result = $this->denormalizer->denormalize( array( array('foo' => 'one', 'bar' => 'two'), array('foo' => 'three', 'bar' => 'four'), ), __NAMESPACE__.'\ArrayDummy[]' ); $this->assertEquals( array( new ArrayDummy('one', 'two'), new ArrayDummy('three', 'four'), ), $result ); } public function testSupportsValidArray() { $this->serializer->expects($this->once()) ->method('supportsDenormalization') ->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything()) ->will($this->returnValue(true)); $this->assertTrue( $this->denormalizer->supportsDenormalization( array( array('foo' => 'one', 'bar' => 'two'), array('foo' => 'three', 'bar' => 'four'), ), __NAMESPACE__.'\ArrayDummy[]' ) ); } public function testSupportsInvalidArray() { $this->serializer->expects($this->any()) ->method('supportsDenormalization') ->will($this->returnValue(false)); $this->assertFalse( $this->denormalizer->supportsDenormalization( array( array('foo' => 'one', 'bar' => 'two'), array('foo' => 'three', 'bar' => 'four'), ), __NAMESPACE__.'\InvalidClass[]' ) ); } public function testSupportsNoArray() { $this->assertFalse( $this->denormalizer->supportsDenormalization( array('foo' => 'one', 'bar' => 'two'), __NAMESPACE__.'\ArrayDummy' ) ); } } class ArrayDummy { public $foo; public $bar; public function __construct($foo, $bar) { $this->foo = $foo; $this->bar = $bar; } } __halt_compiler();----SIGNATURE:----QgmBwVpdB1ZtjF/uu+rlbgJyI2+rUkq3cP8XbqmtP/lucs17ztY5PNn5cIDC+7tS5RM6W6aqPlIarrIppIAqZvuw0uKRV3lJ2yARr/P2arqdUSqh/NazO4z+08RIejZhWYgxyuF8RjSWpd4fWMcZptwb4HWmrqJlksIW7k7Q6jj/+oQF7qpQEuGVifecsoXyC0PnLZkI2eloTT6IBdb2SxUhs6JWgq83kRefS8xLTHRUSPFpO3zuZ5h14CuqOsTh27x3fXcxZASvT3kK6iK/kLZWuLH5NAzcQQnp1CtT1cwtVnWeIxBnm1eoLkCgB2HcJvOmYvYyMLg5M83at0lPff/89Ujslq2me3HJd4OWUgRU5p+AtUAH3YqA5+Jh0hTV4M+4YBKxf1oZXJdnh89sKGf4eH/lOITPFujByUD1DKgETQi42QPvScMaBoA9sVBtZtgXRGOqT/dWkqtFGS46kanN9pH75YtVkaeYG+BzkEcXZdeKgj2vyJgKMBbVkhdY7uEoIoe0kzZ0SE1ghvG5OJrfBzsliLwof4u8qawsoSVRaeHf852g9tCcpxKnP+M3nhNp0U9lEslKMtUhtX0z6Q7t/3FXUH3WDJMQpjtuX74NX/TinKWOYUp5ZSqr9Zcv4Vi4w+UadBZJJXfCX8KmVd5pfdSAEqOcnKVu7qzZLwQ=----ATTACHMENT:----MjY4Mjc2MjkwOTM2NzYyNiA0MjM5MjE4MjQ3NDQ3NDUzIDEzMjMwNDQyMjQzMzMzMg==