ArrayCollectionNormalizerTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace JMS\SerializerBundle\Tests\Serializer\Normalizer;
  3. use JMS\SerializerBundle\Serializer\Normalizer\ArrayCollectionNormalizer;
  4. class ArrayCollectionNormalizerTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testDenormalize()
  7. {
  8. $data = array(
  9. 'foo' => 'bar',
  10. );
  11. $serializer = $this->getMock('Symfony\Component\Serializer\SerializerInterface');
  12. $serializer
  13. ->expects($this->once())
  14. ->method('denormalize')
  15. ->with($this->equalTo($data), $this->equalTo('array<Foo>'))
  16. ->will($this->returnValue(array('foo' => $obj = new \stdClass)))
  17. ;
  18. $normalizer = new ArrayCollectionNormalizer();
  19. $normalizer->setSerializer($serializer);
  20. $denormalized = $normalizer->denormalize($data, 'ArrayCollection<Foo>');
  21. $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $denormalized);
  22. $this->assertSame($obj, $denormalized['foo']);
  23. }
  24. public function testSupportsDenormalization()
  25. {
  26. $normalizer = new ArrayCollectionNormalizer();
  27. $this->assertTrue($normalizer->supportsDenormalization(null, 'ArrayCollection<>'));
  28. $this->assertFalse($normalizer->supportsDenormalization(null, 'ArrayCollection'));
  29. }
  30. }