4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Tests\Normalizer;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
16 use Symfony\Component\Serializer\SerializerInterface;
18 class ArrayDenormalizerTest extends TestCase
21 * @var ArrayDenormalizer
23 private $denormalizer;
26 * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
30 protected function setUp()
32 $this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->getMock();
33 $this->denormalizer = new ArrayDenormalizer();
34 $this->denormalizer->setSerializer($this->serializer);
37 public function testDenormalize()
39 $this->serializer->expects($this->at(0))
40 ->method('denormalize')
41 ->with(array('foo' => 'one', 'bar' => 'two'))
42 ->will($this->returnValue(new ArrayDummy('one', 'two')));
44 $this->serializer->expects($this->at(1))
45 ->method('denormalize')
46 ->with(array('foo' => 'three', 'bar' => 'four'))
47 ->will($this->returnValue(new ArrayDummy('three', 'four')));
49 $result = $this->denormalizer->denormalize(
51 array('foo' => 'one', 'bar' => 'two'),
52 array('foo' => 'three', 'bar' => 'four'),
54 __NAMESPACE__.'\ArrayDummy[]'
59 new ArrayDummy('one', 'two'),
60 new ArrayDummy('three', 'four'),
66 public function testSupportsValidArray()
68 $this->serializer->expects($this->once())
69 ->method('supportsDenormalization')
70 ->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything())
71 ->will($this->returnValue(true));
74 $this->denormalizer->supportsDenormalization(
76 array('foo' => 'one', 'bar' => 'two'),
77 array('foo' => 'three', 'bar' => 'four'),
79 __NAMESPACE__.'\ArrayDummy[]'
84 public function testSupportsInvalidArray()
86 $this->serializer->expects($this->any())
87 ->method('supportsDenormalization')
88 ->will($this->returnValue(false));
91 $this->denormalizer->supportsDenormalization(
93 array('foo' => 'one', 'bar' => 'two'),
94 array('foo' => 'three', 'bar' => 'four'),
96 __NAMESPACE__.'\InvalidClass[]'
101 public function testSupportsNoArray()
104 $this->denormalizer->supportsDenormalization(
105 array('foo' => 'one', 'bar' => 'two'),
106 __NAMESPACE__.'\ArrayDummy'
117 public function __construct($foo, $bar)