XmlFileLoaderTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Tests\Mapping\Loader;
  11. use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
  12. use Symfony\Component\Serializer\Mapping\ClassMetadata;
  13. use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
  14. /**
  15. * @author Kévin Dunglas <dunglas@gmail.com>
  16. */
  17. class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * @var XmlFileLoader
  21. */
  22. private $loader;
  23. /**
  24. * @var ClassMetadata
  25. */
  26. private $metadata;
  27. protected function setUp()
  28. {
  29. $this->loader = new XmlFileLoader(__DIR__.'/../../Fixtures/serialization.xml');
  30. $this->metadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  31. }
  32. public function testInterface()
  33. {
  34. $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Loader\LoaderInterface', $this->loader);
  35. }
  36. public function testLoadClassMetadataReturnsTrueIfSuccessful()
  37. {
  38. $this->assertTrue($this->loader->loadClassMetadata($this->metadata));
  39. }
  40. public function testLoadClassMetadata()
  41. {
  42. $this->loader->loadClassMetadata($this->metadata);
  43. $this->assertEquals(TestClassMetadataFactory::createXmlCLassMetadata(), $this->metadata);
  44. }
  45. public function testMaxDepth()
  46. {
  47. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy');
  48. $this->loader->loadClassMetadata($classMetadata);
  49. $attributesMetadata = $classMetadata->getAttributesMetadata();
  50. $this->assertEquals(2, $attributesMetadata['foo']->getMaxDepth());
  51. $this->assertEquals(3, $attributesMetadata['bar']->getMaxDepth());
  52. }
  53. }