* * 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:----rt22VqIU5nmGTpB8LwqiZgzhMsJRu+dLAAI1PB0thnBJ7XG5Ihk3w5dWN418JT6XlkuywcQ2S6uuyEeB1UpVvjgukbMzZnWoZCP3cLprYz55iJqCxrwLV9QvQ1I2XP21Bvt47Y0iQRfJonSJMfk73mfhpCcViK+xWT/x1DYW36bwFJUCYAOoPNpYOPJzCcdC26gpRrgpyCM7oRh0q/UAd+gtWk7R/3KMYK23SCebihQsbr8n7umbjYI526XpBhny+9MMcgE03eNSC/r9fLI06OCIUMlVnjger0MZcSE3mx7F267pbdkeSDoK6f7kwilGaGdYwYk50b17z1RnJjzupzsLBS7f2BMIbMlVGDxNqRgPpmKy3jvAitHZbiEBT+r9vYNZMcrgHAPWNQ3t10Pgp4iddyVkvjH2ey5sfmrbjfYkYP7Ssno/830E+dqHhqnG+8jBl+z9qcXthMMepZEX7TCxSM80FDBZTO7t791MNy7nYZaotcsoGg1KhHTcnL+A0aT2LtvwJz6Fb4hSEjiTXKkGN2kJLn5dNY07KbAm4iaHOnEZxkX89QtoHSCWOFRj08QxduNk0XUIc+uxnEifydOe+cqTZCjPE6UJUKoG0DW+0BBscownucmaoQR1cWx11onOguRdwcM2M0lSTPzccj3S92JlI25lODNgV4T9Ucw=----ATTACHMENT:----Njc3Nzg4Mjc2NzMxMjIzMiA4MTMwMTYxMDgxMjQ1MjM5IDI4MDc5ODU1ODkyMTM0MTg=