ArrayCollectionNormalizerTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. return;
  9. $data = array(
  10. 'foo' => 'bar',
  11. );
  12. $serializer = $this->getMockBuilder('JMS\SerializerBundle\Serializer\Serializer')
  13. ->setMethods(array('denormalize'))
  14. ->disableOriginalConstructor()
  15. ->getMock();
  16. $serializer
  17. ->expects($this->once())
  18. ->method('denormalize')
  19. ->with($this->equalTo($data), $this->equalTo('array<Foo>'))
  20. ->will($this->returnValue(array('foo' => $obj = new \stdClass)))
  21. ;
  22. $normalizer = new ArrayCollectionNormalizer();
  23. $normalizer->setSerializer($serializer);
  24. $denormalized = $normalizer->denormalize($data, 'ArrayCollection<Foo>');
  25. $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $denormalized);
  26. $this->assertSame($obj, $denormalized['foo']);
  27. }
  28. public function testSupportsDenormalization()
  29. {
  30. $normalizer = new ArrayCollectionNormalizer();
  31. $this->assertTrue($normalizer->supportsDenormalization(null, 'ArrayCollection<>'));
  32. $this->assertFalse($normalizer->supportsDenormalization(null, 'ArrayCollection'));
  33. }
  34. }